pada123 wrote:
If you have some time you can run that in your machine and check it will be very help full....I dont know if there is other mistake in code i have done...and if it socket closing problem as you mention in TCP level...what step i should take to resove that
Like I said. There is no call to shutdown() in transport.cpp.
I'm not running your code on my computer (its nothing personal) but there are some things that I can see without running it.
Firstly check out the MSDN page for
recv[
^] and also
send[
^], in particular check out the return values:
If the connection has been gracefully closed, the return value is zero.
In the function
CThread()
where you are receiving from the proxy, you need to check the return value of
recv()
for 0 because that means the proxy has closed the connection, you then need to pass that onto the web browser with a call to
shutdown()[
^]
if(FD_ISSET(*(con->csock),&fd)) {
char buf[1024];
int len=recv(*(con->csock),buf,1024,0);
if (len == 0) shutdown(*(con->csock), SD_BOTH);
if(len<=0) return 0;
printf("remot->local %d B \r\n",len);
send(*(con->lsock),buf,len,0);
}
if(FD_ISSET(*(con->lsock),&fd)) {
char buf[1024];
int len=recv(*(con->lsock),buf,1024,0);
if (len == 0) shutdown(*(con->lsock), SD_BOTH);
if(len==-1) return 0;
printf("local->remote %d B\r\n",len);
send(*(con->csock),buf,len,0);
}
This is just a start, you should be checking the return from
send()
as well.
Lastly, you have
HANDLE hand=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)CThread,(LPVOID)&tsock,0,NULL);
WaitForSingleObject(hand,INFINITE);
Unless you plan on expanding this later, it is pointless.