socketConnection.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef EQNET_SOCKETCONNECTION_H
00019 #define EQNET_SOCKETCONNECTION_H
00020
00021 #include <eq/base/base.h>
00022 #include <eq/base/buffer.h>
00023
00024 #ifdef WIN32
00025 # include <eq/net/connection.h>
00026 #else
00027 # include "fdConnection.h"
00028 # include <netinet/in.h>
00029 #endif
00030
00031
00032 namespace eq
00033 {
00034 namespace net
00035 {
00037 class SocketConnection
00038 #ifdef WIN32
00039 : public Connection
00040 #else
00041 : public FDConnection
00042 #endif
00043 {
00044 public:
00051 SocketConnection( const ConnectionType type = CONNECTIONTYPE_TCPIP );
00052
00053 virtual bool connect();
00054 virtual bool listen();
00055 virtual void acceptNB();
00056 virtual ConnectionPtr acceptSync();
00057 virtual void close();
00058
00059
00060 #ifdef WIN32
00061
00062 virtual Notifier getNotifier() const { return _overlapped.hEvent; }
00063 #endif
00064
00065 protected:
00066 virtual ~SocketConnection();
00067
00068 #ifdef WIN32
00069 virtual void readNB( void* buffer, const uint64_t bytes );
00070 virtual int64_t readSync( void* buffer, const uint64_t bytes );
00071 virtual int64_t write( const void* buffer, const uint64_t bytes );
00072
00073 typedef SOCKET Socket;
00074 #else
00076 typedef int Socket;
00077 enum
00078 {
00079 INVALID_SOCKET = -1
00080 };
00082 #endif
00083
00084 private:
00085 void _initAIOAccept();
00086 void _exitAIOAccept();
00087 void _initAIORead();
00088 void _exitAIORead();
00089
00090 bool _createSocket();
00091 void _tuneSocket( const Socket fd );
00092 bool _parseAddress( sockaddr_in& socketAddress );
00093 uint16_t _getPort() const;
00094
00095 #ifdef WIN32
00096 union
00097 {
00098 SOCKET _readFD;
00099 SOCKET _writeFD;
00100 };
00101
00102
00103 OVERLAPPED _overlapped;
00104 void* _overlappedAcceptData;
00105 SOCKET _overlappedSocket;
00106
00107 CHECK_THREAD_DECLARE( _recvThread );
00108 #endif
00109 };
00110 }
00111 }
00112
00113 #endif //EQNET_SOCKETCONNECTION_H