 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andrue Cope Guest
|
Posted: Tue Apr 24, 2007 5:52 pm Post subject: recv() stops blocking/no events detected. |
|
|
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 |
|
| Back to top |
|
 |
Andrue Cope Guest
|
Posted: Tue Apr 24, 2007 7:05 pm Post subject: Re: recv() stops blocking/no events detected. |
|
|
Ah ha! It's all related to the events. If I don't call WSACreateEvent()
recv() goes back to blocking.
--
Andrue Cope
[Bicester, Uk]
http://info.borland.com/newsgroups/guide.html |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Apr 24, 2007 9:24 pm Post subject: Re: recv() stops blocking/no events detected. |
|
|
"Andrue Cope" <no.spam (AT) not (DOT) a.valid.address> wrote in message
news:462dfd7f (AT) newsgroups (DOT) borland.com...
| Quote: | myThreadID(GetCurrentThreadId())
|
You are retreiving the ID of the thread that calls the constructor,
not the ID of the thread being created.
| Quote: | DWORD eventID=WSAWaitForMultipleEvents(1,
&myNetworkEvent,FALSE,WSA_INFINITE,FALSE);
[snip]
|
You did not call WSASelectEvent() first to specify which socket
event(s) are to be associated with the event object.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|