Search code examples
socketshttpnewlinerecv

CRLF causes read() from socket to return


I'm writing an HTTP server in C++, using a TCP socket to communicate between client and server.

While sending a request to the server using my Linux terminal, I've noticed that each time I press Enter, the read() on my server returns (it reads up to the \r\n and returns).

Is this behavior "normal" ? I have not found it mentionned anywhere.

EDIT: I'm using telnet as client and a blocking read/recv


Solution

  • A blocking read or recv returns whenever data are available. If you enter Enter on whatever you use on the terminal as client (i.e. netcat, telnet or similar) it will likely (depending on the actual client) directly send this \r\n to the server where it will cause an immediate successful return of read/recv.