Cheap fd, where I can control whether select thinks its readable, but is always (I wouldn't balk at controllable) whether select thinks that its writable.
Bill Freeman
ke1g.nh at gmail.com
Fri Dec 6 17:34:08 EST 2013
I'm using a "library" (*) that emulates an open socket (**). That is, has
send(), recv(), and close() operations (methods). It will also (upon
demand) cough up a *nix file descriptor, suitable for the first argument to
select(). That is, select will respond to the channel having bytes you can
read by returning, and with this FD indicated as readable.
Since the channel is a software construct, and not an OS item, it
synthesizes the FD's behavior by using a pipe. The FD returned is for the
read side of the pipe. When it has bytes you can read from the channel
(with recv()), it writes a single byte to the other FD of the pipe, and,
lo, select returns, indicating read ready on the "channel". When all the
available data has been read, the channel (down deep in recv()) drains the
pipe, and select no longer thinks that there is data.
This is all great, except that I'm using this with another library that
runs a loop in a thread, calling select, with the provided FD in both the
readable and writable arguments, waiting for readability before recv-ing
from this socket, BUT ALSO waiting for write-ability before send-ing on
this socket.
Sadly, the read end of a pipe never appears writable to select (as the FD
of a real socket would, at least when the buffer isn't full). Since I need
to send before I get responses, nothing ever happens.
I could patch the other library to always add in the FD as writable
whenever select returns, and us the timeout argument so that it will return
(messy). But I need to be able to accept updates of that library, so
patching becomes an endless task.
Now, I'm happy to reach into the channel code far enough to catch the
notifications that there is or isn't data to read, and provide my own FD to
the other library, but I need one whose readability I can control, and
whose write-ability I can control or which is always writable.
Can anyone think of something short of a pair of sockets that will work for
me?
(* paramiko, used from python.)
(** A 'direct-tcp' "channel" for those who know paramiko, a means to open a
socket from the other end of your ssh connection, such as would be used in
port forwarding, except I'm using it directly from python, rather than
wiring it to another socket at the local end.)
Thanks, Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.gnhlug.org/mailman/private/gnhlug-discuss/attachments/20131206/aee2af57/attachment.html
More information about the gnhlug-discuss
mailing list