Solved

timeout on sockets

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

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!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

752 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