summaryrefslogtreecommitdiff
path: root/src/pipe.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pipe.cpp')
-rw-r--r--src/pipe.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/pipe.cpp b/src/pipe.cpp
index 6045e0b..328670a 100644
--- a/src/pipe.cpp
+++ b/src/pipe.cpp
@@ -25,27 +25,52 @@
#include <config.h>
#endif
+/* Project */
#include <dbus-c++/pipe.h>
+#include <dbus-c++/util.h>
+#include <dbus-c++/error.h>
+/* STD */
#include <unistd.h>
+#include <sys/poll.h>
+#include <fcntl.h>
+#include <errno.h>
using namespace DBus;
using namespace std;
-Pipe::Pipe () :
- _handler (NULL),
- fd_write (0),
- fd_read (0),
- data (NULL)
+Pipe::Pipe(void(*handler)(const void *data, void *buffer, unsigned int nbyte), const void *data) :
+ _handler(handler),
+ _fd_write (0),
+ _fd_read (0),
+ _data(data)
{
+ int fd[2];
+
+ if(pipe(fd) == 0)
+ {
+ _fd_read = fd[0];
+ _fd_write = fd[1];
+ fcntl(_fd_read, F_SETFL, O_NONBLOCK);
+ fcntl(_fd_write, F_SETFL, O_NONBLOCK);
+ }
+ else
+ {
+ throw Error("PipeError:errno", toString(errno).c_str());
+ }
}
void Pipe::write(const void *buffer, unsigned int nbytes)
{
- ::write(fd_write, buffer, nbytes);
+ ::write(_fd_write, buffer, nbytes);
+}
+
+ssize_t Pipe::read(void *buffer, unsigned int nbytes)
+{
+ return ::read(_fd_read, buffer, nbytes);
}
void Pipe::signal()
{
- ::write(fd_write, '\0', 1);
+ ::write(_fd_write, '\0', 1);
}