You are not logged in.
Pages: 1
6
From: Ilya
I am looking for some recommendation to handle situation as follows: select() says data is available to be read. I read 4096 bytes(this is size for socket receive buffer), parse buffer and see that there are 25 complete messages in buffer and part of the next message. I would like to read rest of uncompleted message without call select(). I would like call select only after I finished read rest of uncompleted message. Thanks
From: Tom
In answering Ilya's question, I would use the following approach to read message one by one (in this case, the messages are strings separate by NULL characters):
while (1)
{
bzero(buffer, sizeof(buffer));
/* PEEK but not read from receive buffer first */
readcount = recv(socketfd, buffer,
sizeof(buffer), MSG_PEEK);
if (readcount <= 0)
break;
recv(socketfd, buffer, strlen(buffer)+1, 0);
fprintf(stdout, "%s\n", buffer);
}From: Ilya
Thank yoy very much !
From: alexandre
Hi,
i use part of your function, to get reliable data transfert over TCP,
here is my func:
call select
if readable continue;
if not return
recv (MSG_PEEK)
does buffer has \r\n
if yes continue
if no return
recv
return len bufferthe problem is that recv, doesn"t change file descriptor status
so select think data is avaible. Is there a function:
similar to get in the way that select doens't see it again
or
get select to return only if new data is available
Cheers
---
Alexandre
From: Bob
Replace MSG_PEEK by 0.
this should chage the fd status
Offline
Pages: 1