From: Christian P. <cp...@us...> - 2005-01-03 13:50:59
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19210/src/Net Modified Files: Socket.cpp Log Message: Added IOFilter support to IODevice. Updated classes that inherit from IODevice. Fixed some minor bugs in ProcessIO class. Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Socket.cpp 23 Dec 2004 06:23:46 -0000 1.3 +++ Socket.cpp 3 Jan 2005 13:50:45 -0000 1.4 @@ -199,72 +199,62 @@ void Socket::open(Domain domain, Type type, int proto) throw(LogicError, IO::IOError) { - if(!valid()) - { - int d; - switch(domain) - { - case Inet: - d = AF_INET; - break; - case Inet6: - d = AF_INET6; - break; - case IPX: - d = AF_IPX; - break; - case AppleTalk: - d = AF_APPLETALK; - break; - } + if(valid()) + close(); - int t; - switch(type) - { - case Stream: - t = SOCK_STREAM; - break; - case Datagram: - t = SOCK_DGRAM; - break; - } + int d; + switch(domain) + { + case Inet: + d = AF_INET; + break; + case Inet6: + d = AF_INET6; + break; + case IPX: + d = AF_IPX; + break; + case AppleTalk: + d = AF_APPLETALK; + break; + } - int ret = ::socket(d, t, proto); - if(ret == -1) - throw IO::IOError(errno, "Could not open socket", P_SOURCEINFO); + int t; + switch(type) + { + case Stream: + t = SOCK_STREAM; + break; + case Datagram: + t = SOCK_DGRAM; + break; + } - IODevice::setAccess(ReadWrite); - IODevice::setValid(true); - IODevice::setEof(false); + int ret = ::socket(d, t, proto); + if(ret == -1) + throw IO::IOError(errno, "Could not open socket", P_SOURCEINFO); - _handle = ret; - _domain = domain; - _type = type; - _proto = proto; + IODevice::setAccess(ReadWrite); + IODevice::setValid(true); + IODevice::setEof(false); - return; - } - - throw LogicError("Socket is already open", P_SOURCEINFO); + _handle = ret; + _domain = domain; + _type = type; + _proto = proto; } -void Socket::close() throw(LogicError, IO::IOError) +void Socket::_close() throw(IO::IOError) { - if(valid()) - { - int ret = ::close(_handle); - if(ret == -1) - throw IO::IOError(errno, "Could not close socket", P_SOURCEINFO); - - IODevice::setAccess(None); - IODevice::setValid(false); - return; - } + int ret = ::close(_handle); + if(ret == -1) + throw IO::IOError(errno, "Could not close socket", P_SOURCEINFO); - throw LogicError("Socket is not open", P_SOURCEINFO); + IODevice::setAccess(None); + IODevice::setValid(false); } -size_t Socket::read(char* buffer, size_t count) throw(IO::IOError) +size_t Socket::_read(char* buffer, size_t count) throw(IO::IOError) { ssize_t ret = ::recv(_handle, (void*)buffer, count, MSG_NOSIGNAL); if(ret == -1) @@ -277,7 +267,7 @@ return ret; } -size_t Socket::peek(char* buffer, size_t count) throw(IO::IOError) +size_t Socket::_peek(char* buffer, size_t count) throw(IO::IOError) { ssize_t ret = ::recv(_handle, (void*)buffer, count, MSG_PEEK|MSG_NOSIGNAL); @@ -287,7 +277,7 @@ return ret; } -size_t Socket::write(const char* buffer, size_t count) throw(IO::IOError) +size_t Socket::_write(const char* buffer, size_t count) throw(IO::IOError) { ssize_t ret = ::send(_handle, (const void*)buffer, count, MSG_NOSIGNAL); |