Line data Source code
1 :
2 : /* Copyright (c) 2007-2012, 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 : #include "bufferConnection.h"
21 :
22 : #include <lunchbox/buffer.h>
23 : #include <string.h>
24 :
25 : namespace co
26 : {
27 : namespace detail
28 : {
29 0 : class BufferConnection
30 : {
31 : public:
32 : lunchbox::Bufferb buffer;
33 : };
34 : }
35 :
36 0 : BufferConnection::BufferConnection()
37 0 : : _impl(new detail::BufferConnection)
38 : {
39 0 : _setState(STATE_CONNECTED);
40 0 : LBVERB << "New BufferConnection @" << (void*)this << std::endl;
41 0 : }
42 :
43 0 : BufferConnection::~BufferConnection()
44 : {
45 0 : _setState(STATE_CLOSED);
46 0 : if (!_impl->buffer.isEmpty())
47 0 : LBWARN << "Deleting BufferConnection with buffered data" << std::endl;
48 0 : delete _impl;
49 0 : }
50 :
51 0 : const lunchbox::Bufferb& BufferConnection::getBuffer() const
52 : {
53 0 : return _impl->buffer;
54 : }
55 :
56 0 : lunchbox::Bufferb& BufferConnection::getBuffer()
57 : {
58 0 : return _impl->buffer;
59 : }
60 :
61 0 : uint64_t BufferConnection::getSize() const
62 : {
63 0 : return _impl->buffer.getSize();
64 : }
65 :
66 0 : int64_t BufferConnection::write(const void* buffer, const uint64_t bytes)
67 : {
68 0 : _impl->buffer.append(reinterpret_cast<const uint8_t*>(buffer), bytes);
69 0 : return bytes;
70 : }
71 :
72 0 : void BufferConnection::sendBuffer(ConnectionPtr connection)
73 : {
74 0 : if (_impl->buffer.isEmpty())
75 0 : return;
76 :
77 0 : if (!connection)
78 : {
79 0 : LBWARN << "NULL connection during buffer write" << std::endl;
80 0 : return;
81 : }
82 :
83 0 : LBCHECK(connection->send(_impl->buffer.getData(), _impl->buffer.getSize()));
84 0 : _impl->buffer.setSize(0);
85 : }
86 63 : }
|