Search code examples
csocketsioblockingnonblocking

Sockets: What is causing read() to return EINVAL?


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.


Solution

  • 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.