zmq_getsockopt function added

This commit is contained in:
Martin Sustrik 2010-04-09 13:04:15 +02:00
parent 027bb1d2a7
commit 716f4ac871
6 changed files with 122 additions and 4 deletions

View File

@ -187,6 +187,8 @@ ZMQ_EXPORT void *zmq_socket (void *context, int type);
ZMQ_EXPORT int zmq_close (void *s);
ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
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_connect (void *s, const char *addr);
ZMQ_EXPORT int zmq_send (void *s, zmq_msg_t *msg, int flags);

View File

@ -17,6 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "../include/zmq.h"
#include "options.hpp"
@ -68,11 +70,11 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
return 0;
case ZMQ_AFFINITY:
if (optvallen_ != sizeof (int64_t)) {
if (optvallen_ != sizeof (uint64_t)) {
errno = EINVAL;
return -1;
}
affinity = (uint64_t) *((int64_t*) optval_);
affinity = *((uint64_t*) optval_);
return 0;
case ZMQ_IDENTITY:
@ -139,3 +141,103 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
errno = EINVAL;
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;
}

View File

@ -32,6 +32,7 @@ namespace zmq
options_t ();
int setsockopt (int option_, const void *optval_, size_t optvallen_);
int getsockopt (int option_, void *optval_, size_t *optvallen_);
uint64_t hwm;
uint64_t lwm;

View File

@ -67,6 +67,13 @@ int zmq::socket_base_t::setsockopt (int option_, const void *optval_,
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_)
{
// Parse addr_ string.

View File

@ -47,8 +47,8 @@ namespace zmq
socket_base_t (class app_thread_t *parent_);
// Interface for communication with the API layer.
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_);
int bind (const char *addr_);
int connect (const char *addr_);
int send (zmq_msg_t *msg_, int flags_);

View File

@ -305,6 +305,12 @@ int zmq_setsockopt (void *s_, int option_, const void *optval_,
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_)
{
return (((zmq::socket_base_t*) s_)->bind (addr_));