mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-30 21:50:49 +01:00
zmq_getsockopt function added
This commit is contained in:
@@ -187,6 +187,8 @@ ZMQ_EXPORT void *zmq_socket (void *context, int type);
|
|||||||
ZMQ_EXPORT int zmq_close (void *s);
|
ZMQ_EXPORT int zmq_close (void *s);
|
||||||
ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
|
ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
|
||||||
size_t optvallen);
|
size_t optvallen);
|
||||||
|
ZMQ_EXPORT int zmq_getsockopt (void *s, int option, void *optval,
|
||||||
|
size_t *optvallen);
|
||||||
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
|
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
|
||||||
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
|
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
|
||||||
ZMQ_EXPORT int zmq_send (void *s, zmq_msg_t *msg, int flags);
|
ZMQ_EXPORT int zmq_send (void *s, zmq_msg_t *msg, int flags);
|
||||||
|
|||||||
106
src/options.cpp
106
src/options.cpp
@@ -17,6 +17,8 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "../include/zmq.h"
|
#include "../include/zmq.h"
|
||||||
|
|
||||||
#include "options.hpp"
|
#include "options.hpp"
|
||||||
@@ -68,11 +70,11 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZMQ_AFFINITY:
|
case ZMQ_AFFINITY:
|
||||||
if (optvallen_ != sizeof (int64_t)) {
|
if (optvallen_ != sizeof (uint64_t)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
affinity = (uint64_t) *((int64_t*) optval_);
|
affinity = *((uint64_t*) optval_);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZMQ_IDENTITY:
|
case ZMQ_IDENTITY:
|
||||||
@@ -139,3 +141,103 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
|||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
||||||
|
{
|
||||||
|
switch (option_) {
|
||||||
|
|
||||||
|
case ZMQ_HWM:
|
||||||
|
if (*optvallen_ < sizeof (uint64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((uint64_t*) optval_) = hwm;
|
||||||
|
*optvallen_ = sizeof (uint64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_LWM:
|
||||||
|
if (*optvallen_ < sizeof (uint64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((uint64_t*) optval_) = lwm;
|
||||||
|
*optvallen_ = sizeof (uint64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_SWAP:
|
||||||
|
if (*optvallen_ < sizeof (int64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int64_t*) optval_) = swap;
|
||||||
|
*optvallen_ = sizeof (int64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_AFFINITY:
|
||||||
|
if (*optvallen_ < sizeof (uint64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((uint64_t*) optval_) = affinity;
|
||||||
|
*optvallen_ = sizeof (uint64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_IDENTITY:
|
||||||
|
if (*optvallen_ < identity.size ()) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memcpy (optval_, identity.data (), identity.size ());
|
||||||
|
*optvallen_ = identity.size ();
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
|
case ZMQ_RATE:
|
||||||
|
if (*optvallen_ < sizeof (int64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int64_t*) optval_) = rate;
|
||||||
|
*optvallen_ = sizeof (int64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_RECOVERY_IVL:
|
||||||
|
if (*optvallen_ < sizeof (int64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int64_t*) optval_) = recovery_ivl;
|
||||||
|
*optvallen_ = sizeof (int64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_MCAST_LOOP:
|
||||||
|
if (*optvallen_ < sizeof (int64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((int64_t*) optval_) = use_multicast_loop ? 1 : 0;
|
||||||
|
*optvallen_ = sizeof (int64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_SNDBUF:
|
||||||
|
if (*optvallen_ < sizeof (uint64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((uint64_t*) optval_) = sndbuf;
|
||||||
|
*optvallen_ = sizeof (uint64_t);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case ZMQ_RCVBUF:
|
||||||
|
if (*optvallen_ < sizeof (uint64_t)) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*((uint64_t*) optval_) = rcvbuf;
|
||||||
|
*optvallen_ = sizeof (uint64_t);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace zmq
|
|||||||
options_t ();
|
options_t ();
|
||||||
|
|
||||||
int setsockopt (int option_, const void *optval_, size_t optvallen_);
|
int setsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
|
int getsockopt (int option_, void *optval_, size_t *optvallen_);
|
||||||
|
|
||||||
uint64_t hwm;
|
uint64_t hwm;
|
||||||
uint64_t lwm;
|
uint64_t lwm;
|
||||||
|
|||||||
@@ -67,6 +67,13 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
|
|||||||
return options.setsockopt (option_, optval_, optvallen_);
|
return options.setsockopt (option_, optval_, optvallen_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zmq::socket_base_t::getsockopt (int option_, void *optval_,
|
||||||
|
size_t *optvallen_)
|
||||||
|
{
|
||||||
|
// At the moment there are no socket-type-specific overloads of getsockopt.
|
||||||
|
return options.getsockopt (option_, optval_, optvallen_);
|
||||||
|
}
|
||||||
|
|
||||||
int zmq::socket_base_t::bind (const char *addr_)
|
int zmq::socket_base_t::bind (const char *addr_)
|
||||||
{
|
{
|
||||||
// Parse addr_ string.
|
// Parse addr_ string.
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ namespace zmq
|
|||||||
socket_base_t (class app_thread_t *parent_);
|
socket_base_t (class app_thread_t *parent_);
|
||||||
|
|
||||||
// Interface for communication with the API layer.
|
// Interface for communication with the API layer.
|
||||||
int setsockopt (int option_, const void *optval_,
|
int setsockopt (int option_, const void *optval_, size_t optvallen_);
|
||||||
size_t optvallen_);
|
int getsockopt (int option_, void *optval_, 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 (zmq_msg_t *msg_, int flags_);
|
int send (zmq_msg_t *msg_, int flags_);
|
||||||
|
|||||||
@@ -305,6 +305,12 @@ int zmq_setsockopt (void *s_, int option_, const void *optval_,
|
|||||||
optvallen_));
|
optvallen_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_)
|
||||||
|
{
|
||||||
|
return (((zmq::socket_base_t*) s_)->getsockopt (option_, optval_,
|
||||||
|
optvallen_));
|
||||||
|
}
|
||||||
|
|
||||||
int zmq_bind (void *s_, const char *addr_)
|
int zmq_bind (void *s_, const char *addr_)
|
||||||
{
|
{
|
||||||
return (((zmq::socket_base_t*) s_)->bind (addr_));
|
return (((zmq::socket_base_t*) s_)->bind (addr_));
|
||||||
|
|||||||
Reference in New Issue
Block a user