I need to read in only the values of a header that terminate with \r\n\r\n
Something like GETFILE OK 1024\r\n\r\n <content>
I'm trying to get the first \r\n
and then get the next pair in a subsequent recv call.
The call to this function is: read_in_header(gfr, headerRecvBuff, 1);
Issue: The logic in the while referring to \n
is completely ignored, or does not show any matches, when I know they exist. Is this the right way to compare the char newline?
int read_in_header(gfcrequest_t *gfr, char *buf, int len) {
char *s = buf;
int slen = len;
int c = 0;
int count = 0;
//get the first \r\n pair
do {
c = recv(gfr->client_fd, s, slen, 0);
printf("checking to see what s has now: %s\n", s);
count += c;
} while ((c > 0) && (s[count - 1] != '\n'));
//get the second \r\n pair
count = 0;
do {
c = recv(gfr->client_fd, s, slen, 0);
printf("checking to see what s has now: %s\n", s);
count += c;
} while ((c > 0) && (s[count - 1] != '\n'));
printf("checking to see what s has now: %s\n", s);
if (c < 0) {
return c;
} else if (c == 0) {
puts("Time to disconnect, the server is done.");
//total bytes received should not include header length
gfr->totalbytesReceived -= gfr->headerbytes_received;
return 0;
} else {
s[c - 1] = '\0';
}
gfr->totalbytesReceived += count;
return c;
}