mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-27 15:41:05 +08:00
ZMQII-16: Change "struct zmq_msg_t" to "zmq_msg_t" in C binding
This commit is contained in:
parent
3bd8f83f6d
commit
088a2db674
@ -80,21 +80,21 @@ ZMQ_EXPORT const char *zmq_strerror (int errnum);
|
|||||||
// rather than straighforward malloc/free. Not that 'content' is not a pointer
|
// rather than straighforward malloc/free. Not that 'content' is not a pointer
|
||||||
// to the raw data. Rather it is pointer to zmq::msg_content_t structure
|
// to the raw data. Rather it is pointer to zmq::msg_content_t structure
|
||||||
// (see src/msg_content.hpp for its definition).
|
// (see src/msg_content.hpp for its definition).
|
||||||
struct zmq_msg_t
|
typedef struct
|
||||||
{
|
{
|
||||||
void *content;
|
void *content;
|
||||||
unsigned char shared;
|
unsigned char shared;
|
||||||
unsigned char vsm_size;
|
unsigned char vsm_size;
|
||||||
unsigned char vsm_data [ZMQ_MAX_VSM_SIZE];
|
unsigned char vsm_data [ZMQ_MAX_VSM_SIZE];
|
||||||
};
|
} zmq_msg_t;
|
||||||
|
|
||||||
// Initialise an empty message (zero bytes long).
|
// Initialise an empty message (zero bytes long).
|
||||||
ZMQ_EXPORT int zmq_msg_init (struct zmq_msg_t *msg);
|
ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg);
|
||||||
|
|
||||||
// Initialise a message 'size' bytes long.
|
// Initialise a message 'size' bytes long.
|
||||||
//
|
//
|
||||||
// Errors: ENOMEM - message is too big to fit into memory.
|
// Errors: ENOMEM - message is too big to fit into memory.
|
||||||
ZMQ_EXPORT int zmq_msg_init_size (struct zmq_msg_t *msg, size_t size);
|
ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg, size_t size);
|
||||||
|
|
||||||
// Initialise a message from an existing buffer. Message isn't copied,
|
// Initialise a message from an existing buffer. Message isn't copied,
|
||||||
// instead 0MQ infrastructure takes ownership of the buffer and
|
// instead 0MQ infrastructure takes ownership of the buffer and
|
||||||
@ -102,28 +102,28 @@ ZMQ_EXPORT int zmq_msg_init_size (struct zmq_msg_t *msg, size_t size);
|
|||||||
// needed anymore. Note that deallocation function prototype is designed
|
// needed anymore. Note that deallocation function prototype is designed
|
||||||
// so that it complies with standard C 'free' function.
|
// so that it complies with standard C 'free' function.
|
||||||
typedef void (zmq_free_fn) (void *data);
|
typedef void (zmq_free_fn) (void *data);
|
||||||
ZMQ_EXPORT int zmq_msg_init_data (struct zmq_msg_t *msg, void *data,
|
ZMQ_EXPORT int zmq_msg_init_data (zmq_msg_t *msg, void *data,
|
||||||
size_t size, zmq_free_fn *ffn);
|
size_t size, zmq_free_fn *ffn);
|
||||||
|
|
||||||
// Deallocate the message.
|
// Deallocate the message.
|
||||||
ZMQ_EXPORT int zmq_msg_close (struct zmq_msg_t *msg);
|
ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg);
|
||||||
|
|
||||||
// Move the content of the message from 'src' to 'dest'. The content isn't
|
// Move the content of the message from 'src' to 'dest'. The content isn't
|
||||||
// copied, just moved. 'src' is an empty message after the call. Original
|
// copied, just moved. 'src' is an empty message after the call. Original
|
||||||
// content of 'dest' message is deallocated.
|
// content of 'dest' message is deallocated.
|
||||||
ZMQ_EXPORT int zmq_msg_move (struct zmq_msg_t *dest, struct zmq_msg_t *src);
|
ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src);
|
||||||
|
|
||||||
// Copy the 'src' message to 'dest'. The content isn't copied, instead
|
// Copy the 'src' message to 'dest'. The content isn't copied, instead
|
||||||
// reference count is increased. Don't modify the message data after the
|
// reference count is increased. Don't modify the message data after the
|
||||||
// call as they are shared between two messages. Original content of 'dest'
|
// call as they are shared between two messages. Original content of 'dest'
|
||||||
// message is deallocated.
|
// message is deallocated.
|
||||||
ZMQ_EXPORT int zmq_msg_copy (struct zmq_msg_t *dest, struct zmq_msg_t *src);
|
ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src);
|
||||||
|
|
||||||
// Returns pointer to message data.
|
// Returns pointer to message data.
|
||||||
ZMQ_EXPORT void *zmq_msg_data (struct zmq_msg_t *msg);
|
ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg);
|
||||||
|
|
||||||
// Return size of message data (in bytes).
|
// Return size of message data (in bytes).
|
||||||
ZMQ_EXPORT size_t zmq_msg_size (struct zmq_msg_t *msg);
|
ZMQ_EXPORT size_t zmq_msg_size (zmq_msg_t *msg);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// 0MQ infrastructure (a.k.a. context) initialisation & termination.
|
// 0MQ infrastructure (a.k.a. context) initialisation & termination.
|
||||||
@ -336,7 +336,7 @@ ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
|
|||||||
// non-blocking send).
|
// non-blocking send).
|
||||||
// ENOTSUP - function isn't supported by particular socket type.
|
// ENOTSUP - function isn't supported by particular socket type.
|
||||||
// EFSM - function cannot be called at the moment.
|
// EFSM - function cannot be called at the moment.
|
||||||
ZMQ_EXPORT int zmq_send (void *s, struct zmq_msg_t *msg, int flags);
|
ZMQ_EXPORT int zmq_send (void *s, zmq_msg_t *msg, int flags);
|
||||||
|
|
||||||
// Flush the messages that were send using ZMQ_NOFLUSH flag down the stream.
|
// Flush the messages that were send using ZMQ_NOFLUSH flag down the stream.
|
||||||
//
|
//
|
||||||
@ -351,7 +351,7 @@ ZMQ_EXPORT int zmq_flush (void *s);
|
|||||||
// non-blocking receive).
|
// non-blocking receive).
|
||||||
// ENOTSUP - function isn't supported by particular socket type.
|
// ENOTSUP - function isn't supported by particular socket type.
|
||||||
// EFSM - function cannot be called at the moment.
|
// EFSM - function cannot be called at the moment.
|
||||||
ZMQ_EXPORT int zmq_recv (void *s, struct zmq_msg_t *msg, int flags);
|
ZMQ_EXPORT int zmq_recv (void *s, zmq_msg_t *msg, int flags);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Helper functions.
|
// Helper functions.
|
||||||
|
@ -31,7 +31,7 @@ int main (int argc, char *argv [])
|
|||||||
void *s;
|
void *s;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
struct zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
printf ("usage: local_lat <bind-to> <message-size> "
|
printf ("usage: local_lat <bind-to> <message-size> "
|
||||||
|
@ -31,7 +31,7 @@ int main (int argc, char *argv [])
|
|||||||
void *s;
|
void *s;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
struct zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
void *watch;
|
void *watch;
|
||||||
unsigned long elapsed;
|
unsigned long elapsed;
|
||||||
unsigned long throughput;
|
unsigned long throughput;
|
||||||
|
@ -32,7 +32,7 @@ int main (int argc, char *argv [])
|
|||||||
void *s;
|
void *s;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
struct zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
void *watch;
|
void *watch;
|
||||||
unsigned long elapsed;
|
unsigned long elapsed;
|
||||||
double latency;
|
double latency;
|
||||||
|
@ -31,7 +31,7 @@ int main (int argc, char *argv [])
|
|||||||
void *s;
|
void *s;
|
||||||
int rc;
|
int rc;
|
||||||
int i;
|
int i;
|
||||||
struct zmq_msg_t msg;
|
zmq_msg_t msg;
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
printf ("usage: remote_thr <connect-to> <message-size> "
|
printf ("usage: remote_thr <connect-to> <message-size> "
|
||||||
|
@ -66,7 +66,7 @@ int zmq::p2p_t::xsetsockopt (int option_, const void *optval_,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::p2p_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
int zmq::p2p_t::xsend (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
zmq_assert (false);
|
zmq_assert (false);
|
||||||
return 0;
|
return 0;
|
||||||
@ -78,7 +78,7 @@ int zmq::p2p_t::xflush ()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::p2p_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
int zmq::p2p_t::xrecv (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
zmq_assert (false);
|
zmq_assert (false);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -39,9 +39,9 @@ namespace zmq
|
|||||||
void xkill (class reader_t *pipe_);
|
void xkill (class reader_t *pipe_);
|
||||||
void xrevive (class reader_t *pipe_);
|
void xrevive (class reader_t *pipe_);
|
||||||
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
int xsend (struct zmq_msg_t *msg_, int flags_);
|
int xsend (zmq_msg_t *msg_, int flags_);
|
||||||
int xflush ();
|
int xflush ();
|
||||||
int xrecv (struct zmq_msg_t *msg_, int flags_);
|
int xrecv (zmq_msg_t *msg_, int flags_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ bool zmq::writer_t::check_write (uint64_t size_)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zmq::writer_t::write (struct zmq_msg_t *msg_)
|
bool zmq::writer_t::write (zmq_msg_t *msg_)
|
||||||
{
|
{
|
||||||
pipe->write (*msg_);
|
pipe->write (*msg_);
|
||||||
return true;
|
return true;
|
||||||
|
@ -43,7 +43,7 @@ namespace zmq
|
|||||||
void set_endpoint (i_endpoint *endpoint_);
|
void set_endpoint (i_endpoint *endpoint_);
|
||||||
|
|
||||||
// Reads a message to the underlying pipe.
|
// Reads a message to the underlying pipe.
|
||||||
bool read (struct zmq_msg_t *msg_);
|
bool read (zmq_msg_t *msg_);
|
||||||
|
|
||||||
// Ask pipe to terminate.
|
// Ask pipe to terminate.
|
||||||
void term ();
|
void term ();
|
||||||
@ -93,7 +93,7 @@ namespace zmq
|
|||||||
|
|
||||||
// Writes a message to the underlying pipe. Returns false if the
|
// Writes a message to the underlying pipe. Returns false if the
|
||||||
// message cannot be written because high watermark was reached.
|
// message cannot be written because high watermark was reached.
|
||||||
bool write (struct zmq_msg_t *msg_);
|
bool write (zmq_msg_t *msg_);
|
||||||
|
|
||||||
// Flush the messages downsteam.
|
// Flush the messages downsteam.
|
||||||
void flush ();
|
void flush ();
|
||||||
|
@ -72,7 +72,7 @@ int zmq::pub_t::xsetsockopt (int option_, const void *optval_,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::pub_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
int zmq::pub_t::xsend (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
out_pipes_t::size_type pipes_count = out_pipes.size ();
|
out_pipes_t::size_type pipes_count = out_pipes.size ();
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ int zmq::pub_t::xflush ()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::pub_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
int zmq::pub_t::xrecv (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
errno = ENOTSUP;
|
errno = ENOTSUP;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -40,9 +40,9 @@ namespace zmq
|
|||||||
void xkill (class reader_t *pipe_);
|
void xkill (class reader_t *pipe_);
|
||||||
void xrevive (class reader_t *pipe_);
|
void xrevive (class reader_t *pipe_);
|
||||||
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
int xsend (struct zmq_msg_t *msg_, int flags_);
|
int xsend (zmq_msg_t *msg_, int flags_);
|
||||||
int xflush ();
|
int xflush ();
|
||||||
int xrecv (struct zmq_msg_t *msg_, int flags_);
|
int xrecv (zmq_msg_t *msg_, int flags_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ int zmq::rep_t::xsetsockopt (int option_, const void *optval_,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::rep_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
if (!waiting_for_reply) {
|
if (!waiting_for_reply) {
|
||||||
errno = EFSM;
|
errno = EFSM;
|
||||||
@ -165,7 +165,7 @@ int zmq::rep_t::xflush ()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::rep_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
int zmq::rep_t::xrecv (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
// Deallocate old content of the message.
|
// Deallocate old content of the message.
|
||||||
zmq_msg_close (msg_);
|
zmq_msg_close (msg_);
|
||||||
|
@ -40,9 +40,9 @@ namespace zmq
|
|||||||
void xkill (class reader_t *pipe_);
|
void xkill (class reader_t *pipe_);
|
||||||
void xrevive (class reader_t *pipe_);
|
void xrevive (class reader_t *pipe_);
|
||||||
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
int xsend (struct zmq_msg_t *msg_, int flags_);
|
int xsend (zmq_msg_t *msg_, int flags_);
|
||||||
int xflush ();
|
int xflush ();
|
||||||
int xrecv (struct zmq_msg_t *msg_, int flags_);
|
int xrecv (zmq_msg_t *msg_, int flags_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ int zmq::req_t::xsetsockopt (int option_, const void *optval_,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::req_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
int zmq::req_t::xsend (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
// If we've sent a request and we still haven't got the reply,
|
// If we've sent a request and we still haven't got the reply,
|
||||||
// we can't send another request.
|
// we can't send another request.
|
||||||
@ -170,7 +170,7 @@ int zmq::req_t::xflush ()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::req_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
int zmq::req_t::xrecv (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
// Deallocate old content of the message.
|
// Deallocate old content of the message.
|
||||||
zmq_msg_close (msg_);
|
zmq_msg_close (msg_);
|
||||||
|
@ -40,9 +40,9 @@ namespace zmq
|
|||||||
void xkill (class reader_t *pipe_);
|
void xkill (class reader_t *pipe_);
|
||||||
void xrevive (class reader_t *pipe_);
|
void xrevive (class reader_t *pipe_);
|
||||||
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
int xsend (struct zmq_msg_t *msg_, int flags_);
|
int xsend (zmq_msg_t *msg_, int flags_);
|
||||||
int xflush ();
|
int xflush ();
|
||||||
int xrecv (struct zmq_msg_t *msg_, int flags_);
|
int xrecv (zmq_msg_t *msg_, int flags_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "../bindings/c/zmq.h"
|
||||||
|
|
||||||
#include "i_endpoint.hpp"
|
#include "i_endpoint.hpp"
|
||||||
#include "object.hpp"
|
#include "object.hpp"
|
||||||
#include "yarray_item.hpp"
|
#include "yarray_item.hpp"
|
||||||
@ -47,9 +49,9 @@ namespace zmq
|
|||||||
size_t optvallen_);
|
size_t optvallen_);
|
||||||
int bind (const char *addr_);
|
int bind (const char *addr_);
|
||||||
int connect (const char *addr_);
|
int connect (const char *addr_);
|
||||||
int send (struct zmq_msg_t *msg_, int flags_);
|
int send (zmq_msg_t *msg_, int flags_);
|
||||||
int flush ();
|
int flush ();
|
||||||
int recv (struct zmq_msg_t *msg_, int flags_);
|
int recv (zmq_msg_t *msg_, int flags_);
|
||||||
int close ();
|
int close ();
|
||||||
|
|
||||||
// The list of sessions cannot be accessed via inter-thread
|
// The list of sessions cannot be accessed via inter-thread
|
||||||
@ -83,9 +85,9 @@ namespace zmq
|
|||||||
// Actual algorithms are to be defined by individual socket types.
|
// Actual algorithms are to be defined by individual socket types.
|
||||||
virtual int xsetsockopt (int option_, const void *optval_,
|
virtual int xsetsockopt (int option_, const void *optval_,
|
||||||
size_t optvallen_) = 0;
|
size_t optvallen_) = 0;
|
||||||
virtual int xsend (struct zmq_msg_t *msg_, int options_) = 0;
|
virtual int xsend (zmq_msg_t *msg_, int options_) = 0;
|
||||||
virtual int xflush () = 0;
|
virtual int xflush () = 0;
|
||||||
virtual int xrecv (struct zmq_msg_t *msg_, int options_) = 0;
|
virtual int xrecv (zmq_msg_t *msg_, int options_) = 0;
|
||||||
|
|
||||||
// Socket options.
|
// Socket options.
|
||||||
options_t options;
|
options_t options;
|
||||||
|
@ -122,7 +122,7 @@ int zmq::sub_t::xsetsockopt (int option_, const void *optval_,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::sub_t::xsend (struct zmq_msg_t *msg_, int flags_)
|
int zmq::sub_t::xsend (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
errno = ENOTSUP;
|
errno = ENOTSUP;
|
||||||
return -1;
|
return -1;
|
||||||
@ -134,7 +134,7 @@ int zmq::sub_t::xflush ()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmq::sub_t::xrecv (struct zmq_msg_t *msg_, int flags_)
|
int zmq::sub_t::xrecv (zmq_msg_t *msg_, int flags_)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
@ -45,15 +45,15 @@ namespace zmq
|
|||||||
void xkill (class reader_t *pipe_);
|
void xkill (class reader_t *pipe_);
|
||||||
void xrevive (class reader_t *pipe_);
|
void xrevive (class reader_t *pipe_);
|
||||||
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
int xsetsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
int xsend (struct zmq_msg_t *msg_, int flags_);
|
int xsend (zmq_msg_t *msg_, int flags_);
|
||||||
int xflush ();
|
int xflush ();
|
||||||
int xrecv (struct zmq_msg_t *msg_, int flags_);
|
int xrecv (zmq_msg_t *msg_, int flags_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// Helper function to return one message choosed using
|
// Helper function to return one message choosed using
|
||||||
// fair queueing algorithm.
|
// fair queueing algorithm.
|
||||||
int fq (struct zmq_msg_t *msg_, int flags_);
|
int fq (zmq_msg_t *msg_, int flags_);
|
||||||
|
|
||||||
// Inbound pipes, i.e. those the socket is getting messages from.
|
// Inbound pipes, i.e. those the socket is getting messages from.
|
||||||
typedef yarray_t <class reader_t> in_pipes_t;
|
typedef yarray_t <class reader_t> in_pipes_t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user