Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

timeout on sockets

Posted on 2011-02-24
7
Medium Priority
?
410 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 1000 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 35

Expert Comment

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

Sara
0
Industry Leaders: 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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

730 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