Is there any way to associate callback functions with sockets in Linux?
For example,when the function
connect(sock, (struct sockaddr *)peeraddr, sizeof(*peeraddr))
has connected the client with the server, is there a way to associate a function "afterRecv
" with the socket of name sock
such that after function recv
has read some data from sock
, afterRecv
gets called?
That sock
is of blocking type. This is due to the many internal send/recv
calls on sock
during the handshake period of OpenSSL
.
If I modify OpenSSL
, it would be cumbersome to modify every recv
. So I wondered, if I can add a callback instead.
The flow should be:
connect
to socketrecv
functionWhen
recv
has read data,afterRecv
gets called as a callback onrecv
recv()
by your own version (wrapping around the originalrecv()
) would do the job, wouldn't it?