SO_RCVWAKEUP & SO_SNDWAKEUP
gene.smith at siemens.com
Tue Sep 30 15:44:34 UTC 2003
I am far from an expert on this but I have fairly successfully used these
function in a complex application. The callbacks are called by the same
criteria that the unix select function uses for ready sockets. If you have
the Stevens book "Unix Network Programming" on page 153-154 the section
"Under what Conditions Is a Descriptor Ready?" you will find the definitive
list of conditions for readable and writable.
When the received bytes equals or exceeds the "low water mark" (default 1
byte) you get a readable callback. If there are 100 bytes in the receive
buffer and you only read 1, you will not get another callback. You will get
another callback only after you read all 100 bytes and at least 1 more
arrives. With a non-blocking socket you should read until read returns
EWOULDBLOCK and then wait for the readable callback to tell you when more
data has arrived. (Rule 1.a).
For sending when the socket connects and the free space is above the "low
water mark" (default 4096 bytes) you will get a single writable callback.
You don't get continuous callbacks if you don't write anything. Using
non-blocking write socket, you can then write until write returns less than
the amount of data sent or EWOULDBLOCK (indicating no longer writable). When
this happens you can try to write again, but it is better to just wait for
another writable callback to tell you when space is available to send again.
I think you only get a writable callback when the free space transitions to
above the "low water mark" in a kind of "edge triggered" manner and not
automatically every time you write. (Rule 2.a)
The remaining rules handle the fact the sockets become readable and/or
writable when connects, disconnects and errors occur, not just when data is
received or sent.
From: Rolf Schroedter [mailto:Rolf.Schroedter at dlr.de]
Sent: Tuesday, September 30, 2003 3:25 AM
To: rtems-users at rtems.com
Subject: SO_RCVWAKEUP & SO_SNDWAKEUP
Seems I need some clarification on the SO_RCVWAKEUP & SO_SNDWAKEUP
Will it be called once when data arrives or repeatedly when
data is available ? E.g. What happens, if the application
doesn't read *all* available data from the socket, but leaves
some bytes in the input queue ? Will there be a 2nd SO_RCVWAKEUP
Will I have exactly one callback after each write() call,
or repeated callbacks whenever there is space available
in the output buffer ?
IMO that's important to know to avoid application deadlocks.
German Aerospace Center
More information about the users