A socket client program establishes a connection with the server,
writes some bytes and waits for response using the (blocking) read()
.
But this fails with the error EINVAL
("Invalid argument").
Previous calls to create()
, bind()
and connect()
the socket have been made successfully.
My Question
- What's wrong here?
Platform is Linux x64.
fd is attached to an object which is unsuitable for reading; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the current file offset is not suitably aligned.
See http://www.kernel.org/doc/man-pages/online/pages/man2/read.2.html
The problem was that I passed a size of 1 byte to the read()
function.
It seems that this is not supported
(why? what is the minimum size? must it be a multiple of 2/the bitness of the platform?).
Now I am passing 8 and it works. Thank you all for your comments.
来源:https://stackoverflow.com/questions/6018974/sockets-what-is-causing-read-to-return-einval