From beffee92a8ec9e14cca21e5901970c4d03967c3d Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 26 Apr 2010 16:51:05 +0200 Subject: P2P renamed to PAIR --- src/Makefile.am | 4 +- src/app_thread.cpp | 6 +-- src/p2p.cpp | 139 ----------------------------------------------------- src/p2p.hpp | 63 ------------------------ src/pair.cpp | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pair.hpp | 63 ++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 207 deletions(-) delete mode 100644 src/p2p.cpp delete mode 100644 src/p2p.hpp create mode 100644 src/pair.cpp create mode 100644 src/pair.hpp (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 8277794..8cd94dd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -90,7 +90,7 @@ libzmq_la_SOURCES = app_thread.hpp \ platform.hpp \ poll.hpp \ poller.hpp \ - p2p.hpp \ + pair.hpp \ prefix_tree.hpp \ pub.hpp \ queue.hpp \ @@ -145,7 +145,7 @@ libzmq_la_SOURCES = app_thread.hpp \ pgm_receiver.cpp \ pgm_sender.cpp \ pgm_socket.cpp \ - p2p.cpp \ + pair.cpp \ prefix_tree.cpp \ pipe.cpp \ poll.cpp \ diff --git a/src/app_thread.cpp b/src/app_thread.cpp index 6141c06..9ff2112 100644 --- a/src/app_thread.cpp +++ b/src/app_thread.cpp @@ -41,7 +41,7 @@ #include "pipe.hpp" #include "config.hpp" #include "socket_base.hpp" -#include "p2p.hpp" +#include "pair.hpp" #include "pub.hpp" #include "sub.hpp" #include "req.hpp" @@ -152,8 +152,8 @@ zmq::socket_base_t *zmq::app_thread_t::create_socket (int type_) { socket_base_t *s = NULL; switch (type_) { - case ZMQ_P2P: - s = new (std::nothrow) p2p_t (this); + case ZMQ_PAIR: + s = new (std::nothrow) pair_t (this); break; case ZMQ_PUB: s = new (std::nothrow) pub_t (this); diff --git a/src/p2p.cpp b/src/p2p.cpp deleted file mode 100644 index 3f63d81..0000000 --- a/src/p2p.cpp +++ /dev/null @@ -1,139 +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 Lesser GNU 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 - Lesser GNU General Public License for more details. - - You should have received a copy of the Lesser GNU General Public License - along with this program. If not, see . -*/ - -#include "../include/zmq.h" - -#include "p2p.hpp" -#include "err.hpp" -#include "pipe.hpp" - -zmq::p2p_t::p2p_t (class app_thread_t *parent_) : - socket_base_t (parent_), - inpipe (NULL), - outpipe (NULL), - alive (true) -{ - options.requires_in = true; - options.requires_out = true; -} - -zmq::p2p_t::~p2p_t () -{ - if (inpipe) - inpipe->term (); - if (outpipe) - outpipe->term (); -} - -void zmq::p2p_t::xattach_pipes (class reader_t *inpipe_, - class writer_t *outpipe_, const blob_t &peer_identity_) -{ - zmq_assert (!inpipe && !outpipe); - inpipe = inpipe_; - outpipe = outpipe_; - outpipe_alive = true; -} - -void zmq::p2p_t::xdetach_inpipe (class reader_t *pipe_) -{ - zmq_assert (pipe_ == inpipe); - inpipe = NULL; -} - -void zmq::p2p_t::xdetach_outpipe (class writer_t *pipe_) -{ - zmq_assert (pipe_ == outpipe); - outpipe = NULL; -} - -void zmq::p2p_t::xkill (class reader_t *pipe_) -{ - zmq_assert (alive); - alive = false; -} - -void zmq::p2p_t::xrevive (class reader_t *pipe_) -{ - zmq_assert (!alive); - alive = true; -} - -void zmq::p2p_t::xrevive (class writer_t *pipe_) -{ - zmq_assert (!outpipe_alive); - outpipe_alive = true; -} - -int zmq::p2p_t::xsetsockopt (int option_, const void *optval_, - size_t optvallen_) -{ - errno = EINVAL; - return -1; -} - -int zmq::p2p_t::xsend (zmq_msg_t *msg_, int flags_) -{ - if (outpipe == NULL || !outpipe_alive) { - errno = EAGAIN; - return -1; - } - - if (!outpipe->write (msg_)) { - outpipe_alive = false; - errno = EAGAIN; - return -1; - } - - outpipe->flush (); - - // Detach the original message from the data buffer. - int rc = zmq_msg_init (msg_); - zmq_assert (rc == 0); - - return 0; -} - -int zmq::p2p_t::xrecv (zmq_msg_t *msg_, int flags_) -{ - // Deallocate old content of the message. - zmq_msg_close (msg_); - - if (!alive || !inpipe || !inpipe->read (msg_)) { - errno = EAGAIN; - return -1; - } - return 0; -} - -bool zmq::p2p_t::xhas_in () -{ - if (alive && inpipe && inpipe->check_read ()) - return true; - return false; -} - -bool zmq::p2p_t::xhas_out () -{ - if (outpipe == NULL || !outpipe_alive) - return false; - - outpipe_alive = outpipe->check_write (); - return outpipe_alive; -} - diff --git a/src/p2p.hpp b/src/p2p.hpp deleted file mode 100644 index 57320d9..0000000 --- a/src/p2p.hpp +++ /dev/null @@ -1,63 +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 Lesser GNU 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 - Lesser GNU General Public License for more details. - - You should have received a copy of the Lesser GNU General Public License - along with this program. If not, see . -*/ - -#ifndef __ZMQ_P2P_HPP_INCLUDED__ -#define __ZMQ_P2P_HPP_INCLUDED__ - -#include "socket_base.hpp" - -namespace zmq -{ - - class p2p_t : public socket_base_t - { - public: - - p2p_t (class app_thread_t *parent_); - ~p2p_t (); - - // Overloads of functions from socket_base_t. - void xattach_pipes (class reader_t *inpipe_, class writer_t *outpipe_, - const blob_t &peer_identity_); - void xdetach_inpipe (class reader_t *pipe_); - void xdetach_outpipe (class writer_t *pipe_); - void xkill (class reader_t *pipe_); - void xrevive (class reader_t *pipe_); - void xrevive (class writer_t *pipe_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - int xsend (zmq_msg_t *msg_, int flags_); - int xrecv (zmq_msg_t *msg_, int flags_); - bool xhas_in (); - bool xhas_out (); - - private: - - class reader_t *inpipe; - class writer_t *outpipe; - - bool alive; - bool outpipe_alive; - - p2p_t (const p2p_t&); - void operator = (const p2p_t&); - }; - -} - -#endif diff --git a/src/pair.cpp b/src/pair.cpp new file mode 100644 index 0000000..31524de --- /dev/null +++ b/src/pair.cpp @@ -0,0 +1,139 @@ +/* + 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 Lesser GNU 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 + Lesser GNU General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program. If not, see . +*/ + +#include "../include/zmq.h" + +#include "pair.hpp" +#include "err.hpp" +#include "pipe.hpp" + +zmq::pair_t::pair_t (class app_thread_t *parent_) : + socket_base_t (parent_), + inpipe (NULL), + outpipe (NULL), + alive (true) +{ + options.requires_in = true; + options.requires_out = true; +} + +zmq::pair_t::~pair_t () +{ + if (inpipe) + inpipe->term (); + if (outpipe) + outpipe->term (); +} + +void zmq::pair_t::xattach_pipes (class reader_t *inpipe_, + class writer_t *outpipe_, const blob_t &peer_identity_) +{ + zmq_assert (!inpipe && !outpipe); + inpipe = inpipe_; + outpipe = outpipe_; + outpipe_alive = true; +} + +void zmq::pair_t::xdetach_inpipe (class reader_t *pipe_) +{ + zmq_assert (pipe_ == inpipe); + inpipe = NULL; +} + +void zmq::pair_t::xdetach_outpipe (class writer_t *pipe_) +{ + zmq_assert (pipe_ == outpipe); + outpipe = NULL; +} + +void zmq::pair_t::xkill (class reader_t *pipe_) +{ + zmq_assert (alive); + alive = false; +} + +void zmq::pair_t::xrevive (class reader_t *pipe_) +{ + zmq_assert (!alive); + alive = true; +} + +void zmq::pair_t::xrevive (class writer_t *pipe_) +{ + zmq_assert (!outpipe_alive); + outpipe_alive = true; +} + +int zmq::pair_t::xsetsockopt (int option_, const void *optval_, + size_t optvallen_) +{ + errno = EINVAL; + return -1; +} + +int zmq::pair_t::xsend (zmq_msg_t *msg_, int flags_) +{ + if (outpipe == NULL || !outpipe_alive) { + errno = EAGAIN; + return -1; + } + + if (!outpipe->write (msg_)) { + outpipe_alive = false; + errno = EAGAIN; + return -1; + } + + outpipe->flush (); + + // Detach the original message from the data buffer. + int rc = zmq_msg_init (msg_); + zmq_assert (rc == 0); + + return 0; +} + +int zmq::pair_t::xrecv (zmq_msg_t *msg_, int flags_) +{ + // Deallocate old content of the message. + zmq_msg_close (msg_); + + if (!alive || !inpipe || !inpipe->read (msg_)) { + errno = EAGAIN; + return -1; + } + return 0; +} + +bool zmq::pair_t::xhas_in () +{ + if (alive && inpipe && inpipe->check_read ()) + return true; + return false; +} + +bool zmq::pair_t::xhas_out () +{ + if (outpipe == NULL || !outpipe_alive) + return false; + + outpipe_alive = outpipe->check_write (); + return outpipe_alive; +} + diff --git a/src/pair.hpp b/src/pair.hpp new file mode 100644 index 0000000..aea249f --- /dev/null +++ b/src/pair.hpp @@ -0,0 +1,63 @@ +/* + 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 Lesser GNU 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 + Lesser GNU General Public License for more details. + + You should have received a copy of the Lesser GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __ZMQ_PAIR_HPP_INCLUDED__ +#define __ZMQ_PAIR_HPP_INCLUDED__ + +#include "socket_base.hpp" + +namespace zmq +{ + + class pair_t : public socket_base_t + { + public: + + pair_t (class app_thread_t *parent_); + ~pair_t (); + + // Overloads of functions from socket_base_t. + void xattach_pipes (class reader_t *inpipe_, class writer_t *outpipe_, + const blob_t &peer_identity_); + void xdetach_inpipe (class reader_t *pipe_); + void xdetach_outpipe (class writer_t *pipe_); + void xkill (class reader_t *pipe_); + void xrevive (class reader_t *pipe_); + void xrevive (class writer_t *pipe_); + int xsetsockopt (int option_, const void *optval_, size_t optvallen_); + int xsend (zmq_msg_t *msg_, int flags_); + int xrecv (zmq_msg_t *msg_, int flags_); + bool xhas_in (); + bool xhas_out (); + + private: + + class reader_t *inpipe; + class writer_t *outpipe; + + bool alive; + bool outpipe_alive; + + pair_t (const pair_t&); + void operator = (const pair_t&); + }; + +} + +#endif -- cgit v1.2.3