Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Tue Mar 24, 2009 5:06 pm Post subject: recv problem |
|
|
hello,
I'm coding my own little http lib atm and I'm having a problem with recv.
| Code: | int bytes_read;
char rvBuffer[512];
string h_body;
string response;
do
{
bytes_read = recv(s, rvBuffer, sizeof(rvBuffer), 0);
response += rvBuffer;
if(response.find(RHTTP_CONTENT_END) != -1)
{
//h_body.assign(response, response.find("\r\n\r\n")+4, response.length());
//h_body.assign(h_body, 0, h_body.length()-8);
//printf("%d\n", h_body.c_str()[h_body.length()]);
break;
}
}
while ( bytes_read > 0 );
printf("response: %s\n", response.c_str()); |
So the while-loop to recv only breaks if the socket was closed or R_HTTP_CONTENT_END was found in response. But later when it printfs out the response it appears to ALWAYS replaces the bytes of the last packet with very weird bytes.
I'm very confused because this always only happens with the last packet reviced.
What's happening to them?
Edit: I forgot to call ZeroMemory() on rvBuffer. Hmm weird how it acts when I don't call it though.
Thanks ..to myself Lol.
Edit2: Also using std:string+= isn't that good, I suggest using std:string.append(rvBuf, bytes_recv).
|
|