Can add some api to export the fd ?
For example, add some api like dill_tcp_get_fd, by using it, it provides the possibility to do something like ioctl: ioctl(dill_tcp_get_fd(s), SIOCOUTQ, &pending);
The problem is that libdill socket layer can (and does) do some buffering itself. Thus, when you extract the underlying socket it can be in an inconsistent state, without libdill-layer buffers being pushed into it. That way SIOCOUTQ becomes quite useless.
Possible solution: Don't use dill sockets. Use a POSIX socket instead and integrate it will libdill via fdin/fdout.
If use a POSIX socket with the fdin/fdout, then I need to do the same thing as dill_tcp_connect, there are lots of work.