Hello, im using a SocketWrapper Named "SocketCom" it detects the connection drop fine but sometimes it doesnt... i have no idea why the socket thinks is online while is not.
this is the code which detects the connection drop
Code:
LPBYTE lpData = (LPBYTE)&stMsgProxy;
while( IsOpen() ){ // if the port is Open
// Blocking mode: Wait for event
dwBytes = ReadComm(lpData, dwSize, dwTimeout);
// Error? - need to signal error
if (dwBytes == (DWORD)-1L){
// Do not send event if we are closing
if (IsOpen()){
if ( bSmartAddressing ){
RemoveFromList( stMsgProxy.address );
}
OnEvent( EVT_CONDROP, &stMsgProxy.address ); // lost connection
}
As i understand it attemps to read data from the Socket and if the read bytes result in
(DWORD)-1L launches the EVT_CONDROP.
I have another doub what does the L means there?
and why would this fail to detect the connection drop while the Run Thread still running.
and why reading that would give the signal to detect connection drop.
If you use Winsock, WSAGetLastError() would return socket errors. The library you are using will have its own error checking implemented. Look in the Documentation.
If you use Winsock, WSAGetLastError() would return socket errors. The library you are using will have its own error checking implemented. Look in the Documentation.
thx for ur answer yea i read the documentation of recv and it says when the socket closes "gracefully" it will return 0 or the error values that i suposse they are negative values.
but i found that the sockets dont necesary detect Cable pull or anyother abnormal termination like crashes etc.
my program needs to handle these too but i think i fond the solution in this article.
For 32-bit MSVC the L isn't needed since an int is 32 bits and so is a DWORD (back in the 16-bit era the L was needed so the snippet might be from an old source)
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
thx for ur answer yea i read the documentation of recv and it says when the socket closes "gracefully" it will return 0 or the error values that i suposse they are negative values.
Well you have to see what these error values are. There should be a table or list somewhere. Otherwise you can't possibly know.
Bookmarks