Article View: borland.public.cppbuilder.internet.socket
Article #1178recv() stops blocking/no events detected.
From: Andrue Cope
Date: Tue, 24 Apr 2007 12:52
Date: Tue, 24 Apr 2007 12:52
61 lines
2299 bytes
2299 bytes
Hiya
I am developing a simple server application and I have a primary thread
which looks for incoming connections (using accept()). This thread is
correctly blocking on the socket. When an incoming connection is
detected this primary thread creates a service thread to handle the
connection.
My problem is twofold:
1.Originally the service thread used WSAWaitForMultipleEvents() but it
never seemed to receive any events:
KOWinsockConnector(SOCKET connectionSocket)
:mySocket(connectionSocket),
myRunning(false),
myNetworkEvent(WSACreateEvent()),
myThreadID(GetCurrentThreadId())
{
}
// Service thread
virtual DWORD Run()
{
myRunning=true;
printf("%u:Listener thread started.\n",myThreadID);
while(true)
{
DWORD eventID=WSAWaitForMultipleEvents(1,
&myNetworkEvent,FALSE,WSA_INFINITE,FALSE);
[snip]
2.I changed the code to just call recv(). This echoes incoming data
correctly but it isn't blocking.
// Service thread
virtual DWORD Run()
{
myRunning=true;
printf("%u:Listener thread started.\n",myThreadID);
while(true)
{
char str[1024];
int recvLength = recv(mySocket,str,sizeof(str),0);
if(recvLength&&
(recvLength<sizeof(str)))
{
str[recvLength] = '\0';
printf("%u:%s\n",myThreadID,str);
}
[snip]
Can anyone shed any light on this?
--
Andrue Cope
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<462dfd7f@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,757efd80047970e6,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Andrue Cope" <no.spam@not.a.valid.address> Subject: recv() stops blocking/no events detected. Newsgroups: borland.public.cppbuilder.internet.socket User-Agent: XanaNews/1.18.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 217.207.223.34 Message-ID: <462dfd7f@newsgroups.borland.com> Date: 24 Apr 2007 05:52:15 -0700 X-Trace: newsgroups.borland.com 1177419135 217.207.223.34 (24 Apr 2007 05:52:15 -0700) Lines: 61 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail