🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages Started by newbie Wed, 22 Aug 2007 15:04
ConnectNamedPipe and closing Application
#1415
Author: newbie
Date: Wed, 22 Aug 2007 15:04
19 lines
1557 bytes
Hello,

This is the first time I am using Pipes, so I am using code based on the Microsoft  example (Multithreaded Pipe Server) 
found at http://msdn2.microsoft.com/en-us/library/aa365588.aspx


I have implemented (copy\pasted) the code in a vcl form for 
testing purposes but it will eventually be moved to a 
TService.  As implemented, ConnectNamedPipe waits for a client 
to connect, however this locks the application which prevents 
the user from closing or any other actions. I assume this would 
also prevent me from closing or restarting a service aswell.

Any suggestions on how to change, or deal with this behavior?


Thanks in advance,
newbie
Re: ConnectNamedPipe and closing Application
#1416
Author: Bob Gonder
Date: Wed, 22 Aug 2007 15:45
42 lines
2370 bytes
newbie wrote:

> As implemented, ConnectNamedPipe waits for a client 
>to connect, however this locks the application which prevents 
>the user from closing or any other actions. I assume this would 
>also prevent me from closing or restarting a service aswell.

Yes, as long as you are using blocking code, it will block.
There are 4 ways to use this, but only 3 work.

1) Fully blocking
CreateNamedPipe in blocking mode.
ConnectNamedPipe( hP, NULL )

2) Asynchronous
CreateNamedPipe in blocking mode.
ConnectNamedPipe( hP, &Overlap )
WaitForSingleObject( event flag in Overlap, timeout)

3) Error
CreateNamedPipe in non-blocking mode.
ConnectNamedPipe( hP, NULL )
Must use Overlap on non-blocking pipe.

4) Asynchronous
CreateNamedPipe in non-blocking mode.
ConnectNamedPipe( hP, &Overlap )
WaitForSingleObject( event flag in Overlap, timeout)

>Any suggestions on how to change, or deal with this behavior?

Use 2 or 4 (4 would likely be prefered).
You probably want one thread per pipe in addition
to the main thread that handles the UI.

If the pipe handling is short, you might get away with
one worker thread that can handle up to 64 pipes
with WaitForMultipleObjects.

The worker threads would check a global flag every
time the WaitFor times out, and gracefully close all
the pipes, and exit.
Re: ConnectNamedPipe and closing Application
#1417
Author: Remy Lebeau (TeamB)
Date: Wed, 22 Aug 2007 16:41
13 lines
1388 bytes
"newbie" <ms_crack@yahoo.com> wrote in message
news:46cc5077$1@newsgroups.borland.com...

> Any suggestions on how to change, or deal with this behavior?

ConnectNamedPipe() supports overlapped I/O.  Simply provide an OVERLAPPED
structure to it, and the call will then always exit immediately.  You can
then use any of the various WaitFor...() functions along with
GetOverlappedResult() to implement a timeout in your code.


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