HTTP client could not active close - a concept question
Hi,
I have ran the belows code and trace with Ethereal. Noticed that this app does not exit do_while loop when the html file has finished downloaded. It lingers in the loop and waits until remote server sends a 'FIN_ACK', then only it continues to check if (count > 0) and exit. Thus, it can never send an Active close to the remote server. If I remove the do_while loop, the app will send 'FIN'. May I know what has happened that causing the app idle in the loop, until server timeout? Can we fix the problem? int httpFileRequest(..){ if(createSocketConnection(&http_server_info) == SUCCESS) { // create and send the http GET request sprintf( stream_buf_p, "GET %s HTTP/1.1\r\nAccept: application/octet-stream\r\nHost: %s\r\nConnection: Keep-Alive\r\n\r\n",url_p, ipaddr_p); send( http_server_info.sock, stream_buf_p, strlen( stream_buf_p), 0); // get the answer from server and put it out to stdout do { count = recv( http_server_info.sock, stream_buf_p, sizeof(stream_buf_p), 0); // check if content_buf_p will overflow, // realloc to a multiple of MAX_STREAM_BUFFER_SZ if (count_bytes+count > curr_max_stream_bytes){ realloc(content_buf_p, curr_max_stream_bytes+MAX_STREAM_BUFFER_SZ); curr_max_stream_bytes += MAX_STREAM_BUFFER_SZ; } for (content_idx=count_bytes, stream_idx=0; content_idx < count_bytes+count; content_idx++, stream_idx++) content_buf_p[content_idx] = stream_buf_p[stream_idx]; #ifdef DEBUG //write( 1, buf_p, count); fprintf(stdout, "%s:%d:%s() - count=%u, content_idx=%u \n" \ , __FILE__, __LINE__, __FUNCTION__, count, content_idx); #endif count_bytes += count; } while (count > 0); // close the connection to the server close(http_server_info.sock); } } |
Hi,
I have ran the belows code and trace with Ethereal. Noticed that this app does not exit do_while loop when the html file has finished downloaded. It lingers in the loop and waits until remote server sends a 'FIN_ACK', then only it continues to check if (count > 0) and exit. Thus, it can never send an Active close to the remote server. If I remove the do_while loop, the app will send 'FIN'. May I know what has happened that causing the app idle in the loop, until server timeout? Can we fix the problem? Quote:
|
All times are GMT -5. The time now is 02:30 PM. |