Networking Forums

Networking Forums > Computer Networking > Linux Networking > non-blocking recv() problem when webserver disconnects

Reply
Thread Tools Display Modes

non-blocking recv() problem when webserver disconnects

 
 
Erik Larsson
Guest
Posts: n/a

 
      02-25-2004, 10:24 AM
I'm having trouble a non-blocking revc(). If I'm correct shall recv()
return the amount of bytes revived at particular moment, and return 0
when EOF and –1 when error.

My program connects to a web server and sends the "GET / HTTP1.1…."
the the socket starts to receive data from the web server. But recv()
NEVER returns 0 or –1. So the connection is never ended witch hangs
the program there until the socket timeouts.

Any ideas what can be wrong?

Here's some code:
FD_ZERO(&real_mask);
FD_SET(wget_s.getSock(), &real_mask);

tv.tv_sec = (long) 50000;
tv.tv_usec = (long) 0;

wget_s.set_non_blocking(true);

struct pollfd poll_list[1];
int t, q;

try
{

poll_list[0].fd = wget_s.getSock();
poll_list[0].events = POLLIN;
t=0;
q=1;
while(t != 1)
{
cout << poll(poll_list,(unsigned long)1,-1) << endl;

if(((poll_list[0].revents&POLLHUP) == POLLHUP) ||
((poll_list[0].revents&POLLERR) == POLLERR) ||
((poll_list[0].revents&POLLNVAL) == POLLNVAL))
{
cout << "Mysko" << endl;
return 0;
}

if((poll_list[0].revents&POLLIN) == POLLIN)
{
wget_s.set_non_blocking(false);

cout << wget_s.recv(wget_data) << " RECV" << endl;

cout << wget_s.send(" ") << " SEND" << endl;

cout <<wget_data.find("0",0) << endl;
cout << wget_data << endl;
}
}

}
catch (SocketException &e)
{
cout << "Exception" << endl;
}
 
Reply With Quote
 
 
 
 
Cameron Kerr
Guest
Posts: n/a

 
      02-26-2004, 07:02 AM
Erik Larsson <(E-Mail Removed)> wrote:
> I'm having trouble a non-blocking revc(). If I'm correct shall recv()
> return the amount of bytes revived at particular moment, and return 0
> when EOF and ?1 when error.
>
> My program connects to a web server and sends the "GET / HTTP1.1?."
> the the socket starts to receive data from the web server. But recv()
> NEVER returns 0 or ?1. So the connection is never ended witch hangs
> the program there until the socket timeouts.


It sounds like its not being set non-blocking. Run it through strace to
see what the system calls are doing.

But what's the point? You're polling as well as non-blocking? You only
really need one method or the other.

--
Cameron Kerr
(E-Mail Removed) : http://nzgeeks.org/cameron/
Empowered by Perl!
 
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
recv() problem, need help!! michal.shmueli@gmail.com Linux Networking 4 04-10-2006 04:33 PM
recv() problem? michal.shmueli@gmail.com Linux Networking 8 01-11-2006 08:14 PM
recv() problem? michal.shmueli@gmail.com Linux Networking 5 01-10-2006 01:55 PM
recv() problem? michal.shmueli@gmail.com Linux Networking 1 01-09-2006 04:33 AM
recv() problem? michal.shmueli@gmail.com Linux Networking 0 01-08-2006 07:55 AM



1 2 3 4 5 6 7 8 9 10 11