Article View: borland.public.cppbuilder.nativeapi
Article #217Re: events and overlapped structures
From: Remy Lebeau (TeamB)
Date: Tue, 08 Jul 2008 20:05
Date: Tue, 08 Jul 2008 20:05
63 lines
3236 bytes
3236 bytes
"Lesley Anne" <mspfila (dash) brl (at) yahoo (dot) com> wrote in message news:4873b98e$1@newsgroups.borland.com... > In our initial (non-overlapped) version, it got stuck in the ReadFile > function. You could use PeekNamedPipe() to avoid that. > This is why we went to the overlapped structure, so that we could tell it > to stop trying to read, even if it hadn't read anything. Are you openng the pipe in overlapped mode to begin with? You can only pass an OVERLAPPED structure to ReadFile() if the pipe has the FILE_FLAG_OVERLAPPED flag enabled. > We still get stuck trying to read Then you are not using overlapped I/O correctly. > so I'm trying to figure out why our stop event isn't working. Is you code getting into WaitForMultiObjects() to begin with? Or is it getting stuck in ReadFile()? > pReadThread = new TReadThread(hReadPipe, gbl_hStopEvent); How are you creating hReadPipe exactly? > When we want to close the connection we have a Cleanup function > which triggers the reading thread to terminate and sets that > gbl_hStopEvent > so that the reading thread will get out of its WaitForMultipleObjects > call and see that it was terminated. Only if it reaches WaitForMultipleObjects() to begin with. > The problem is that the thread isn't seeing that gbl_hStopEvent. If it > isn't getting data to read, then it remains permanently stuck > (presumably in its WaitForMultipleObjects call). Don't presume anything. Debug your code and find out exactly where it is getting stuck. > What's more, since that's using the read pipe, the main unit is > unable to DisconnectNamedPipe(hReadPipe) so then that gets > stuck as well. Wait until the thead terminates before you disconnect. > ResetEvent(StopEventHandle); I would not do that inside the thread. What if you want to terminate the thread before it begins running? Your main thread would signal the event, and then the thread would reset it and continue running. Since the event is created intially unsignaled, there is no need for the thread to reset it. > ResetEvent(HandleArray[0]); You don't need to do that. ReadFile() will handle that for you. Gambit
Technical Details
Message-ID:
<4873c8f0$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4873b98e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e9d4b7e876cb4c6a X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4873b98e$1@newsgroups.borland.com> Subject: Re: events and overlapped structures Date: Tue, 8 Jul 2008 13:05:50 -0700 Lines: 65 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <4873c8f0$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1215547632 207.178.157.90 (8 Jul 2008 13:07:12 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail