Take the 2-minute tour ×  I have implemented a forward proxy in
linux which listens on few ports. Whenever a connection happens
it puts into outer world. My setup looks as follows:
Outerworld<----->Proxy(Listens on Port
A)<------->Browser(Configured with proxy set toPort A)  However,
I am not sure when to close the connection between proxy-outer
world and proxy-browser. I was under impression that if I see a
packet with data size 0 (recv()) then it is end of communication
from client side. Once I get "recv()=0", I do "close()" with
outer world. Is this the right way to do? Or should I do
shutdown()? Also, I think sometimes browser sends a a "FIN" with
data packet and I fail to catch it. I sometimes see connection
from browser on a socket which was never closed. (Linux reuses
the same fd numbers. That is one of the reason, I believe I am
missing socket closure.)  Where could I be going wrong.
share|improve this question add comment  1 Answer  up vote 2
down vote accepted  For a generic TCP forwarder, shutdo