socketConnection.h

00001 
00002 /* Copyright (c) 2005-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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> // member
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         // overlapped data structures
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
Generated on Mon Aug 10 18:58:41 2009 for Equalizer 0.9 by  doxygen 1.5.8