879 Subj : Re: Threading and Timeouts To : comp.programming.threads From : Giancarlo Niccolai Date : Wed Jul 20 2005 11:18 pm David Schwartz wrote: > > "Giancarlo Niccolai" wrote in message > news:dbldbm$blc$2@newsread.albacom.net... > >> Sorry, missing last lines: >> >> """ >> The length of the message to be sent is specified by the length argument. >> If >> the message is too long to pass through the underlying protocol, send() >> shall fail and no data shall be transmitted. >> """ >> >> So there's no way a write() call on a very long set of data will block >> until >> all the data is sent. Write()/send() will always write what it can (or >> refuse to write large blocks if the protocol can't handle it i.e. UDP), >> and >> immediately return after a single send() operation is posted to the >> network >> stack. Select saying "socket ready" determines that the network stack >> won't >> block the next operation on that socket. > > What? What if the message is longer than the available buffer space > but > not longer than the underlying protocol can pass? > > DS No; if the underlying protocol can accept data fragmentation (i.e. TCP), write() will post to the network layer exactly the data that can pass in that moment (and will return how many characters have been delivered), while if the protocol cannot fragment data (i.e. UDP), select() won't declare the socket ready until it is certain that the next operation can pass unblocked, that is, that there is enough buffer space to accept the longest possible data send for that protocol. Of course, select()/network stack is free to wait for "better opportunities" to i.e. declare a TCP socket ready when there's more than just some byte of free space in the buffers, but that's not required by the standard. If any of this weren't the case, then the POSIX specifications about select() wouldn't be possibly fulfilled, as it explicitly says that after that select() declares a socket ready, it MUST NOT BLOCK the very next operation for which select() was queried . Bests, Giancarlo Niccolai. . 0