1
/** Implementation of the isapistream class.
2
* @file isapistream.cpp
3
* @author Christian Aberger
4
* Copyright (C) 2001 WebWare (http://www.webware.at)
6
#include "isapistream.h"
10
isapistreambuf::isapistreambuf(EXTENSION_CONTROL_BLOCK *pECB)
13
static const int nMinBufSize = 1024;
15
setp(_obuf, _obuf + sizeof _obuf);
17
_cbTotalBytes = pECB->cbTotalBytes;
18
_ibuflen = pECB->cbAvailable > nMinBufSize ? pECB->cbAvailable : nMinBufSize;
19
_ibuf = new char[_ibuflen + 1]; // we allocate it one byte more, adding a trailing '\0', then it is easier with strings
20
memset(_ibuf, 0, _ibuflen + 1);
21
memcpy(_ibuf, pECB->lpbData, pECB->cbAvailable);
22
_cbRead = pECB->cbAvailable;
23
setg(_ibuf, _ibuf, _ibuf + _cbRead);
25
isapistreambuf::~isapistreambuf() {
28
int isapistreambuf::sync() {
31
DWORD dwBytesWritten = pptr() - pbase();
33
bWrite = _pECB->WriteClient(_pECB->ConnID, (PVOID)_obuf, &dwBytesWritten, 0);
34
setp(_obuf, _obuf + sizeof _obuf);
37
return bWrite ? 0 : -1;
39
int isapistreambuf::overflow(int ch) {
40
if (char_traits<char>::eof() == ch) {
41
return streambuf::overflow(ch);
43
if (pptr() < epptr()) {
47
if (0 == ret && char_traits<char>::eof() != ch) {
52
int isapistreambuf::underflow() {
53
int retval = char_traits<char>::eof();
54
if (gptr() < egptr()) {
58
if (_cbRead < _cbTotalBytes) {
59
memset(_ibuf, 0, _ibuflen + 1);
60
DWORD dwLen = _ibuflen;
61
BOOL bRead = (*_pECB->ReadClient)(_pECB->ConnID, _ibuf, &dwLen);
62
if (bRead && dwLen > 0) {
64
setg(_ibuf, _ibuf, _ibuf + dwLen);
72
isapistream::~isapistream() {
74
EXTENSION_CONTROL_BLOCK *isapistreambuf::ECB() {
77
EXTENSION_CONTROL_BLOCK *isapistream::ECB() {