Hi Mark,
I am still having the same issues (after copying over tcp.c). I placed some messages on the screen and debugged the code and this is what is happening.
The first time around TCP_STATE_CLOSED is called and I mark the socket as to be used again (within my own code). When I try to re-use the socket the TCP_STATE_CLOSED is called again , as within the fnTCP_Connect() function :
if (!(ptr_TCP->ucTCP_state & (TCP_STATE_RESERVED | TCP_STATE_LISTEN | TCP_STATE_CLOSED))) { // are we in an invalid state?
#ifdef REUSE_TIME_WAIT_SOCKETS
if (ptr_TCP->ucTCP_state & (TCP_STATE_FIN_WAIT_2 | TCP_STATE_TIME_WAIT)) {
fnNewTCPState(ptr_TCP, TCP_STATE_CLOSED);
ptr_TCP->event_listener(ptr_TCP->MySocketNumber, TCP_EVENT_CLOSED, ptr_TCP->ucRemoteIP, ptr_TCP->usRemport); <<< gets called again.
}
else {
return (SOCKET_STATE_INVALID);
}
As I mark each socket to be reused within the TCP_STATE_CLOSED, getting called again, simply marks as re-use. I checked the value of ptr_TCP when TCP_STATE_CLOSED was called and when the above was called to make sure the pointer address was the same, and they were.
I assume this is the reason why my code always works when calling fnGetTCP_state(..) before reusing the socket.
Looking at usOurPort parameter within fnTCP_Connect(..) function, should this be set to 1 if reusing a socket ? I noticed withing the fnTCP_Connect(..) function ,fnGetFreeTCP_Port() gets called if usOurPort=0. I tried setting to 1 , but still no luck.
Regards
Neil