-
February 28th, 2011, 11:58 AM
#1
Winsock Connection Drop Detection
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.
Thx in advance.
-
February 28th, 2011, 02:30 PM
#2
Re: Winsock Connection Drop Detection
I believe L is part of a type cast.
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.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
ahoodin
To keep the plot moving, that's why.
-
February 28th, 2011, 03:27 PM
#3
Re: Winsock Connection Drop Detection
Originally Posted by ahoodin
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.
http://tangentsoft.net/wskfaq/newbie.html
2.14 - How do I detect an abnormal network disconnect?
THX for ur time.
-
February 28th, 2011, 03:33 PM
#4
Re: Winsock Connection Drop Detection
No L is an integer suffix that tell the compiler that the 1 should be interpreted as a long, not an integer (default for a plain number). See this http://msdn.microsoft.com/en-us/library/00a1awxf.aspx
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)
-
February 28th, 2011, 04:04 PM
#5
Re: Winsock Connection Drop Detection
Originally Posted by Alphadan
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.
ahoodin
To keep the plot moving, that's why.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|