mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-17 08:34:00 +00:00
C++ binding removed from the core
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
parent
7d87db0529
commit
d4e83d2601
@ -96,7 +96,6 @@ This package contains ZeroMQ related development libraries and header files.
|
|||||||
%files devel
|
%files devel
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
%{_includedir}/zmq.h
|
%{_includedir}/zmq.h
|
||||||
%{_includedir}/zmq.hpp
|
|
||||||
%{_includedir}/zmq_utils.h
|
%{_includedir}/zmq_utils.h
|
||||||
|
|
||||||
%{_libdir}/libzmq.la
|
%{_libdir}/libzmq.la
|
||||||
|
@ -3,8 +3,8 @@ MAN3 = zmq_bind.3 zmq_close.3 zmq_connect.3 zmq_init.3 \
|
|||||||
zmq_msg_init_data.3 zmq_msg_init_size.3 zmq_msg_move.3 zmq_msg_size.3 \
|
zmq_msg_init_data.3 zmq_msg_init_size.3 zmq_msg_move.3 zmq_msg_size.3 \
|
||||||
zmq_poll.3 zmq_recv.3 zmq_send.3 zmq_setsockopt.3 zmq_socket.3 \
|
zmq_poll.3 zmq_recv.3 zmq_send.3 zmq_setsockopt.3 zmq_socket.3 \
|
||||||
zmq_strerror.3 zmq_term.3 zmq_version.3 zmq_getsockopt.3 zmq_errno.3
|
zmq_strerror.3 zmq_term.3 zmq_version.3 zmq_getsockopt.3 zmq_errno.3
|
||||||
MAN7 = zmq.7 zmq_tcp.7 zmq_pgm.7 zmq_epgm.7 zmq_inproc.7 zmq_ipc.7 \
|
MAN7 = zmq.7 zmq_tcp.7 zmq_pgm.7 zmq_epgm.7 zmq_inproc.7 zmq_ipc.7
|
||||||
zmq_cpp.7
|
|
||||||
MAN_DOC = $(MAN1) $(MAN3) $(MAN7)
|
MAN_DOC = $(MAN1) $(MAN3) $(MAN7)
|
||||||
|
|
||||||
MAN_TXT = $(MAN3:%.3=%.txt)
|
MAN_TXT = $(MAN3:%.3=%.txt)
|
||||||
|
212
doc/zmq_cpp.txt
212
doc/zmq_cpp.txt
@ -1,212 +0,0 @@
|
|||||||
zmq_cpp(7)
|
|
||||||
==========
|
|
||||||
|
|
||||||
|
|
||||||
NAME
|
|
||||||
----
|
|
||||||
zmq_cpp - interface between 0MQ and C++ applications
|
|
||||||
|
|
||||||
|
|
||||||
SYNOPSIS
|
|
||||||
--------
|
|
||||||
*#include <zmq.hpp>*
|
|
||||||
|
|
||||||
*c$$++$$* ['flags'] 'files' *-lzmq* ['libraries']
|
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
|
||||||
-----------
|
|
||||||
This manual page describes how the 0MQ C++ language binding maps to the
|
|
||||||
underlying 0MQ C library functions.
|
|
||||||
|
|
||||||
All 0MQ constants defined by _zmq.h_ are also available to the C++ language
|
|
||||||
binding.
|
|
||||||
|
|
||||||
The following classes are provided in the 'zmq' namespace:
|
|
||||||
|
|
||||||
|
|
||||||
Context
|
|
||||||
~~~~~~~
|
|
||||||
The 'context_t' class encapsulates functionality dealing with the
|
|
||||||
initialisation and termination of a 0MQ _context_.
|
|
||||||
|
|
||||||
|
|
||||||
Constructor
|
|
||||||
^^^^^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*context_t::context_t(int 'io_threads')*
|
|
||||||
|
|
||||||
Maps to the _zmq_init()_ function, as described in linkzmq:zmq_init[3].
|
|
||||||
|
|
||||||
Destructor
|
|
||||||
^^^^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*context_t::~context_t(void)*
|
|
||||||
|
|
||||||
Maps to the _zmq_term()_ function, as described in linkzmq:zmq_term[3].
|
|
||||||
|
|
||||||
|
|
||||||
Methods
|
|
||||||
^^^^^^^
|
|
||||||
None.
|
|
||||||
|
|
||||||
|
|
||||||
Socket
|
|
||||||
~~~~~~
|
|
||||||
The 'socket_t' class encapsulates a 0MQ socket.
|
|
||||||
|
|
||||||
|
|
||||||
Constructor
|
|
||||||
^^^^^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*socket_t::socket_t(context_t '&context', int 'type')*
|
|
||||||
|
|
||||||
Maps to the _zmq_socket()_ function, as described in linkzmq:zmq_socket[3].
|
|
||||||
|
|
||||||
|
|
||||||
Destructor
|
|
||||||
^^^^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*socket_t::~socket_t(void)*
|
|
||||||
|
|
||||||
Calls the _zmq_close()_ function, as described in linkzmq:zmq_close[3].
|
|
||||||
|
|
||||||
|
|
||||||
Methods
|
|
||||||
^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*void socket_t::getsockopt(int 'option_name', void '*option_value', size_t
|
|
||||||
'*option_len')*
|
|
||||||
|
|
||||||
Maps to the _zmq_getsockopt()_ function, as described in
|
|
||||||
linkzmq:zmq_getsockopt[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*void socket_t::setsockopt(int 'option_name', const void '*option_value', size_t
|
|
||||||
'option_len')*
|
|
||||||
|
|
||||||
Maps to the _zmq_setsockopt()_ function, as described in
|
|
||||||
linkzmq:zmq_setsockopt[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*void socket_t::bind(const char '*endpoint')*
|
|
||||||
|
|
||||||
Maps to the _zmq_bind()_ function, as described in linkzmq:zmq_bind[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*void socket_t::connect(const char '*endpoint')*
|
|
||||||
|
|
||||||
Maps to the _zmq_connect()_ function, as described in linkzmq:zmq_connect[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*bool socket_t::send(message_t '&msg', int 'flags' = 0)*
|
|
||||||
|
|
||||||
Maps to the _zmq_send()_ function, as described in linkzmq:zmq_send[3].
|
|
||||||
Returns true if message is successfully sent, false if it is not.
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*bool socket_t::recv(message_t '*msg', int 'flags' = 0)*
|
|
||||||
|
|
||||||
Maps to the _zmq_recv()_ function, as described in linkzmq:zmq_recv[3].
|
|
||||||
Returns true if message is successfully received, false if it is not.
|
|
||||||
|
|
||||||
|
|
||||||
Message
|
|
||||||
~~~~~~~
|
|
||||||
The 'zmq::message_t' class encapsulates the 'zmq_msg_t' structure and
|
|
||||||
functions to construct, destruct and manipulate 0MQ messages.
|
|
||||||
|
|
||||||
|
|
||||||
Constructor
|
|
||||||
^^^^^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*message_t::message_t(void)*
|
|
||||||
*message_t::message_t(size_t 'size')*
|
|
||||||
*message_t::message_t(void '*data', size_t 'size', free_fn '*ffn')*
|
|
||||||
|
|
||||||
These map to the _zmq_msg_init()_, _zmq_msg_init_size()_ and
|
|
||||||
_zmq_msg_init_data()_ functions, described in linkzmq:zmq_msg_init[3],
|
|
||||||
linkzmq:zmq_msg_init_size[3] and linkzmq:zmq_msg_init_data[3] respectively.
|
|
||||||
|
|
||||||
|
|
||||||
Destructor
|
|
||||||
^^^^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*message_t::~message_t(void)*
|
|
||||||
|
|
||||||
Calls the _zmq_msg_close()_ function, as described in linkzmq:zmq_msg_close[3].
|
|
||||||
|
|
||||||
|
|
||||||
Methods
|
|
||||||
^^^^^^^
|
|
||||||
[verse]
|
|
||||||
*void *message_t::data (void)*
|
|
||||||
|
|
||||||
Maps to the _zmq_msg_data()_ function, as described in linkzmq:zmq_msg_data[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*size_t message_t::size (void)*
|
|
||||||
|
|
||||||
Maps to the _zmq_msg_size()_ function, as described in linkzmq:zmq_msg_size[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*void message_t::copy (message_t '*src')*
|
|
||||||
|
|
||||||
Maps to the _zmq_msg_copy()_ function, as described in linkzmq:zmq_msg_copy[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*void message_t::move (message_t '*src')*
|
|
||||||
|
|
||||||
Maps to the _zmq_msg_move()_ function, as described in linkzmq:zmq_msg_move[3].
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*message_t::rebuild(void)*
|
|
||||||
*message_t::rebuild(size_t 'size')*
|
|
||||||
*message_t::rebuild(void '*data', size_t 'size', free_fn '*ffn')*
|
|
||||||
|
|
||||||
Equivalent to calling the _zmq_msg_close()_ function followed by the
|
|
||||||
corresponding _zmq_msg_init()_ function.
|
|
||||||
|
|
||||||
|
|
||||||
Input/output multiplexing
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
[verse]
|
|
||||||
*int poll (zmq_pollitem_t *items, int nitems, long timeout = -1)*
|
|
||||||
|
|
||||||
The _poll()_ function is a namespaced equivalent of the _zmq_poll()_ function,
|
|
||||||
as described in linkzmq:zmq_poll[3].
|
|
||||||
|
|
||||||
NOTE: To obtain a 0MQ _socket_ for use in a _zmq_pollitem_t_ structure, you
|
|
||||||
should cast an instance of the _socket_t_ class to `(void *)`.
|
|
||||||
|
|
||||||
|
|
||||||
ERROR HANDLING
|
|
||||||
--------------
|
|
||||||
All errors reported by the underlying 0MQ C library functions are automatically
|
|
||||||
converted to exceptions by the C++ language binding. The 'zmq::error_t' class
|
|
||||||
is derived from the 'std::exception' class and uses the _zmq_strerror()_
|
|
||||||
function to convert the error code to human-readable string.
|
|
||||||
|
|
||||||
|
|
||||||
EXAMPLE
|
|
||||||
-------
|
|
||||||
----
|
|
||||||
zmq::context_t ctx (1);
|
|
||||||
zmq::socket_t s (ctx, ZMQ_PUB);
|
|
||||||
s.connect ("tcp://192.168.0.115:5555");
|
|
||||||
zmq::message_t msg (100);
|
|
||||||
memset (msg.data (), 0, 100);
|
|
||||||
s.send (msg);
|
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
SEE ALSO
|
|
||||||
--------
|
|
||||||
linkzmq:zmq[7]
|
|
||||||
|
|
||||||
|
|
||||||
AUTHORS
|
|
||||||
-------
|
|
||||||
The 0MQ documentation was written by Martin Sustrik <sustrik@250bpm.com> and
|
|
||||||
Martin Lucina <mato@kotelna.sk>.
|
|
289
include/zmq.hpp
289
include/zmq.hpp
@ -1,289 +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_HPP_INCLUDED__
|
|
||||||
#define __ZMQ_HPP_INCLUDED__
|
|
||||||
|
|
||||||
#include "zmq.h"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstring>
|
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
namespace zmq
|
|
||||||
{
|
|
||||||
|
|
||||||
typedef zmq_free_fn free_fn;
|
|
||||||
typedef zmq_pollitem_t pollitem_t;
|
|
||||||
|
|
||||||
class error_t : public std::exception
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
error_t () : errnum (zmq_errno ()) {}
|
|
||||||
|
|
||||||
virtual const char *what () const throw ()
|
|
||||||
{
|
|
||||||
return zmq_strerror (errnum);
|
|
||||||
}
|
|
||||||
|
|
||||||
int num () const
|
|
||||||
{
|
|
||||||
return errnum;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
int errnum;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline int poll (zmq_pollitem_t *items_, int nitems_, long timeout_ = -1)
|
|
||||||
{
|
|
||||||
int rc = zmq_poll (items_, nitems_, timeout_);
|
|
||||||
if (rc < 0)
|
|
||||||
throw error_t ();
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
class message_t : private zmq_msg_t
|
|
||||||
{
|
|
||||||
friend class socket_t;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
inline message_t ()
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_init (this);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline message_t (size_t size_)
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_init_size (this, size_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline message_t (void *data_, size_t size_, free_fn *ffn_,
|
|
||||||
void *hint_ = NULL)
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_init_data (this, data_, size_, ffn_, hint_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ~message_t ()
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_close (this);
|
|
||||||
assert (rc == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void rebuild ()
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_close (this);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
rc = zmq_msg_init (this);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void rebuild (size_t size_)
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_close (this);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
rc = zmq_msg_init_size (this, size_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void rebuild (void *data_, size_t size_, free_fn *ffn_,
|
|
||||||
void *hint_ = NULL)
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_close (this);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
rc = zmq_msg_init_data (this, data_, size_, ffn_, hint_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void move (message_t *msg_)
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_move (this, (zmq_msg_t*) msg_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void copy (message_t *msg_)
|
|
||||||
{
|
|
||||||
int rc = zmq_msg_copy (this, (zmq_msg_t*) msg_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void *data ()
|
|
||||||
{
|
|
||||||
return zmq_msg_data (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline size_t size ()
|
|
||||||
{
|
|
||||||
return zmq_msg_size (this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Disable implicit message copying, so that users won't use shared
|
|
||||||
// messages (less efficient) without being aware of the fact.
|
|
||||||
message_t (const message_t&);
|
|
||||||
void operator = (const message_t&);
|
|
||||||
};
|
|
||||||
|
|
||||||
class context_t
|
|
||||||
{
|
|
||||||
friend class socket_t;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
inline context_t (int io_threads_)
|
|
||||||
{
|
|
||||||
ptr = zmq_init (io_threads_);
|
|
||||||
if (ptr == NULL)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ~context_t ()
|
|
||||||
{
|
|
||||||
int rc = zmq_term (ptr);
|
|
||||||
assert (rc == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Be careful with this, it's probably only useful for
|
|
||||||
// using the C api together with an existing C++ api.
|
|
||||||
// Normally you should never need to use this.
|
|
||||||
inline operator void* ()
|
|
||||||
{
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
context_t (const context_t&);
|
|
||||||
void operator = (const context_t&);
|
|
||||||
};
|
|
||||||
|
|
||||||
class socket_t
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
inline socket_t (context_t &context_, int type_)
|
|
||||||
{
|
|
||||||
ptr = zmq_socket (context_.ptr, type_);
|
|
||||||
if (ptr == NULL)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline ~socket_t ()
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline operator void* ()
|
|
||||||
{
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void close()
|
|
||||||
{
|
|
||||||
if(ptr == NULL)
|
|
||||||
// already closed
|
|
||||||
return ;
|
|
||||||
int rc = zmq_close (ptr);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
ptr = 0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setsockopt (int option_, const void *optval_,
|
|
||||||
size_t optvallen_)
|
|
||||||
{
|
|
||||||
int rc = zmq_setsockopt (ptr, option_, optval_, optvallen_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void getsockopt (int option_, void *optval_,
|
|
||||||
size_t *optvallen_)
|
|
||||||
{
|
|
||||||
int rc = zmq_getsockopt (ptr, option_, optval_, optvallen_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void bind (const char *addr_)
|
|
||||||
{
|
|
||||||
int rc = zmq_bind (ptr, addr_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void connect (const char *addr_)
|
|
||||||
{
|
|
||||||
int rc = zmq_connect (ptr, addr_);
|
|
||||||
if (rc != 0)
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool send (message_t &msg_, int flags_ = 0)
|
|
||||||
{
|
|
||||||
int rc = zmq_send (ptr, &msg_, flags_);
|
|
||||||
if (rc == 0)
|
|
||||||
return true;
|
|
||||||
if (rc == -1 && zmq_errno () == EAGAIN)
|
|
||||||
return false;
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool recv (message_t *msg_, int flags_ = 0)
|
|
||||||
{
|
|
||||||
int rc = zmq_recv (ptr, msg_, flags_);
|
|
||||||
if (rc == 0)
|
|
||||||
return true;
|
|
||||||
if (rc == -1 && zmq_errno () == EAGAIN)
|
|
||||||
return false;
|
|
||||||
throw error_t ();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void *ptr;
|
|
||||||
|
|
||||||
socket_t (const socket_t&);
|
|
||||||
void operator = (const socket_t&);
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -3,7 +3,7 @@ lib_LTLIBRARIES = libzmq.la
|
|||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = libzmq.pc
|
pkgconfig_DATA = libzmq.pc
|
||||||
|
|
||||||
include_HEADERS = ../include/zmq.h ../include/zmq.hpp ../include/zmq_utils.h
|
include_HEADERS = ../include/zmq.h ../include/zmq_utils.h
|
||||||
|
|
||||||
if BUILD_PGM
|
if BUILD_PGM
|
||||||
noinst_LTLIBRARIES = libpgm.la
|
noinst_LTLIBRARIES = libpgm.la
|
||||||
|
Loading…
x
Reference in New Issue
Block a user