Article View: borland.public.cppbuilder.internet.socket
Article #4262Re: breaking blocking socket
From: Bob Gonder
Date: Fri, 11 Mar 2005 15:35
Date: Fri, 11 Mar 2005 15:35
29 lines
1724 bytes
1724 bytes
Adam wrote:
>Is it possible to break blocking socket ?
>For instance: while using socket in thread - function: recvfrom(), I will
>close this socket from main thread. Is it possible ?
>thanks
If you close the socket, the recv will return with error.
The code in your thread should notice the error and exit.
Also, perhaps more gracefull...use
main:
shutdown( sok, SD_BOTH );
closesocket( sok );
thread:
if( SOCKET_ERROR == recvfrom() )
{
if( WSAESHUTDOWN == WSAGetLastError() )
{ ExitThread(1);//main shut us down
}else
//handle other errors
};
}else{
//process the data
};
WSAESHUTDOWN The socket has been shut down; it is not possible to
recvfrom on a socket after shutdown has been invoked with how set to
SD_RECEIVE or SD_BOTH.
Technical Details
Message-ID:
<uud331hn6a9n957dqk8fttnapniifp97g9@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4231568b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a69a85a7f710f262 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: breaking blocking socket Date: Fri, 11 Mar 2005 07:35:50 -0800 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <uud331hn6a9n957dqk8fttnapniifp97g9@4ax.com> References: <4231568b@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.145.168 X-Trace: newsgroups.borland.com 1110555350 67.77.145.168 (11 Mar 2005 07:35:50 -0800) Lines: 31 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail