I am writing a small HTTP server on C, using select() and non-blocking sockets, but I have found myself with an issue.
When I accept a connection and try to read the HTTP Request (from a BROWSER, i.e: Mozilla Firefox) using the recv() function with 1024 length buffer. I get the whole request just fine. But in a general way, I don't know if recv() gave me the whole request or piece of it, meaning I don't know if I should keep reading or send a HTTP Response back to the client (BROWSER). What happens is as follows:
Will errno be set to EAGAIN/EWOULDBLOCK if the recv() function only read a piece of the request, or only if it has reached the end of the request and there is no more to be read? How to handle that?
Neither. It will be set to that value if there is no more data immediately available to be read.
recv() doesn't know the HTTP request format from third base.
You need a good knowledge of RFC 2616 and friends to implement HTTP, specifically the parts about content-length and chunked encoding. You cannot do without it.