2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
22 * (c) Copyright 2007 by Intra2net AG
25 #include "async_pipe.hpp"
28 #include <boost/bind.hpp>
31 #include <sys/types.h>
32 #include <sys/socket.h>
41 * Implementation of SimplePipe
44 SimplePipe::SimplePipe()
46 m_signal_read.connect(boost::bind(&SimplePipe::slotReceived,this));
47 } // eo SimplePipe::SimplePipe()
50 SimplePipe::~SimplePipe()
52 } // eo SimplePipe::~SimplePipe()
57 * This method connects itself with a newly created peer object with a bidirectional pipe.
58 * @return the peer pipe object.
60 bool SimplePipe::makePipe(SimplePipe& peer)
62 close(); // just in case...
66 int res= ::socketpair( AF_UNIX, SOCK_STREAM, 0, fds);
78 peer.close(); // just in case
83 peer.setWriteFd(fds[1]);
84 peer.setReadFd(fds[1]);
87 } // eo SimplePipe.:makePipe()
91 * sends a string through the pipe.
92 * @param data the data which should be sent to the other side.
94 void SimplePipe::sendString(const std::string& data)
97 } // eo SimplePipe::sendString(const std::string&)
101 * emits the signal signalReceived with the received data.
102 * This slot is connected to IOImplementation::m_signal_read.
104 void SimplePipe::slotReceived()
107 data.swap(m_input_buffer);
108 signal_received_string(data);
109 } // eo SimplePipe::slotReceived()
112 } // eo namespace AsyncIo