When data is sent over a Socket, when does send/write returns -1?
Linux. Tcp socket.
When does a send()/write() command fail?
开发者_如何学编程Does it return -1 only if the TCP send buffer in the kernel overflow?
From the OpenGroup definition for write():
Upon successful completion, write() [XSI] and pwrite() shall return the number of bytes actually written to the file associated with fildes. This number shall never be greater than nbyte. Otherwise, -1 shall be returned and errno set to indicate the error.
The same thing is done for send() - OpenGroup page for send()
You will find out more information by looking at the errno. See the OpenGroup page on errno for some more information.
To your specific point - if your write call was blocking, (as is the default), an overflow would just block you until there was buffer space available.
If the write call was non-blocking, and the buffers were full, you would receive an error.
精彩评论