From: Christian P. <cp...@us...> - 2005-01-03 13:50:58
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19210/src/System Modified Files: File.posix.cpp Pipe.posix.cpp ProcessIO.cpp Log Message: Added IOFilter support to IODevice. Updated classes that inherit from IODevice. Fixed some minor bugs in ProcessIO class. Index: File.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/File.posix.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- File.posix.cpp 1 Jan 2005 19:00:08 -0000 1.10 +++ File.posix.cpp 3 Jan 2005 13:50:45 -0000 1.11 @@ -85,11 +85,14 @@ File::File(const File& f) throw(IO::IOError) : IODevice(f), _handle((unsigned long)-1) { - int handle = ::dup((int)f._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate file handle", P_SOURCEINFO); - - _handle = (unsigned long)handle; + if(f.valid()) + { + int handle = ::dup((int)f._handle); + if(handle == -1) + throw IO::IOError(errno, "Could not duplicate file handle", P_SOURCEINFO); + + _handle = (unsigned long)handle; + } } File::File(const Unicode::String& name, AccessMode amode, OpenMode omode, @@ -125,20 +128,17 @@ IODevice::setEof(false); } -void File::close() throw(IO::IOError) +void File::_close() throw(IO::IOError) { - if(valid()) - { - if(::close((int)_handle) == -1) - throw IO::IOError(errno, "Could not close file", P_SOURCEINFO); - - _handle = (unsigned long)-1; - IODevice::setAccess(None); - IODevice::setValid(false); - } + if(::close((int)_handle) == -1) + throw IO::IOError(errno, "Could not close file", P_SOURCEINFO); + + _handle = (unsigned long)-1; + IODevice::setAccess(None); + IODevice::setValid(false); } -size_t File::read(char* buffer, size_t count) throw(IO::IOError) +size_t File::_read(char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; @@ -158,7 +158,7 @@ return ret; } -size_t File::peek(char* buffer, size_t count) throw(IO::IOError) +size_t File::_peek(char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; @@ -177,7 +177,7 @@ return ret; } -size_t File::write(const char* buffer, size_t count) throw(IO::IOError) +size_t File::_write(const char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; @@ -195,7 +195,7 @@ return ret; } -offset_t File::seek(offset_t offset, SeekMode mode) throw(IO::IOError) +offset_t File::_seek(offset_t offset, SeekMode mode) throw(IO::IOError) { int whence; switch(mode) @@ -220,7 +220,7 @@ return ret; } -bool File::isSeekable() const throw() +bool File::_isSeekable() const throw() { struct stat buff; int ret = fstat((int)_handle, &buff); @@ -233,14 +233,14 @@ return false; } -void File::sync() const throw(IO::IOError) +void File::_sync() const throw(IO::IOError) { int ret = fsync((int)_handle); if(ret == -1) throw IO::IOError(errno, "Could not sync file to disk", P_SOURCEINFO); } -offset_t File::size() const throw(IO::IOError) +offset_t File::_size() const throw(IO::IOError) { struct stat buff; int ret = fstat((int)_handle, &buff); @@ -252,6 +252,8 @@ void File::resize(size_t sz) throw(IO::IOError) { + sync(); + int ret = ftruncate((int)_handle, sz); if(ret == -1) throw IO::IOError(errno, "Could not truncate file", P_SOURCEINFO); @@ -259,25 +261,37 @@ File& File::operator=(const File& f) throw(IO::IOError) { - int handle = ::dup((int)f._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate file handle", P_SOURCEINFO); - - if(valid()) + if(f.valid()) { - try - { - close(); - } - catch(...) + int handle = ::dup((int)f._handle); + if(handle == -1) + throw IO::IOError(errno, "Could not duplicate file handle", P_SOURCEINFO); + + if(valid()) { - ::close(handle); - throw; + try + { + close(); + } + catch(...) + { + ::close(handle); + throw; + } } + + IODevice::operator=(f); + _handle = (unsigned long)handle; } + else + { + if(valid()) + close(); - IODevice::operator=(f); - _handle = (unsigned long)handle; + setValid(false); + setEof(true); + setAccess(None); + } return *this; } Index: ProcessIO.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/ProcessIO.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ProcessIO.cpp 31 Dec 2004 03:22:57 -0000 1.1 +++ ProcessIO.cpp 3 Jan 2005 13:50:45 -0000 1.2 @@ -28,14 +28,19 @@ throw(IO::IOError) : _in(in), _out(out), _err(err) { + setValid(true); + setAccess(ReadWrite); + setEof(false); } ProcessIO::~ProcessIO() throw() { } -void ProcessIO::close() throw(IO::IOError) +void ProcessIO::_close() throw(IO::IOError) { + setValid(false); + _in.close(); _out.close(); _err.close(); @@ -59,12 +64,12 @@ _err.close(); } -size_t ProcessIO::write(const char* buffer, size_t count) throw(IO::IOError) +size_t ProcessIO::_write(const char* buffer, size_t count) throw(IO::IOError) { return _in.write(buffer,count); } -size_t ProcessIO::read(char* buffer, size_t count) throw(IO::IOError) +size_t ProcessIO::_read(char* buffer, size_t count) throw(IO::IOError) { return _out.read(buffer,count); } Index: Pipe.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/Pipe.posix.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Pipe.posix.cpp 1 Jan 2005 19:00:08 -0000 1.7 +++ Pipe.posix.cpp 3 Jan 2005 13:50:45 -0000 1.8 @@ -31,7 +31,7 @@ namespace System { Pipe::Pipe(unsigned long h, bool readEnd) throw() -: _handle(h) +: IODevice(), _handle(h) { IODevice::setAccess(readEnd ? Read : Write); IODevice::setValid(true); @@ -41,11 +41,14 @@ Pipe::Pipe(const Pipe& p) throw(IO::IOError) : IODevice(p), _handle((unsigned long)-1) { - int handle = ::dup((int)p._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate pipe handle", P_SOURCEINFO); - - _handle = (unsigned long)handle; + if(p.valid()) + { + int handle = ::dup((int)p._handle); + if(handle == -1) + throw IO::IOError(errno, "Could not duplicate pipe handle", P_SOURCEINFO); + + _handle = (unsigned long)handle; + } } Pipe::~Pipe() throw() @@ -69,20 +72,17 @@ return std::make_pair(readPipe, writePipe); } -void Pipe::close() throw(IO::IOError) +void Pipe::_close() throw(IO::IOError) { - if(valid()) - { - if(::close((int)_handle) == -1) - throw IO::IOError(errno, "Could not close pipe", P_SOURCEINFO); - - _handle = (unsigned long)-1; - IODevice::setAccess(None); - IODevice::setValid(false); - } + if(::close((int)_handle) == -1) + throw IO::IOError(errno, "Could not close pipe", P_SOURCEINFO); + + _handle = (unsigned long)-1; + IODevice::setAccess(None); + IODevice::setValid(false); } -size_t Pipe::read(char* buffer, size_t count) throw(IO::IOError) +size_t Pipe::_read(char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; @@ -102,7 +102,7 @@ return ret; } -size_t Pipe::write(const char* buffer, size_t count) throw(IO::IOError) +size_t Pipe::_write(const char* buffer, size_t count) throw(IO::IOError) { if(count > SSIZE_MAX) count = SSIZE_MAX; @@ -122,34 +122,47 @@ return ret; } -void Pipe::sync() const throw(IO::IOError) +void Pipe::_sync() const throw(IO::IOError) { + /* pipes cant be synced !! int ret = fsync((int)_handle); if(ret == -1) - throw IO::IOError(errno, "Could not commit to pipe", P_SOURCEINFO); + throw IO::IOError(errno, "Could not commit to pipe", P_SOURCEINFO); */ } Pipe& Pipe::operator=(const Pipe& p) throw(IO::IOError) { - int handle = ::dup((int)p._handle); - if(handle == -1) - throw IO::IOError(errno, "Could not duplicate pipe handle", P_SOURCEINFO); - - if(valid()) + if(p.valid()) { - try - { - close(); - } - catch(...) + int handle = ::dup((int)p._handle); + if(handle == -1) + throw IO::IOError(errno, "Could not duplicate pipe handle", P_SOURCEINFO); + + if(valid()) { - ::close(handle); - throw; + try + { + close(); + } + catch(...) + { + ::close(handle); + throw; + } } + + IODevice::operator=(p); + _handle = (unsigned long)handle; } + else + { + if(valid()) + close(); - IODevice::operator=(p); - _handle = (unsigned long)handle; + setValid(false); + setEof(true); + setAccess(None); + } return *this; } |