LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   HTTP client could not active close - a concept question (https://www.linuxquestions.org/questions/programming-9/http-client-could-not-active-close-a-concept-question-412909/)

syseeker 02-08-2006 03:17 AM

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);
}
}

syseeker 02-08-2006 03:22 AM

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:

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);
}
}


All times are GMT -5. The time now is 02:30 PM.