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);
#define ZMQ_DONTWAIT 1
#define ZMQ_SNDMORE 2
/* Wildcard endpoint support. */
#define ZMQ_ENDPOINT_MAX 256
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,
......
......@@ -95,7 +95,7 @@ void zmq::ipc_listener_t::in_event ()
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;
int rc;
......@@ -106,8 +106,9 @@ int zmq::ipc_listener_t::get_address (unsigned char *addr, size_t *len)
if (rc != 0) {
return rc;
}
// 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;
}
......
......@@ -50,7 +50,7 @@ namespace zmq
int set_address (const char *addr_);
// Get the bound address for use with wildcards
int get_address(unsigned char *addr, size_t *len);
int get_address(std::string *addr_);
private:
......
......@@ -30,7 +30,6 @@ zmq::options_t::options_t () :
rcvhwm (1000),
affinity (0),
identity_size (0),
last_endpoint_size(0),
rate (100),
recovery_ivl (10000),
multicast_hops (1),
......@@ -387,12 +386,13 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
return 0;
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;
return -1;
}
memcpy (optval_, last_endpoint, last_endpoint_size);
*optvallen_ = last_endpoint_size;
memcpy (optval_, last_endpoint.c_str(), last_endpoint.size()+1);
*optvallen_ = last_endpoint.size()+1;
return 0;
}
......
......@@ -23,6 +23,8 @@
#ifndef __ZMQ_OPTIONS_HPP_INCLUDED__
#define __ZMQ_OPTIONS_HPP_INCLUDED__
#include <string>
#include "stddef.h"
#include "stdint.hpp"
......@@ -48,8 +50,7 @@ namespace zmq
unsigned char identity [256];
// Last socket endpoint URI
unsigned char last_endpoint [256];
size_t last_endpoint_size;
std::string last_endpoint;
// Maximum tranfer rate [kb/s]. Default 100kb/s.
int rate;
......
......@@ -342,7 +342,7 @@ int zmq::socket_base_t::bind (const char *addr_)
return -1;
}
rc = listener->get_address (options.last_endpoint, &(options.last_endpoint_size));
rc = listener->get_address (&options.last_endpoint);
launch_child (listener);
return 0;
}
......@@ -357,7 +357,8 @@ int zmq::socket_base_t::bind (const char *addr_)
delete listener;
return -1;
}
rc = listener->get_address (options.last_endpoint, &(options.last_endpoint_size));
rc = listener->get_address (&options.last_endpoint);
launch_child (listener);
return 0;
}
......
......@@ -22,6 +22,7 @@
#include <new>
#include <string.h>
#include <sstream>
#include "platform.hpp"
#include "tcp_listener.hpp"
......@@ -119,11 +120,12 @@ void zmq::tcp_listener_t::close ()
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;
char host[INET6_ADDRSTRLEN];
int port, rc;
std::stringstream portnum;
// Get the details of the TCP socket
socklen_t sl = sizeof(sockaddr);
......@@ -136,15 +138,17 @@ int zmq::tcp_listener_t::get_address (unsigned char *addr, size_t *len)
if ( sa.sa_family == AF_INET ) {
inet_ntop(AF_INET, &(((struct sockaddr_in *)&sa)->sin_addr), host, INET6_ADDRSTRLEN);
port = ntohs( ((struct sockaddr_in *)&sa)->sin_port);
portnum << port;
// 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 {
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)&sa)->sin6_addr), host, INET6_ADDRSTRLEN);
port = ntohs( ((struct sockaddr_in6 *)&sa)->sin6_port);
portnum << port;
// 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;
......
......@@ -46,7 +46,7 @@ namespace zmq
int set_address (const char *addr_);
// Get the bound address for use with wildcard
int get_address(unsigned char *addr, size_t *len);
int get_address(std::string *addr_);
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