diff options
author | Andrew Stitcher <astitcher@apache.org> | 2009-10-21 21:53:53 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2009-10-21 21:53:53 +0000 |
commit | bd3c7f363d0a623ad1118fb337a38dee9a7d3b85 (patch) | |
tree | 4498dbfed67bb9d774735465df22ac3e92c797b3 /cpp | |
parent | 6ffba51e70414f0dfe3d641e7fe82622911f154a (diff) | |
download | qpid-python-bd3c7f363d0a623ad1118fb337a38dee9a7d3b85.tar.gz |
Tidied up dependencies in IOHandle so that it is no longer
dependent on the windows implementation classes.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@828230 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/qpid/sys/IOHandle.h | 16 | ||||
-rw-r--r-- | cpp/src/qpid/sys/windows/AsynchIO.cpp | 45 | ||||
-rwxr-xr-x | cpp/src/qpid/sys/windows/AsynchIoResult.h | 2 | ||||
-rwxr-xr-x | cpp/src/qpid/sys/windows/IoHandlePrivate.h | 5 | ||||
-rwxr-xr-x | cpp/src/qpid/sys/windows/IocpPoller.cpp | 2 | ||||
-rwxr-xr-x | cpp/src/qpid/sys/windows/Socket.cpp | 10 | ||||
-rw-r--r-- | cpp/src/tests/SocketProxy.h | 4 |
7 files changed, 41 insertions, 43 deletions
diff --git a/cpp/include/qpid/sys/IOHandle.h b/cpp/include/qpid/sys/IOHandle.h index 68e9d92a04..45fc8c240a 100644 --- a/cpp/include/qpid/sys/IOHandle.h +++ b/cpp/include/qpid/sys/IOHandle.h @@ -31,25 +31,11 @@ namespace sys { * This is a class intended to abstract the Unix concept of file descriptor * or the Windows concept of HANDLE */ -// Windows-related classes -class AsynchAcceptorPrivate; -class AsynchAcceptResult; -namespace windows { - class AsynchAcceptor; - class AsynchAcceptResult; - class AsynchIO; -} - -// General classes class PollerHandle; class IOHandlePrivate; class IOHandle { - - friend class windows::AsynchAcceptResult; - friend class windows::AsynchAcceptor; - friend class windows::AsynchIO; - friend class PollerHandle; + friend class IOHandlePrivate; protected: IOHandlePrivate* const impl; diff --git a/cpp/src/qpid/sys/windows/AsynchIO.cpp b/cpp/src/qpid/sys/windows/AsynchIO.cpp index c4f67ddf70..7241398c9e 100644 --- a/cpp/src/qpid/sys/windows/AsynchIO.cpp +++ b/cpp/src/qpid/sys/windows/AsynchIO.cpp @@ -79,16 +79,7 @@ namespace windows { /* * Asynch Acceptor * - * TODO FIX this comment - is it still true? - * This implementation uses knowledge that the DispatchHandle handle member - * is derived from PollerHandle, which has a reference to the Socket. - * No dispatching features of DispatchHandle are used - we just use the - * conduit to the Socket. - * - * AsynchAcceptor uses an AsynchAcceptResult object to track completion - * and status of each accept operation outstanding. */ - class AsynchAcceptor : public qpid::sys::AsynchAcceptor { friend class AsynchAcceptResult; @@ -131,10 +122,10 @@ void AsynchAcceptor::restart(void) { DWORD bytesReceived = 0; // Not used, needed for AcceptEx API AsynchAcceptResult *result = new AsynchAcceptResult(acceptedCallback, this, - toFd(socket.impl)); + toSocketHandle(socket)); BOOL status; - status = ::fnAcceptEx(toFd(socket.impl), - toFd(result->newSocket->impl), + status = ::fnAcceptEx(toSocketHandle(socket), + toSocketHandle(*result->newSocket), result->addressBuffer, 0, AsynchAcceptResult::SOCKADDRMAXLEN, @@ -153,7 +144,7 @@ AsynchAcceptResult::AsynchAcceptResult(AsynchAcceptor::Callback cb, } void AsynchAcceptResult::success(size_t /*bytesTransferred*/) { - ::setsockopt (toFd(newSocket->impl), + ::setsockopt (toSocketHandle(*newSocket), SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, (char*)&listener, @@ -354,6 +345,15 @@ private: void completion(AsynchIoResult *result); }; +// This is used to encapsulate pure callbacks into a handle +class CallbackHandle : public IOHandle { +public: + CallbackHandle(AsynchIoResult::Completer completeCb, + AsynchIO::RequestCallback reqCb = 0) : + IOHandle(new IOHandlePrivate (INVALID_SOCKET, completeCb, reqCb)) + {} +}; + AsynchIO::AsynchIO(const Socket& s, ReadCallback rCb, EofCallback eofCb, @@ -447,11 +447,7 @@ void AsynchIO::notifyPendingWrite() { return; InterlockedIncrement(&opsInProgress); - IOHandlePrivate *hp = - new IOHandlePrivate (INVALID_SOCKET, - boost::bind(&AsynchIO::completion, this, _1)); - IOHandle h(hp); - PollerHandle ph(h); + PollerHandle ph(CallbackHandle(boost::bind(&AsynchIO::completion, this, _1))); poller->monitorHandle(ph, Poller::OUTPUT); } @@ -494,7 +490,7 @@ void AsynchIO::startReading() { readCount); DWORD bytesReceived = 0, flags = 0; InterlockedIncrement(&opsInProgress); - int status = WSARecv(toFd(socket.impl), + int status = WSARecv(toSocketHandle(socket), const_cast<LPWSABUF>(result->getWSABUF()), 1, &bytesReceived, &flags, @@ -534,12 +530,9 @@ void AsynchIO::requestCallback(RequestCallback callback) { return; InterlockedIncrement(&opsInProgress); - IOHandlePrivate *hp = - new IOHandlePrivate (INVALID_SOCKET, - boost::bind(&AsynchIO::completion, this, _1), - callback); - IOHandle h(hp); - PollerHandle ph(h); + PollerHandle ph(CallbackHandle( + boost::bind(&AsynchIO::completion, this, _1), + callback)); poller->monitorHandle(ph, Poller::INPUT); } @@ -596,7 +589,7 @@ void AsynchIO::startWrite(AsynchIO::BufferBase* buff) { buff, buff->dataCount); DWORD bytesSent = 0; - int status = WSASend(toFd(socket.impl), + int status = WSASend(toSocketHandle(socket), const_cast<LPWSABUF>(result->getWSABUF()), 1, &bytesSent, 0, diff --git a/cpp/src/qpid/sys/windows/AsynchIoResult.h b/cpp/src/qpid/sys/windows/AsynchIoResult.h index c9cdebce16..66c89efc11 100755 --- a/cpp/src/qpid/sys/windows/AsynchIoResult.h +++ b/cpp/src/qpid/sys/windows/AsynchIoResult.h @@ -74,6 +74,8 @@ protected: int status; }; +class AsynchAcceptor; + class AsynchAcceptResult : public AsynchResult { friend class AsynchAcceptor; diff --git a/cpp/src/qpid/sys/windows/IoHandlePrivate.h b/cpp/src/qpid/sys/windows/IoHandlePrivate.h index ffe539aab2..5943db5cc7 100755 --- a/cpp/src/qpid/sys/windows/IoHandlePrivate.h +++ b/cpp/src/qpid/sys/windows/IoHandlePrivate.h @@ -39,6 +39,9 @@ namespace sys { // can be a RequestCallback set - this carries the callback object through // from AsynchIO::requestCallback() through to the I/O completion processing. class IOHandlePrivate { + friend QPID_COMMON_EXTERN SOCKET toSocketHandle(const Socket& s); + static IOHandlePrivate* getImpl(const IOHandle& h); + public: IOHandlePrivate(SOCKET f = INVALID_SOCKET, windows::AsynchIoResult::Completer cb = 0, @@ -51,7 +54,7 @@ public: AsynchIO::RequestCallback cbRequest; }; -QPID_COMMON_EXTERN SOCKET toFd(const IOHandlePrivate* h); +QPID_COMMON_EXTERN SOCKET toSocketHandle(const Socket& s); }} diff --git a/cpp/src/qpid/sys/windows/IocpPoller.cpp b/cpp/src/qpid/sys/windows/IocpPoller.cpp index b18e41b3a7..4fcc9155f1 100755 --- a/cpp/src/qpid/sys/windows/IocpPoller.cpp +++ b/cpp/src/qpid/sys/windows/IocpPoller.cpp @@ -55,7 +55,7 @@ class PollerHandlePrivate { }; PollerHandle::PollerHandle(const IOHandle& h) : - impl(new PollerHandlePrivate(toFd(h.impl), h.impl->event, h.impl->cbRequest)) + impl(new PollerHandlePrivate(toSocketHandle(static_cast<const Socket&>(h)), h.impl->event, h.impl->cbRequest)) {} PollerHandle::~PollerHandle() { diff --git a/cpp/src/qpid/sys/windows/Socket.cpp b/cpp/src/qpid/sys/windows/Socket.cpp index e2ef195040..11fb8b4133 100755 --- a/cpp/src/qpid/sys/windows/Socket.cpp +++ b/cpp/src/qpid/sys/windows/Socket.cpp @@ -330,4 +330,14 @@ void Socket::setTcpNoDelay() const nodelay = true; } +inline IOHandlePrivate* IOHandlePrivate::getImpl(const qpid::sys::IOHandle &h) +{ + return h.impl; +} + +SOCKET toSocketHandle(const Socket& s) +{ + return IOHandlePrivate::getImpl(s)->fd; +} + }} // namespace qpid::sys diff --git a/cpp/src/tests/SocketProxy.h b/cpp/src/tests/SocketProxy.h index 9df32a1336..df243cb42a 100644 --- a/cpp/src/tests/SocketProxy.h +++ b/cpp/src/tests/SocketProxy.h @@ -47,7 +47,11 @@ class SocketProxy : private qpid::sys::Runnable // Need a Socket we can get the fd from class LowSocket : public qpid::sys::Socket { public: +#ifdef _WIN32 + FdType getFd() { return toSocketHandle(*this); } +#else FdType getFd() { return toFd(impl); } +#endif }; public: |