Solved

timeout on sockets

Posted on 2011-02-24
7
393 Views
Last Modified: 2012-05-11
I am using  #include <poll.h>  on Linux

Client is continously sending data using send(). I am using poll before timeout. after few sends() poll timeouts.
Under what circumstance would poll(fds, 1, timeout)  will timeout?


0
Comment
Question by:learningunix
  • 5
7 Comments
 

Author Comment

by:learningunix
ID: 34976926
here's my poll code before send

while (1)
   struct pollfd sd;
    int return_value = 0;

    sd.fd = socket;
    sd.events = POLLOUT;
    return_value = poll(&sd, 1, timeOut);
    send();

}

after few iterations return_value = 0 which means somehow i can't write. not sure why would this happen?
0
 
LVL 8

Accepted Solution

by:
ssnkumar earned 250 total points
ID: 34976991
> Under what circumstance would poll(fds, 1, timeout)  will timeout?
Timeout will happen only if the socket descriptor that you have specified is not ready for I/O till the time timeOut occurs.

From the code snippet, I see that you are using send() without arguments!
I assume that you haven't given the complete code.
Still, I want to know, what is the socket descriptor that you are using with send().
And what are you doing with the socket sd.fd?

> after few iterations return_value = 0
That means timeout happened and still the sd.fd is not ready for I/O.

So, without knowing exactly what you are trying to do here, it is very difficult to understand the problem. Please give more details.
0
 
LVL 33

Expert Comment

by:sarabande
ID: 34977720
why do you call poll at all?

Sara
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:learningunix
ID: 34979256
Its an old application which is using poll if POSIX (meaning on unix platform)

Why the socket is not ready to write? is it because too much data has been already return and there is no one receiving packet on that socket?
0
 

Author Comment

by:learningunix
ID: 34979292
also one thing I need to understand.

If the poll returns 0 that means the socket connection is still alive (client is still alive). Its just that socket is not ready to accept new packet. Correct? In that case I can retry?
0
 

Author Closing Comment

by:learningunix
ID: 34979904
thx
0
 

Author Comment

by:learningunix
ID: 34979906
I just retried and it worked fine.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Focus not getting shifted out of  editbox 2 66
Add values of each row in an array 3 64
Error C2678: binary '!=': no operator found... 4 61
Android development question 2 55
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question