Using recv I want to get the http header so I can parse for a content length. However I’m having trouble detecting the line break. Or actually do I even have to detect line break or will the first time I read into the buffer always be the complete header (assuming I have a long enough buffer).
This is written in C.
edit: looking at some of the related questions one of the things I am worried about is
“…the “\r\n” of the header break might be pulled into your buffer by two different calls to recv() which would prevent your code from recognizing the header break.”
You should call recv() repeatedly and each time it gives you
xbytes you increase the buffer-pointer you give to it byxbytes (and decrease the cb it is allowed to write also byxbytes). You do this until your buffer either contains a\r\n\r\nor is completely full, in which case you just close the socket and ignore the malicious client from then on. Buffer-size should be about 3000 bytes.But: this ignores the general problem that your server seems to be a polling-server. If you have some experience you should try to make an epoll-server instead.