Home > Archive > Unix Programming > January 2006 > send() returns 0 but poll() says I can write
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
send() returns 0 but poll() says I can write
|
|
| Jan Vidar Krey 2006-01-22, 9:59 pm |
| Hi all,
I have an application with a message loop where poll() is
called every now and then with a 25 ms timeout.
The application keeps at least two TCP connections at any time,
mostly idle with some protocol talk every few seconds, but at some point
large chunks of data may be transfered (typically hundreds of MB).
When a file is about to be sent I also add the POLLOUT to
pollfd.event for the given socket descriptor to poll for writability.
Before each send() I obtain the send buffer size (typically
getsockopt/SO_SNDBUF says 131072 bytes).
I try to send() that amount of data every time the revent detects POLLOUT.
After a while send() suddenly returns 0, and it keeps doing that
indefinitely.
The poll revent suggests the socket can still be written to, and
triggers always from that point on, which means the application goes into a
fairly tight and pointless loop.
During testing I've been using another agent on localhost which works as
designed, so I don't have any reason to believe there is anything wrong
with that.
I always check all return values, but no error is triggered here.
Getsockopt() for SO_ERROR concurs.
Any idea why this happens?
Cheers
-janvidar-
--
Jan Vidar Krey
Software engineer
| |
| phil-news-nospam@ipal.net 2006-01-22, 9:59 pm |
| On Mon, 23 Jan 2006 01:45:21 +0100 Jan Vidar Krey <janvidar@remove.me.extatic.org.remove.me> wrote:
| After a while send() suddenly returns 0, and it keeps doing that
| indefinitely.
| The poll revent suggests the socket can still be written to, and
| triggers always from that point on, which means the application goes into a
| fairly tight and pointless loop.
And is the buffer size still 131072 just before each send() when this
happens? How much are you actually trying to write? Could you do a
test to see if, which this condition occurs, if sending just 1 byte
per send() call would succeed?
--
-----------------------------------------------------------------------------
| Phil Howard KA9WGN | http://linuxhomepage.com/ http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/ http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------
| |
| Jan Vidar Krey 2006-01-22, 9:59 pm |
| phil-news-nospam@ipal.net wrote:
> And is the buffer size still 131072 just before each send() when this
> happens? How much are you actually trying to write? Could you do a
> test to see if, which this condition occurs, if sending just 1 byte
> per send() call would succeed?
Yes, the buffer size is retreived before every send(), and starting sending
just 1 byte after this condition occurs does not make any difference.
--
Jan Vidar Krey
Software engineer
| |
| Jan Vidar Krey 2006-01-22, 9:59 pm |
| Jan Vidar Krey wrote:
> phil-news-nospam@ipal.net wrote:
>
>
> Yes, the buffer size is retreived before every send(), and starting
> sending just 1 byte after this condition occurs does not make any
> difference.
Found it to be a separate programming error.
Reading from the file returned an EOF due to a wrong s () ``whence''.
--
Jan Vidar Krey
Software engineer
|
|
|
|
|