Link to home
Start Free TrialLog in
Avatar of Stanciu
Stanciu

asked on

pipes

Did you used pipes? How can I wait for a connection at the server end of the pipe (for a blocking pipe), without using ConnectNamedPipe() (that is a blocking function)? MSDN says that ConnectNamedPipe() only role is to wait for client connexion. I tried to replace this function with a while loop, but the client didn't connect:
 
while( LINK_OK != m_pCommServer->m_iLinkStatus )      
  {
   TRACE("HProtocolPipeServer::Wait() ~~~ Waiting client to connect\n");  
   GetNamedPipeHandleState (m_hPipe,&dwInstances,NULL,NULL,NULL,NULL,0);  
    if(1>dwInstances)
    {
       ::Sleep(100);
        continue;
    }
}
 
Thanx,
H
Avatar of oldbaby
oldbaby

ConnectNamedPipe() API is equivalent of tcp/ip accept()
(CreateNamedPipe() then maps to listen(...,backlog) where
backlog in your case is max number of pipe instances).
I hope this tcp/ip metaphore would help you understand
the mechanics of named pipe protocol.
To enable non-blocking mode (if your consern is about blocking while waiting for a client ) you woild have to use overlapped i/o e.g:
 //server dedicated thread function
 ...
 //connection event
 OVERLAPPED ov;
 ZeroMemory(&ov,sizeof(ov));
 //manually set event
 ov.hEvent = CreateEvent(NULL,TRUE,...);
 //start waiting for clients
 for(;;){
    TRACE("HProtocolPipeServer::Wait() ~~~ Waiting client  to connect\n");  
   DWORD dwRet = WaitForSingleObject(ov.hEvent,INFINITE);
   TRACE("HProtocolPipeServer::Wait() connected!\n");  
   if(WAIT_FALED == dwRet)
     continue;
   ResetEvent(ov.hEvent);
   //do some processing ,be as short as possible
  }
 
  Here I tried to replicate semantics of your code:)
 
Avatar of Stanciu

ASKER

I resolve this problem building some client pipes on server application, connecting these pipes to server pipes, and then closing'em all.

Thanx anyway,

H
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have refunded your 20 points to you for this question, since Netminder posted these comments in all your open questions to help you find them and finalize them, rather than posting a technical solution.  This has value in our PAQ so others can benefit.  

Hopefully you'll now move through the rest of your open questions and finalize them.  I also changed the grade from a "B" to an "A", since excellent information was posted.  Anytime you choose to grade less than an "A", please do take the time to comment as to why, everyone here strives to achieve "A" level support, and more experts are willing to help if you have a good closing/grading record.  It costs you the same number of points, regardless of grade given, but the expert points are increased, based upon grade.  In this case it doesn't matter, but wanted you to have this information for future decisions.

These links will help in these regards:

https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
https://www.experts-exchange.com/jsp/infoMemberAgreement.jsp

Moondancer
Community Support Moderator @ Experts Exchange