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

Generated by: LCOV version 1.11