mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-19 18:03:50 +00:00
zmq_device removed
Devices are basically applications on top of 0MQ stack. They should reside in separate libraties. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
d4d184a750
commit
941be8d217
@ -91,14 +91,7 @@ This package contains ZeroMQ related development libraries and header files.
|
|||||||
%{_libdir}/libzmq.so.1
|
%{_libdir}/libzmq.so.1
|
||||||
%{_libdir}/libzmq.so.1.0.0
|
%{_libdir}/libzmq.so.1.0.0
|
||||||
|
|
||||||
%attr(0755,root,root) %{_bindir}/zmq_forwarder
|
|
||||||
%attr(0755,root,root) %{_bindir}/zmq_queue
|
|
||||||
%attr(0755,root,root) %{_bindir}/zmq_streamer
|
|
||||||
|
|
||||||
%{_mandir}/man7/zmq.7.gz
|
%{_mandir}/man7/zmq.7.gz
|
||||||
%{_mandir}/man1/zmq_forwarder.1.gz
|
|
||||||
%{_mandir}/man1/zmq_queue.1.gz
|
|
||||||
%{_mandir}/man1/zmq_streamer.1.gz
|
|
||||||
|
|
||||||
%files devel
|
%files devel
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
|
@ -241,16 +241,6 @@ typedef struct
|
|||||||
|
|
||||||
ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout);
|
ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout);
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/* Devices - Experimental. */
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
#define ZMQ_STREAMER 1
|
|
||||||
#define ZMQ_FORWARDER 2
|
|
||||||
#define ZMQ_QUEUE 3
|
|
||||||
|
|
||||||
ZMQ_EXPORT int zmq_device (int device, void * insocket, void* outsocket);
|
|
||||||
|
|
||||||
#undef ZMQ_EXPORT
|
#undef ZMQ_EXPORT
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -62,13 +62,6 @@ namespace zmq
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void device (int device_, void * insocket_, void* outsocket_)
|
|
||||||
{
|
|
||||||
int rc = zmq_device (device_, insocket_, outsocket_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
class message_t : private zmq_msg_t
|
class message_t : private zmq_msg_t
|
||||||
{
|
{
|
||||||
friend class socket_t;
|
friend class socket_t;
|
||||||
|
@ -71,7 +71,6 @@ libzmq_la_SOURCES = \
|
|||||||
connect_session.hpp \
|
connect_session.hpp \
|
||||||
ctx.hpp \
|
ctx.hpp \
|
||||||
decoder.hpp \
|
decoder.hpp \
|
||||||
device.hpp \
|
|
||||||
devpoll.hpp \
|
devpoll.hpp \
|
||||||
dist.hpp \
|
dist.hpp \
|
||||||
encoder.hpp \
|
encoder.hpp \
|
||||||
@ -141,7 +140,6 @@ libzmq_la_SOURCES = \
|
|||||||
ctx.cpp \
|
ctx.cpp \
|
||||||
connect_session.cpp \
|
connect_session.cpp \
|
||||||
decoder.cpp \
|
decoder.cpp \
|
||||||
device.cpp \
|
|
||||||
devpoll.cpp \
|
devpoll.cpp \
|
||||||
dist.cpp \
|
dist.cpp \
|
||||||
encoder.cpp \
|
encoder.cpp \
|
||||||
|
120
src/device.cpp
120
src/device.cpp
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2007-2011 iMatix Corporation
|
|
||||||
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
|
||||||
|
|
||||||
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 <stddef.h>
|
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
|
||||||
|
|
||||||
#include "device.hpp"
|
|
||||||
#include "socket_base.hpp"
|
|
||||||
#include "likely.hpp"
|
|
||||||
#include "err.hpp"
|
|
||||||
|
|
||||||
int zmq::device (class socket_base_t *insocket_,
|
|
||||||
class socket_base_t *outsocket_)
|
|
||||||
{
|
|
||||||
zmq_msg_t msg;
|
|
||||||
int rc = zmq_msg_init (&msg);
|
|
||||||
|
|
||||||
if (rc != 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t more;
|
|
||||||
size_t moresz;
|
|
||||||
|
|
||||||
zmq_pollitem_t items [2];
|
|
||||||
items [0].socket = insocket_;
|
|
||||||
items [0].fd = 0;
|
|
||||||
items [0].events = ZMQ_POLLIN;
|
|
||||||
items [0].revents = 0;
|
|
||||||
items [1].socket = outsocket_;
|
|
||||||
items [1].fd = 0;
|
|
||||||
items [1].events = ZMQ_POLLIN;
|
|
||||||
items [1].revents = 0;
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
// Wait while there are either requests or replies to process.
|
|
||||||
rc = zmq_poll (&items [0], 2, -1);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The algorithm below asumes ratio of request and replies processed
|
|
||||||
// under full load to be 1:1. Although processing requests replies
|
|
||||||
// first is tempting it is suspectible to DoS attacks (overloading
|
|
||||||
// the system with unsolicited replies).
|
|
||||||
|
|
||||||
// Process a request.
|
|
||||||
if (items [0].revents & ZMQ_POLLIN) {
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
rc = insocket_->recv (&msg, 0);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
moresz = sizeof (more);
|
|
||||||
rc = insocket_->getsockopt (ZMQ_RCVMORE, &more, &moresz);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = outsocket_->send (&msg, more ? ZMQ_SNDMORE : 0);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!more)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process a reply.
|
|
||||||
if (items [1].revents & ZMQ_POLLIN) {
|
|
||||||
while (true) {
|
|
||||||
|
|
||||||
rc = outsocket_->recv (&msg, 0);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
moresz = sizeof (more);
|
|
||||||
rc = outsocket_->getsockopt (ZMQ_RCVMORE, &more, &moresz);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = insocket_->send (&msg, more ? ZMQ_SNDMORE : 0);
|
|
||||||
if (unlikely (rc < 0)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!more)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2007-2011 iMatix Corporation
|
|
||||||
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
|
||||||
|
|
||||||
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_DEVICE_HPP_INCLUDED__
|
|
||||||
#define __ZMQ_DEVICE_HPP_INCLUDED__
|
|
||||||
|
|
||||||
namespace zmq
|
|
||||||
{
|
|
||||||
|
|
||||||
int device (class socket_base_t *insocket_,
|
|
||||||
class socket_base_t *outsocket_);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
18
src/zmq.cpp
18
src/zmq.cpp
@ -40,7 +40,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include "device.hpp"
|
|
||||||
#include "socket_base.hpp"
|
#include "socket_base.hpp"
|
||||||
#include "msg_content.hpp"
|
#include "msg_content.hpp"
|
||||||
#include "stdint.hpp"
|
#include "stdint.hpp"
|
||||||
@ -729,23 +728,6 @@ int zmq_errno ()
|
|||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq_device (int device_, void *insocket_, void *outsocket_)
|
|
||||||
{
|
|
||||||
if (!insocket_ || !outsocket_) {
|
|
||||||
errno = EFAULT;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// 0MQ utils - to be used by perf tests
|
// 0MQ utils - to be used by perf tests
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
x
Reference in New Issue
Block a user