Line data Source code
1 :
2 : /* Copyright (c) 2005-2014, 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_PIPE_CONNECTION_H
21 : #define CO_PIPE_CONNECTION_H
22 :
23 : #ifdef _WIN32
24 : # include <co/namedPipeConnection.h>
25 : #else
26 : # include "fdConnection.h"
27 : #endif
28 :
29 : #include <lunchbox/monitor.h>
30 : #include <lunchbox/thread.h>
31 :
32 : namespace co
33 : {
34 : class NamedPipeConnection;
35 : class PipeConnection;
36 : typedef lunchbox::RefPtr< PipeConnection > PipeConnectionPtr;
37 : typedef lunchbox::RefPtr< const PipeConnection > ConstPipeConnectionPtr;
38 :
39 : /**
40 : * An inter-thread, bi-directional connection using anonymous pipes.
41 : *
42 : * The pipe connection is implemented using anonymous pipes, and can
43 : * therefore only be used between related threads. It consist of a pair of
44 : * siblings representing the two endpoints.
45 : */
46 : class PipeConnection
47 : #ifdef _WIN32
48 : : public Connection
49 : #else
50 : : public FDConnection
51 : #endif
52 : {
53 : public:
54 : /** Construct a new pipe connection. */
55 : CO_API PipeConnection();
56 : /** Destruct this pipe connection. */
57 : CO_API virtual ~PipeConnection();
58 :
59 : bool connect() override;
60 109 : void close() override { _close(); }
61 :
62 : #ifdef _WIN32
63 : Notifier getNotifier() const override;
64 : #endif
65 :
66 0 : void acceptNB() override { /* nop */ }
67 :
68 : /** @return the sibling of this pipe connection. */
69 : ConnectionPtr acceptSync() override;
70 :
71 : /** @return the sibling connection. */
72 91 : PipeConnectionPtr getSibling() { return _sibling; }
73 :
74 : protected:
75 : #ifdef _WIN32
76 : void readNB( void* buffer, const uint64_t bytes ) override;
77 : int64_t readSync( void* buffer, const uint64_t bytes,
78 : const bool ignored ) override;
79 : int64_t write( const void* buffer,
80 : const uint64_t bytes ) override;
81 : #endif
82 :
83 : private:
84 : PipeConnectionPtr _sibling;
85 : lunchbox::Monitorb _connected;
86 :
87 : #ifdef _WIN32
88 : NamedPipeConnectionPtr _namedPipe;
89 :
90 : LB_TS_VAR( _recvThread );
91 : #endif
92 :
93 : bool _createPipes();
94 : void _close();
95 : };
96 : }
97 :
98 : #endif //CO_PIPE_CONNECTION_H
|