LCOV - code coverage report
Current view: top level - co - socketConnection.h (source / functions) Hit Total Coverage
Test: Collage Lines: 1 1 100.0 %
Date: 2016-12-14 01:26:48 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). */
      41             :     class SocketConnection
      42             : #ifdef WIN32
      43             :         : public Connection
      44             : #else
      45             :         : public FDConnection
      46             : #endif
      47             :     {
      48             :     public:
      49             :         /** Create a new TCP-based connection */
      50             :         SocketConnection();
      51             :         bool connect() override;
      52             :         bool listen() override;
      53             :         void acceptNB() override;
      54             :         ConnectionPtr acceptSync() override;
      55         144 :         void close() override { _close(); }
      56             : 
      57             : 
      58             : #ifdef WIN32
      59             :         /** @sa Connection::getNotifier */
      60             :         Notifier getNotifier() const override
      61             :             { return _overlappedRead.hEvent; }
      62             : #endif
      63             : 
      64             :     protected:
      65             :         virtual ~SocketConnection();
      66             : 
      67             : #ifdef WIN32
      68             :         void readNB( void* buffer, const uint64_t bytes ) override;
      69             :         int64_t readSync( void* buffer, const uint64_t bytes,
      70             :                                   const bool block ) override;
      71             :         int64_t write( const void* buffer,
      72             :                                const uint64_t bytes ) override;
      73             : 
      74             :         typedef UINT_PTR Socket;
      75             : #else
      76             :         //! @cond IGNORE
      77             :         typedef int    Socket;
      78             :         enum
      79             :         {
      80             :             INVALID_SOCKET = -1
      81             :         };
      82             :         //! @endcond
      83             : #endif
      84             : 
      85             :     private:
      86             :         void _initAIOAccept();
      87             :         void _exitAIOAccept();
      88             :         void _initAIORead();
      89             :         void _exitAIORead();
      90             : 
      91             :         bool _createSocket();
      92             :         void _tuneSocket( const Socket fd );
      93             :         uint16_t _getPort() const;
      94             : 
      95             : #ifdef WIN32
      96             :         union
      97             :         {
      98             :             Socket _readFD;
      99             :             Socket _writeFD;
     100             :         };
     101             : 
     102             :         // overlapped data structures
     103             :         OVERLAPPED _overlappedRead;
     104             :         OVERLAPPED _overlappedWrite;
     105             :         void*      _overlappedAcceptData;
     106             :         Socket     _overlappedSocket;
     107             :         DWORD      _overlappedDone;
     108             : 
     109             :         LB_TS_VAR( _recvThread );
     110             : #endif
     111             : 
     112             :         void _close();
     113             :     };
     114             : }
     115             : 
     116             : #endif //CO_SOCKETCONNECTION_H

Generated by: LCOV version 1.11