From 65b029e8334d4dfc9a6161fc04740b03d56a8e2f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 5 Aug 2011 01:46:00 +0300 Subject: [PATCH] Update handle types Derive Socket from EventObject --- source/socket.cpp | 11 ++++++----- source/socket.h | 9 ++++----- source/types.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/socket.cpp b/source/socket.cpp index a4675f5..7ff7741 100644 --- a/source/socket.cpp +++ b/source/socket.cpp @@ -4,6 +4,7 @@ #include #endif #include +#include #include #include #include @@ -50,6 +51,8 @@ Socket::Socket(SocketHandle h, const SockAddr &paddr): #ifdef WIN32 event = CreateEvent(0, false, false, 0); +#else + *event = handle; #endif } @@ -62,6 +65,8 @@ Socket::Socket(Family af, int type, int proto): #ifdef WIN32 event = CreateEvent(0, false, false, 0); +#else + *event = handle; #endif } @@ -85,13 +90,9 @@ void Socket::set_block(bool b) #endif } -IO::Handle Socket::get_event_handle() +const IO::Handle &Socket::get_event_handle() { -#ifdef WIN32 return event; -#else - return handle; -#endif } diff --git a/source/socket.h b/source/socket.h index a2cbae1..5536146 100644 --- a/source/socket.h +++ b/source/socket.h @@ -1,7 +1,8 @@ #ifndef MSP_NET_SOCKET_H_ #define MSP_NET_SOCKET_H_ -#include +#include +#include #include "constants.h" #include "sockaddr.h" #include "types.h" @@ -9,13 +10,11 @@ namespace Msp { namespace Net { -class Socket: public IO::Base +class Socket: public IO::EventObject { protected: SocketHandle handle; -#ifdef WIN32 IO::Handle event; -#endif bool connected; SockAddr *local_addr; SockAddr *peer_addr; @@ -26,7 +25,7 @@ public: ~Socket(); void set_block(bool); - IO::Handle get_event_handle(); + const IO::Handle &get_event_handle(); bool is_connected() const { return connected; } diff --git a/source/types.h b/source/types.h index 3989fa9..3af68ab 100644 --- a/source/types.h +++ b/source/types.h @@ -10,9 +10,9 @@ typedef int socklen_t; #define MSP_NET_INVALID_SOCKET_HANDLE static_cast(-1) #else -typedef IO::Handle SocketHandle; +typedef int SocketHandle; -#define MSP_NET_INVALID_SOCKET_HANDLE MSP_IO_INVALID_HANDLE +#define MSP_NET_INVALID_SOCKET_HANDLE -1 #endif } // namespace Net -- 2.43.0