Re: question about how to use send() and recv()
From: QNils_O=2E_Sel=E5sdal=22?= (NOS_at_Utel.no)
Date: 11/14/05
- Next message: Lars Kellogg-Stedman: "Re: SCTP multihoming problems"
- Previous message: Kenneth Sparre Sørensen: "SCTP multihoming problems"
- In reply to: xucaen: "question about how to use send() and recv()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Nov 2005 14:21:32 +0100
xucaen wrote:
> Hi, I've been reading some threads about send() and recv() and I'm a
> little bit confused about whether or not I need to wrap those function
> calls inside a loop.
>
> If I have a 1024 byte send buffer and I know my application will never
> want to send more than 1024 bytes at a time, I pass my buffer off to
> send(), does the sockets library take my buffer of bytes and keep
> trying to send until it is all sent or do I have to keep calling send()
> until my data is all sent?
Both might happen. The underlying protocol might break your buffer up in
pieces and send them individually (for stream sockets) and it might
not grab all your data at once, so you must loop.
> Likewise, if I have a 1024 byte read buffer, and I know my application
> will never want to receive more than 1024 bytes at a time, I pass my
> buffer off to recv(), does the sockets library keep trying to receive
> data until a completed stream of data has been received? or will I have
> to check that my self and loop until I have gotten my 1024 bytes that
> my application expects?
It's a stream, thus there is no such thing as 'all data' or 'complete
stream'.
You will have to check yourself, unless you use the MSG_WAITALL flag in
the call
to recv, which will try to fill up to the size of the buffer you gave to
recv. (even with that flag in might return less, in case of errors or
similar)
> And, what if I receive a full 1024 bytes and if element 1023 of my read
> buffer is not '\n' or '\r' (which to me would indicate there is more
> data to come) and I know that my application will never want to receive
> more than 1024 bytes of data, should I assume flooding?
You should expect the client to follow the application protocol you have
made. If it doesn't, there might not be much sensible you can do with
it. (so disconnect the client or take some other measures..)
- Next message: Lars Kellogg-Stedman: "Re: SCTP multihoming problems"
- Previous message: Kenneth Sparre Sørensen: "SCTP multihoming problems"
- In reply to: xucaen: "question about how to use send() and recv()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|