From: Christian P. <cp...@us...> - 2005-01-24 23:01:27
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4612/src/Net Modified Files: Socket.cpp Log Message: Added Socket::listen(), Socket::accept(). Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Socket.cpp 7 Jan 2005 13:39:02 -0000 1.5 +++ Socket.cpp 24 Jan 2005 23:00:39 -0000 1.6 @@ -197,7 +197,7 @@ } void Socket::open(Domain domain, Type type, int proto) - throw(LogicError, IO::IOError) + throw(IO::IOError) { if(valid()) close(); @@ -244,6 +244,22 @@ _proto = proto; } +void Socket::open(int handle, Domain domain, Type type, int proto) + throw(IO::IOError) +{ + if(valid()) + close(); + + IODevice::setAccess(ReadWrite); + IODevice::setValid(true); + IODevice::setEof(false); + + _handle = handle; + _domain = domain; + _type = type; + _proto = proto; +} + void Socket::_close() throw(IO::IOError) { int ret = ::close(_handle); @@ -353,6 +369,24 @@ throw IO::IOError(errno, "Could not connect socket", P_SOURCEINFO); } +void Socket::listen() throw(IO::IOError) +{ + int ret = ::listen(_handle, 128); + if(ret == -1) + throw IO::IOError(errno, "Could not listen on socket", P_SOURCEINFO); +} + +Socket Socket::accept() throw(IO::IOError) +{ + int ret = ::accept(_handle, 0, 0); + if(ret == -1) + throw IO::IOError(errno, "Could not accept connection on socket", P_SOURCEINFO); + + Socket s; + s.open(ret, _domain, _type, _proto); + return s; +} + void Socket::setSendTimeout(unsigned int timeout) throw(IO::IOError) { SocketOption<SOL_SOCKET, SO_SNDTIMEO, int> opt(_handle); |