BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

recv() stops blocking/no events detected.

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
Andrue Cope
Guest





PostPosted: Tue Apr 24, 2007 5:52 pm    Post subject: recv() stops blocking/no events detected. Reply with quote



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





PostPosted: Tue Apr 24, 2007 7:05 pm    Post subject: Re: recv() stops blocking/no events detected. Reply with quote



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





PostPosted: Tue Apr 24, 2007 9:24 pm    Post subject: Re: recv() stops blocking/no events detected. Reply with quote



"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.