| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | blockreading from a pipe |
//
// ************************************************************************
// Demonstration of how DosRead works with pipes.
// (c) Copyright 1996 Jonathan de Boyne Pollard. All rights reserved.
// ************************************************************************
//
//
// Permission is hereby granted to post, steal, and abuse this source for
// your own purposes and to your heart's content as long as you understand
// that I take no responsibility whatsoever for what it may do to your
// machine, data, cat, or marital status.
//
#define INCL_BASE
#include
#include
#include
//
// This program demonstrates what appears to be a common misconception
// with pipes. The misconception is that DosRead will block indefinitely
// until the read buffer is completely full. This is not true. DosRead
// will empty the pipe's data buffer, and return immediately. Only if
// there are no data at all will DosRead block. This is because a count
// of zero bytes does *not* mean a partial buffer with zero bytes in it.
// It has the special meaning that the write end of the pipe has been
// closed.
//
static HFILE ReadHandle, WriteHandle ;
static
void
readthread ( void * )
{
char buffer [1024] ;
ULONG BytesRead ;
do {
DosRead(ReadHandle, buffer, sizeof buffer, &BytesRead) ;
cout << "\t\t\t\tRead " << BytesRead <<
" bytes." << endl ;
} while (BytesRead) ;
}
int
main ( int, char ** )
{
DosCreatePipe(&ReadHandle, &WriteHandle, 256) ;
cout << hex << "Created pipe, read = " << ReadHandle
<< ", write = " << WriteHandle << dec
<< endl ;
TID Thread1 = _beginthread(readthread, 0x40000, 0) ;
char buffer [1024] ;
ULONG BytesWritten ;
DosWrite(WriteHandle, buffer, sizeof buffer, &BytesWritten) ;
cout << "Wrote " << BytesWritten << "
bytes." << endl ;
DosWrite(WriteHandle, buffer, 1, &BytesWritten) ;
cout << "Wrote " << BytesWritten << "
bytes." << endl ;
DosWrite(WriteHandle, buffer, sizeof buffer, &BytesWritten) ;
cout << "Wrote " << BytesWritten << "
bytes." << endl ;
DosClose(WriteHandle) ;
cout << "Closed write handle." << endl ;
DosWaitThread(&Thread1, DCWW_WAIT) ;
return 0 ;
}
> JdeBP <
___
X MegaMail 2.10 #0:
--- Maximus/2 3.01
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)SEEN-BY: 50/99 270/101 620/243 625/160 711/401 409 410 413 430 808 809 934 SEEN-BY: 711/955 712/407 515 624 628 713/317 800/1 @PATH: 440/4 141/209 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.