Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Andrue Cope
Tue, 24 Apr 2007 12:52
recv() stops blocking/no events detected.
Author: 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
Re: recv() stops blocking/no events detected.
Author: Andrue Cope
Date: Tue, 24 Apr 2007 14:05
Date: Tue, 24 Apr 2007 14:05
7 lines
1082 bytes
1082 bytes
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
Re: recv() stops blocking/no events detected.
Author: Remy Lebeau (TeamB)
Date: Tue, 24 Apr 2007 16:24
Date: Tue, 24 Apr 2007 16:24
18 lines
1418 bytes
1418 bytes
"Andrue Cope" <no.spam@not.a.valid.address> wrote in message news:462dfd7f@newsgroups.borland.com... > myThreadID(GetCurrentThreadId()) You are retreiving the ID of the thread that calls the constructor, not the ID of the thread being created. > 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads