I would like a way to be able to peek data from a tcp connection, without actually taking it from the socket output, so I can read it later. For example, peeking the TLS ClientHello to inspect the SNI hostname and then either upgrading the connection via ssl.handshake, or tunneling the encoded TCP stream with the ClientHello somewhere else.
Erlang's gen_tcp does not allow setting socket flags like MSG_PEEK on recv calls to do this.
However, according to this old issue and the gen_tcp source:
-export([send/2, recv/2, recv/3, unrecv/2]).
There exists a function gen_tcp:unrecv that does this in a hacky way. Could this be added to glisten/tcp, barring any plans to switch to the newer socket module?
I would like a way to be able to peek data from a tcp connection, without actually taking it from the socket output, so I can read it later. For example, peeking the TLS ClientHello to inspect the SNI hostname and then either upgrading the connection via
ssl.handshake, or tunneling the encoded TCP stream with the ClientHello somewhere else.Erlang's gen_tcp does not allow setting socket flags like MSG_PEEK on recv calls to do this.
However, according to this old issue and the gen_tcp source:
There exists a function
gen_tcp:unrecvthat does this in a hacky way. Could this be added toglisten/tcp, barring any plans to switch to the newersocketmodule?