🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1416

Re: ConnectNamedPipe and closing Application

#1416
From: 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.
Technical Details
Message-ID: <n0loc3lensr7h15vp2pu2mejdfl4ic7ipj@4ax.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46cc5077$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,75a6e7b4be820a
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: ConnectNamedPipe and closing Application
Date: Wed, 22 Aug 2007 08:45:55 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <n0loc3lensr7h15vp2pu2mejdfl4ic7ipj@4ax.com>
References: <46cc5077$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.88.24
X-Trace: newsgroups.borland.com 1187797557 69.69.88.24 (22 Aug 2007 08:45:57 -0700)
Lines: 45
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 2228