LCOV - code coverage report
Current view: top level - co - socketConnection.h (source / functions) Hit Total Coverage
Test: Collage Lines: 1 1 100.0 %
Date: 2015-11-03 13:48:53 Functions: 1 1 100.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This file is part of Collage <https://github.com/Eyescale/Collage>
       5             :  *
       6             :  * This library is free software; you can redistribute it and/or modify it under
       7             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       8             :  * by the Free Software Foundation.
       9             :  *
      10             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      11             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      12             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      13             :  * details.
      14             :  *
      15             :  * You should have received a copy of the GNU Lesser General Public License
      16             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      17             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      18             :  */
      19             : 
      20             : #ifndef CO_SOCKETCONNECTION_H
      21             : #define CO_SOCKETCONNECTION_H
      22             : 
      23             : #include <co/connectionType.h> // enum
      24             : #include <lunchbox/api.h>
      25             : #include <lunchbox/buffer.h> // member
      26             : #include <lunchbox/os.h>
      27             : #include <lunchbox/thread.h> // for LB_TS_VAR
      28             : 
      29             : 
      30             : #ifdef WIN32
      31             : #  include <co/connection.h>
      32             : #else
      33             : #  include "fdConnection.h"
      34             : #  include <netinet/in.h>
      35             : #endif
      36             : 
      37             : 
      38             : namespace co
      39             : {
      40             :     /** A socket connection (TCPIP or SDP). */
      41             :     class SocketConnection
      42             : #ifdef WIN32
      43             :         : public Connection
      44             : #else
      45             :         : public FDConnection
      46             : #endif
      47             :     {
      48             :     public:
      49             :         /**
      50             :          * Create a new socket-based connection
      51             :          *
      52             :          * @param type the connection type, can be CONNECTIONTYPE_TCPIP or
      53             :          *             CONNECTIONTYPE_SDP.
      54             :          */
      55             :         explicit SocketConnection( const ConnectionType type =
      56             :                                    CONNECTIONTYPE_TCPIP );
      57             :         bool connect() override;
      58             :         bool listen() override;
      59             :         void acceptNB() override;
      60             :         ConnectionPtr acceptSync() override;
      61         139 :         void close() override { _close(); }
      62             : 
      63             : 
      64             : #ifdef WIN32
      65             :         /** @sa Connection::getNotifier */
      66             :         Notifier getNotifier() const override
      67             :             { return _overlappedRead.hEvent; }
      68             : #endif
      69             : 
      70             :     protected:
      71             :         virtual ~SocketConnection();
      72             : 
      73             : #ifdef WIN32
      74             :         void readNB( void* buffer, const uint64_t bytes ) override;
      75             :         int64_t readSync( void* buffer, const uint64_t bytes,
      76             :                                   const bool block ) override;
      77             :         int64_t write( const void* buffer,
      78             :                                const uint64_t bytes ) override;
      79             : 
      80             :         typedef UINT_PTR Socket;
      81             : #else
      82             :         //! @cond IGNORE
      83             :         typedef int    Socket;
      84             :         enum
      85             :         {
      86             :             INVALID_SOCKET = -1
      87             :         };
      88             :         //! @endcond
      89             : #endif
      90             : 
      91             :     private:
      92             :         void _initAIOAccept();
      93             :         void _exitAIOAccept();
      94             :         void _initAIORead();
      95             :         void _exitAIORead();
      96             : 
      97             :         bool _createSocket();
      98             :         void _tuneSocket( const Socket fd );
      99             :         uint16_t _getPort() const;
     100             : 
     101             : #ifdef WIN32
     102             :         union
     103             :         {
     104             :             Socket _readFD;
     105             :             Socket _writeFD;
     106             :         };
     107             : 
     108             :         // overlapped data structures
     109             :         OVERLAPPED _overlappedRead;
     110             :         OVERLAPPED _overlappedWrite;
     111             :         void*      _overlappedAcceptData;
     112             :         Socket     _overlappedSocket;
     113             :         DWORD      _overlappedDone;
     114             : 
     115             :         LB_TS_VAR( _recvThread );
     116             : #endif
     117             : 
     118             :         void _close();
     119             :     };
     120             : }
     121             : 
     122             : #endif //CO_SOCKETCONNECTION_H

Generated by: LCOV version 1.11