Solved

timeout on sockets

Posted on 2011-02-24
7
365 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 32

Expert Comment

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

Sara
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now