🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Response not in que?

#6459
From: Bob Gonder
Date: Mon, 09 May 2005 22:03
38 lines
2335 bytes
Neil P. wrote:

>Well, I am using overlapped I/O.  The problem is that I don't want my code
>to lock up.

It won't lock up.
WaitForSingleObject() has a timeout value.
You should be running all this an a worker thread so the GUI stays
available to the user in any case.

If you want to use blocking reads/writes instead of overlapped
(blocking is easier to write and understand), then set a reasonable
timeout with SetCommTimeouts() so you don't lock up.

>If the other unit does not respond, I want the read function to quit, but
>what is a good time to quit?

Well, you expect to get a result in < 1 sec, so 2 second timeout seems
safe.  The speed of the CPU is mostly irrelevant at 9600 baud, unless
you are talking less than 1 MHz.

	WriteFile( f, "t", 1, &written, &overlap );
	status = WaitForSingleObject( hCommEvent, 1000 );
	if( status != WAIT_OBJECT_0 )
	{	/*handle the write error*/
	}else{
		GetOverlappedResult(.....);
		/* double check the write completed */

		ReadFile( f, buf, 1, &read, &overlap );
		status = WaitForSingleObject( hCommEvent, 2000 );
		if( status != WAIT_OBJECT_0 )
		{	/*handle the read error*/
		}else{
			GetOverlappedResult(.....);
			/* double check the read */
		};
	};
Technical Details
Message-ID: <nalv71h3qpjabvbq2fku2juim9ttqeeqp6@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <427fa27e@newsgroups.borland.com> <vugv711ona1kdbekucqqkg6csqkcd4agrd@4ax.com> <427fca8b$1@newsgroups.borland.com> <427fce92$1@newsgroups.borland.com> <427fd0af@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,369fa724017da622
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Response not in que?
Date: Mon, 09 May 2005 15:03:51 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <nalv71h3qpjabvbq2fku2juim9ttqeeqp6@4ax.com>
References: <427fa27e@newsgroups.borland.com> <vugv711ona1kdbekucqqkg6csqkcd4agrd@4ax.com> <427fca8b$1@newsgroups.borland.com> <427fce92$1@newsgroups.borland.com> <427fd0af@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: 67.77.41.187
X-Trace: newsgroups.borland.com 1115676228 67.77.41.187 (9 May 2005 15:03:48 -0700)
Lines: 41
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail