LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2006, 03:17 AM   #1
syseeker
Member
 
Registered: Aug 2003
Posts: 66

Rep: Reputation: 15
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);
}
}
 
Old 02-08-2006, 03:22 AM   #2
syseeker
Member
 
Registered: Aug 2003
Posts: 66

Original Poster
Rep: Reputation: 15
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);
}
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Active FTP Client Problems Sarcha Linux - Networking 2 06-29-2005 03:59 PM
connecting to X using Cygwin : Concept Question, not technical linuxquestions.fructose Linux - Software 0 08-28-2004 03:43 PM
Question: the concept of suid and sgid feetyouwell Linux - Software 4 02-03-2004 04:12 PM
teaching active directory w/o teaching network concept (possible???) Tafta General 4 01-21-2004 06:12 PM
Apache 1.3.20 close connection on HTTP 1.1 400 500 errors dafri Linux - Software 4 01-14-2003 08:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration