I want to write a specific number of bytes to a socket,
n=write(sock_fd, buf, len);
if n<len
, I would rather no bytes are written into the socket,
is it possible or not?
thanks!
I want to write a specific number of bytes to a socket,
if |
|||||
|
|
|||||||||||||||||||
|
If the socket is in blocking mode then, as EJP (+1) says, write() will not return until len bytes have been written to the socket's outgoing buffer. However, it's important to note that that doesn't tell you anything about how many bytes have been received at the receiving end of the connection. In fact for small values of len when write() returns no data has been sent at all (yet). And when the other end calls read() it will block until some data has arrived, but not necessarily len bytes. If you want to read len bytes then you may have to keep calling read() until you have got them all. The only real way to know what's actually happened and when it finished is to have some sort of message being returned from the other end of the socket to say that everything has now arrived. A confirmatory return from write() is not enough by itself. |
|||
|