To ensure optimal performance, this will be solved by filtering in the network stack, but the details of this will depend on the operating system (this is not part of the socket interface, and your application, as a rule, does not even have rights to configure the network stack in this way.)
Another possibility is after accept
, by this time the connection has already been accepted (CONNECT ACK) at the TCP level.
I do not think that you can do this in the middle phase, where you prefer it. However, this will not differ much from this after accept
.
source share