Commit b5d33739 authored by Ian Barber's avatar Ian Barber

Moving to std::string in options

parent 770f8433
...@@ -203,9 +203,6 @@ ZMQ_EXPORT int zmq_term (void *context); ...@@ -203,9 +203,6 @@ ZMQ_EXPORT int zmq_term (void *context);
#define ZMQ_DONTWAIT 1 #define ZMQ_DONTWAIT 1
#define ZMQ_SNDMORE 2 #define ZMQ_SNDMORE 2
/* Wildcard endpoint support. */
#define ZMQ_ENDPOINT_MAX 256
ZMQ_EXPORT void *zmq_socket (void *context, int type); 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,
......
...@@ -95,7 +95,7 @@ void zmq::ipc_listener_t::in_event () ...@@ -95,7 +95,7 @@ void zmq::ipc_listener_t::in_event ()
send_attach (session, engine, false); send_attach (session, engine, false);
} }
int zmq::ipc_listener_t::get_address (unsigned char *addr, size_t *len) int zmq::ipc_listener_t::get_address (std::string *addr_)
{ {
struct sockaddr_un sun; struct sockaddr_un sun;
int rc; int rc;
...@@ -106,8 +106,9 @@ int zmq::ipc_listener_t::get_address (unsigned char *addr, size_t *len) ...@@ -106,8 +106,9 @@ int zmq::ipc_listener_t::get_address (unsigned char *addr, size_t *len)
if (rc != 0) { if (rc != 0) {
return rc; return rc;
} }
// Store the address for retrieval by users using wildcards // Store the address for retrieval by users using wildcards
*len = sprintf((char *)addr, "ipc://%s", sun.sun_path); *addr_ = std::string("ipc://") + std::string(sun.sun_path);
return 0; return 0;
} }
......
...@@ -50,7 +50,7 @@ namespace zmq ...@@ -50,7 +50,7 @@ namespace zmq
int set_address (const char *addr_); int set_address (const char *addr_);
// Get the bound address for use with wildcards // Get the bound address for use with wildcards
int get_address(unsigned char *addr, size_t *len); int get_address(std::string *addr_);
private: private:
......
...@@ -30,7 +30,6 @@ zmq::options_t::options_t () : ...@@ -30,7 +30,6 @@ zmq::options_t::options_t () :
rcvhwm (1000), rcvhwm (1000),
affinity (0), affinity (0),
identity_size (0), identity_size (0),
last_endpoint_size(0),
rate (100), rate (100),
recovery_ivl (10000), recovery_ivl (10000),
multicast_hops (1), multicast_hops (1),
...@@ -387,12 +386,13 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) ...@@ -387,12 +386,13 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
return 0; return 0;
case ZMQ_LAST_ENDPOINT: case ZMQ_LAST_ENDPOINT:
if (*optvallen_ < last_endpoint_size) { // don't allow string which cannot contain the entire message
if (*optvallen_ < last_endpoint.size() + 1) {
errno = EINVAL; errno = EINVAL;
return -1; return -1;
} }
memcpy (optval_, last_endpoint, last_endpoint_size); memcpy (optval_, last_endpoint.c_str(), last_endpoint.size()+1);
*optvallen_ = last_endpoint_size; *optvallen_ = last_endpoint.size()+1;
return 0; return 0;
} }
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#ifndef __ZMQ_OPTIONS_HPP_INCLUDED__ #ifndef __ZMQ_OPTIONS_HPP_INCLUDED__
#define __ZMQ_OPTIONS_HPP_INCLUDED__ #define __ZMQ_OPTIONS_HPP_INCLUDED__
#include <string>
#include "stddef.h" #include "stddef.h"
#include "stdint.hpp" #include "stdint.hpp"
...@@ -48,8 +50,7 @@ namespace zmq ...@@ -48,8 +50,7 @@ namespace zmq
unsigned char identity [256]; unsigned char identity [256];
// Last socket endpoint URI // Last socket endpoint URI
unsigned char last_endpoint [256]; std::string last_endpoint;
size_t last_endpoint_size;
// Maximum tranfer rate [kb/s]. Default 100kb/s. // Maximum tranfer rate [kb/s]. Default 100kb/s.
int rate; int rate;
......
...@@ -342,7 +342,7 @@ int zmq::socket_base_t::bind (const char *addr_) ...@@ -342,7 +342,7 @@ int zmq::socket_base_t::bind (const char *addr_)
return -1; return -1;
} }
rc = listener->get_address (options.last_endpoint, &(options.last_endpoint_size)); rc = listener->get_address (&options.last_endpoint);
launch_child (listener); launch_child (listener);
return 0; return 0;
} }
...@@ -357,7 +357,8 @@ int zmq::socket_base_t::bind (const char *addr_) ...@@ -357,7 +357,8 @@ int zmq::socket_base_t::bind (const char *addr_)
delete listener; delete listener;
return -1; return -1;
} }
rc = listener->get_address (options.last_endpoint, &(options.last_endpoint_size));
rc = listener->get_address (&options.last_endpoint);
launch_child (listener); launch_child (listener);
return 0; return 0;
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <new> #include <new>
#include <string.h> #include <string.h>
#include <sstream>
#include "platform.hpp" #include "platform.hpp"
#include "tcp_listener.hpp" #include "tcp_listener.hpp"
...@@ -119,11 +120,12 @@ void zmq::tcp_listener_t::close () ...@@ -119,11 +120,12 @@ void zmq::tcp_listener_t::close ()
s = retired_fd; s = retired_fd;
} }
int zmq::tcp_listener_t::get_address (unsigned char *addr, size_t *len) int zmq::tcp_listener_t::get_address (std::string *addr_)
{ {
struct sockaddr sa; struct sockaddr sa;
char host[INET6_ADDRSTRLEN]; char host[INET6_ADDRSTRLEN];
int port, rc; int port, rc;
std::stringstream portnum;
// Get the details of the TCP socket // Get the details of the TCP socket
socklen_t sl = sizeof(sockaddr); socklen_t sl = sizeof(sockaddr);
...@@ -136,15 +138,17 @@ int zmq::tcp_listener_t::get_address (unsigned char *addr, size_t *len) ...@@ -136,15 +138,17 @@ int zmq::tcp_listener_t::get_address (unsigned char *addr, size_t *len)
if ( sa.sa_family == AF_INET ) { if ( sa.sa_family == AF_INET ) {
inet_ntop(AF_INET, &(((struct sockaddr_in *)&sa)->sin_addr), host, INET6_ADDRSTRLEN); inet_ntop(AF_INET, &(((struct sockaddr_in *)&sa)->sin_addr), host, INET6_ADDRSTRLEN);
port = ntohs( ((struct sockaddr_in *)&sa)->sin_port); port = ntohs( ((struct sockaddr_in *)&sa)->sin_port);
portnum << port;
// Store the address for retrieval by users using wildcards // Store the address for retrieval by users using wildcards
*len = sprintf((char *)addr, "tcp://%s:%d", host, port); *addr_ = std::string("tcp://") + std::string(host) + std::string(":") + portnum.str();
} else { } else {
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)&sa)->sin6_addr), host, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)&sa)->sin6_addr), host, INET6_ADDRSTRLEN);
port = ntohs( ((struct sockaddr_in6 *)&sa)->sin6_port); port = ntohs( ((struct sockaddr_in6 *)&sa)->sin6_port);
portnum << port;
// Store the address for retrieval by users using wildcards // Store the address for retrieval by users using wildcards
*len = sprintf((char *)*addr, "tcp://[%s]:%d", host, port); *addr_ = std::string("tcp://[") + std::string(host) + std::string("]:") + portnum.str();
} }
return 0; return 0;
......
...@@ -46,7 +46,7 @@ namespace zmq ...@@ -46,7 +46,7 @@ namespace zmq
int set_address (const char *addr_); int set_address (const char *addr_);
// Get the bound address for use with wildcard // Get the bound address for use with wildcard
int get_address(unsigned char *addr, size_t *len); int get_address(std::string *addr_);
private: private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment