Solved

timeout on sockets

Posted on 2011-02-24
7
408 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

Expert Comment

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

Sara
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

623 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