diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2010-12-06 22:57:29 +0100 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2010-12-06 22:57:29 +0100 |
commit | 8d6cafe06696e17afff03adf4b33bd504b55e277 (patch) | |
tree | f84d638376281ae1e7e0ef2d1f1ab909d3f9130a /src | |
parent | ec61751e17fe4ceb62cc16750b12df6056c5962a (diff) |
All devices conflated into a single implementation.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/device.cpp (renamed from src/queue.cpp) | 4 | ||||
-rw-r--r-- | src/device.hpp (renamed from src/queue.hpp) | 6 | ||||
-rw-r--r-- | src/forwarder.cpp | 60 | ||||
-rw-r--r-- | src/forwarder.hpp | 31 | ||||
-rw-r--r-- | src/streamer.cpp | 60 | ||||
-rw-r--r-- | src/streamer.hpp | 31 | ||||
-rw-r--r-- | src/zmq.cpp | 24 |
8 files changed, 16 insertions, 208 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index eea7d35..0b00f1c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -71,12 +71,12 @@ libzmq_la_SOURCES = \ connect_session.hpp \ ctx.hpp \ decoder.hpp \ + device.hpp \ devpoll.hpp \ encoder.hpp \ epoll.hpp \ err.hpp \ fd.hpp \ - forwarder.hpp \ fq.hpp \ i_inout.hpp \ io_object.hpp \ @@ -106,7 +106,6 @@ libzmq_la_SOURCES = \ pub.hpp \ pull.hpp \ push.hpp \ - queue.hpp \ rep.hpp \ req.hpp \ select.hpp \ @@ -114,7 +113,6 @@ libzmq_la_SOURCES = \ session.hpp \ socket_base.hpp \ stdint.hpp \ - streamer.hpp \ sub.hpp \ swap.hpp \ tcp_connecter.hpp \ @@ -141,11 +139,11 @@ libzmq_la_SOURCES = \ ctx.cpp \ connect_session.cpp \ decoder.cpp \ + device.cpp \ devpoll.cpp \ encoder.cpp \ epoll.cpp \ err.cpp \ - forwarder.cpp \ fq.cpp \ io_object.cpp \ io_thread.cpp \ @@ -167,13 +165,11 @@ libzmq_la_SOURCES = \ pull.cpp \ push.cpp \ pub.cpp \ - queue.cpp \ rep.cpp \ req.cpp \ select.cpp \ session.cpp \ socket_base.cpp \ - streamer.cpp \ sub.cpp \ swap.cpp \ tcp_connecter.cpp \ diff --git a/src/queue.cpp b/src/device.cpp index 7c731d8..e7c6090 100644 --- a/src/queue.cpp +++ b/src/device.cpp @@ -21,12 +21,12 @@ #include "../include/zmq.h" -#include "queue.hpp" +#include "device.hpp" #include "socket_base.hpp" #include "likely.hpp" #include "err.hpp" -int zmq::queue (class socket_base_t *insocket_, +int zmq::device (class socket_base_t *insocket_, class socket_base_t *outsocket_) { zmq_msg_t msg; diff --git a/src/queue.hpp b/src/device.hpp index 998b2e1..eab92c6 100644 --- a/src/queue.hpp +++ b/src/device.hpp @@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __ZMQ_QUEUE_HPP_INCLUDED__ -#define __ZMQ_QUEUE_HPP_INCLUDED__ +#ifndef __ZMQ_DEVICE_HPP_INCLUDED__ +#define __ZMQ_DEVICE_HPP_INCLUDED__ namespace zmq { - int queue (class socket_base_t *insocket_, + int device (class socket_base_t *insocket_, class socket_base_t *outsocket_); } diff --git a/src/forwarder.cpp b/src/forwarder.cpp deleted file mode 100644 index b00af1d..0000000 --- a/src/forwarder.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (c) 2007-2010 iMatix Corporation - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "../include/zmq.h" - -#include "forwarder.hpp" -#include "socket_base.hpp" -#include "likely.hpp" -#include "err.hpp" - -int zmq::forwarder (socket_base_t *insocket_, socket_base_t *outsocket_) -{ - zmq_msg_t msg; - int rc = zmq_msg_init (&msg); - errno_assert (rc == 0); - - int64_t more; - size_t more_sz = sizeof (more); - - while (true) { - rc = insocket_->recv (&msg, 0); - if (unlikely (rc < 0)) { - if (errno == ETERM) - return -1; - errno_assert (false); - } - - rc = insocket_->getsockopt (ZMQ_RCVMORE, &more, &more_sz); - if (unlikely (rc < 0)) { - if (errno == ETERM) - return -1; - errno_assert (false); - } - - rc = outsocket_->send (&msg, more ? ZMQ_SNDMORE : 0); - if (unlikely (rc < 0)) { - if (errno == ETERM) - return -1; - errno_assert (false); - } - } - - return 0; -} diff --git a/src/forwarder.hpp b/src/forwarder.hpp deleted file mode 100644 index 3ac69c2..0000000 --- a/src/forwarder.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright (c) 2007-2010 iMatix Corporation - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __ZMQ_FORWARDER_HPP_INCLUDED__ -#define __ZMQ_FORWARDER_HPP_INCLUDED__ - -namespace zmq -{ - - int forwarder (class socket_base_t *insocket_, - class socket_base_t *outsocket_); - -} - -#endif diff --git a/src/streamer.cpp b/src/streamer.cpp deleted file mode 100644 index 264fc6b..0000000 --- a/src/streamer.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (c) 2007-2010 iMatix Corporation - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "../include/zmq.h" - -#include "streamer.hpp" -#include "socket_base.hpp" -#include "likely.hpp" -#include "err.hpp" - -int zmq::streamer (socket_base_t *insocket_, socket_base_t *outsocket_) -{ - zmq_msg_t msg; - int rc = zmq_msg_init (&msg); - errno_assert (rc == 0); - - int64_t more; - size_t more_sz = sizeof (more); - - while (true) { - rc = insocket_->recv (&msg, 0); - if (unlikely (rc < 0)) { - if (errno == ETERM) - return -1; - errno_assert (false); - } - - rc = insocket_->getsockopt (ZMQ_RCVMORE, &more, &more_sz); - if (unlikely (rc < 0)) { - if (errno == ETERM) - return -1; - errno_assert (false); - } - - rc = outsocket_->send (&msg, more ? ZMQ_SNDMORE : 0); - if (unlikely (rc < 0)) { - if (errno == ETERM) - return -1; - errno_assert (false); - } - } - - return 0; -} diff --git a/src/streamer.hpp b/src/streamer.hpp deleted file mode 100644 index 681f01f..0000000 --- a/src/streamer.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - Copyright (c) 2007-2010 iMatix Corporation - - This file is part of 0MQ. - - 0MQ is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - 0MQ is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __ZMQ_STREAMER_HPP_INCLUDED__ -#define __ZMQ_STREAMER_HPP_INCLUDED__ - -namespace zmq -{ - - int streamer (class socket_base_t *insocket_, - class socket_base_t *outsocket_); - -} - -#endif diff --git a/src/zmq.cpp b/src/zmq.cpp index 6a1d396..c9fae28 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -39,9 +39,7 @@ #include <stdlib.h> #include <new> -#include "forwarder.hpp" -#include "queue.hpp" -#include "streamer.hpp" +#include "device.hpp" #include "socket_base.hpp" #include "msg_content.hpp" #include "stdint.hpp" @@ -685,19 +683,15 @@ int zmq_device (int device_, void *insocket_, void *outsocket_) errno = EFAULT; return -1; } - switch (device_) { - case ZMQ_FORWARDER: - return zmq::forwarder ((zmq::socket_base_t*) insocket_, - (zmq::socket_base_t*) outsocket_); - case ZMQ_QUEUE: - return zmq::queue ((zmq::socket_base_t*) insocket_, - (zmq::socket_base_t*) outsocket_); - case ZMQ_STREAMER: - return zmq::streamer ((zmq::socket_base_t*) insocket_, - (zmq::socket_base_t*) outsocket_); - default: - return EINVAL; + + if (device_ != ZMQ_FORWARDER && device_ != ZMQ_QUEUE && + device_ != ZMQ_STREAMER) { + errno = EINVAL; + return -1; } + + return zmq::device ((zmq::socket_base_t*) insocket_, + (zmq::socket_base_t*) outsocket_); } //////////////////////////////////////////////////////////////////////////////// |