mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-14 02:57:47 +01:00
some spaces cleanups + delete unused anymore zmq::max_sockets + some minor code chages
This commit is contained in:
parent
acba6bdd6c
commit
c77dc98b5c
@ -27,11 +27,8 @@ namespace zmq
|
|||||||
|
|
||||||
// Compile-time settings.
|
// Compile-time settings.
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// Maximum number of sockets that can be opened at the same time.
|
|
||||||
max_sockets = 512,
|
|
||||||
|
|
||||||
// Number of new messages in message pipe needed to trigger new memory
|
// Number of new messages in message pipe needed to trigger new memory
|
||||||
// allocation. Setting this parameter to 256 decreases the impact of
|
// allocation. Setting this parameter to 256 decreases the impact of
|
||||||
// memory allocation by approximately 99.6%
|
// memory allocation by approximately 99.6%
|
||||||
|
11
src/ip.cpp
11
src/ip.cpp
@ -150,14 +150,14 @@ void zmq::unblock_socket (fd_t s_)
|
|||||||
int rc = ioctlsocket (s_, FIONBIO, &nonblock);
|
int rc = ioctlsocket (s_, FIONBIO, &nonblock);
|
||||||
wsa_assert (rc != SOCKET_ERROR);
|
wsa_assert (rc != SOCKET_ERROR);
|
||||||
#elif ZMQ_HAVE_OPENVMS
|
#elif ZMQ_HAVE_OPENVMS
|
||||||
int nonblock = 1;
|
int nonblock = 1;
|
||||||
int rc = ioctl (s_, FIONBIO, &nonblock);
|
int rc = ioctl (s_, FIONBIO, &nonblock);
|
||||||
errno_assert (rc != -1);
|
errno_assert (rc != -1);
|
||||||
#else
|
#else
|
||||||
int flags = fcntl (s_, F_GETFL, 0);
|
int flags = fcntl (s_, F_GETFL, 0);
|
||||||
if (flags == -1)
|
if (flags == -1)
|
||||||
flags = 0;
|
flags = 0;
|
||||||
int rc = fcntl (s_, F_SETFL, flags | O_NONBLOCK);
|
int rc = fcntl (s_, F_SETFL, flags | O_NONBLOCK);
|
||||||
errno_assert (rc != -1);
|
errno_assert (rc != -1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -179,4 +179,3 @@ void zmq::enable_ipv4_mapping (fd_t s_)
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_,
|
|||||||
}
|
}
|
||||||
rate = *((int*) optval_);
|
rate = *((int*) optval_);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZMQ_RECOVERY_IVL:
|
case ZMQ_RECOVERY_IVL:
|
||||||
if (optvallen_ != sizeof (int) || *((int*) optval_) < 0) {
|
if (optvallen_ != sizeof (int) || *((int*) optval_) < 0) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
@ -366,7 +366,7 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_)
|
|||||||
*((int*) optval_) = rate;
|
*((int*) optval_) = rate;
|
||||||
*optvallen_ = sizeof (int);
|
*optvallen_ = sizeof (int);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZMQ_RECOVERY_IVL:
|
case ZMQ_RECOVERY_IVL:
|
||||||
if (*optvallen_ < sizeof (int)) {
|
if (*optvallen_ < sizeof (int)) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
@ -50,7 +50,7 @@ namespace zmq
|
|||||||
// Socket identity
|
// Socket identity
|
||||||
unsigned char identity_size;
|
unsigned char identity_size;
|
||||||
unsigned char identity [256];
|
unsigned char identity [256];
|
||||||
|
|
||||||
// Last socket endpoint URI
|
// Last socket endpoint URI
|
||||||
std::string last_endpoint;
|
std::string last_endpoint;
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv4only_)
|
|||||||
size_t ifr_size = sizeof (struct lifreq) * ifn.lifn_count;
|
size_t ifr_size = sizeof (struct lifreq) * ifn.lifn_count;
|
||||||
char *ifr = (char*) malloc (ifr_size);
|
char *ifr = (char*) malloc (ifr_size);
|
||||||
alloc_assert (ifr);
|
alloc_assert (ifr);
|
||||||
|
|
||||||
// Retrieve interface names.
|
// Retrieve interface names.
|
||||||
lifconf ifc;
|
lifconf ifc;
|
||||||
ifc.lifc_family = AF_INET;
|
ifc.lifc_family = AF_INET;
|
||||||
@ -145,7 +145,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv4only_)
|
|||||||
memcpy (&address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr,
|
memcpy (&address.ipv4.sin_addr, &((sockaddr_in*) &ifr.ifr_addr)->sin_addr,
|
||||||
sizeof (in_addr));
|
sizeof (in_addr));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif ((defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_FREEBSD ||\
|
#elif ((defined ZMQ_HAVE_LINUX || defined ZMQ_HAVE_FREEBSD ||\
|
||||||
@ -358,9 +358,9 @@ int zmq::tcp_address_t::resolve_hostname (const char *hostname_, bool ipv4only_)
|
|||||||
// Copy first result to output addr with hostname and service.
|
// Copy first result to output addr with hostname and service.
|
||||||
zmq_assert ((size_t) (res->ai_addrlen) <= sizeof (address));
|
zmq_assert ((size_t) (res->ai_addrlen) <= sizeof (address));
|
||||||
memcpy (&address, res->ai_addr, res->ai_addrlen);
|
memcpy (&address, res->ai_addr, res->ai_addrlen);
|
||||||
|
|
||||||
freeaddrinfo (res);
|
freeaddrinfo (res);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -458,11 +458,9 @@ const int zmq::tcp_address_mask_t::mask () const
|
|||||||
|
|
||||||
int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv4only_)
|
int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv4only_)
|
||||||
{
|
{
|
||||||
std::string addr_str;
|
|
||||||
std::string mask_str;
|
|
||||||
|
|
||||||
// Find '/' at the end that separates address from the cidr mask number.
|
// Find '/' at the end that separates address from the cidr mask number.
|
||||||
// Allow empty mask clause and threat it like '/32' for ipv4 or '/128' for ipv6.
|
// Allow empty mask clause and threat it like '/32' for ipv4 or '/128' for ipv6.
|
||||||
|
std::string addr_str, mask_str;
|
||||||
const char *delimiter = strrchr (name_, '/');
|
const char *delimiter = strrchr (name_, '/');
|
||||||
if (delimiter != NULL) {
|
if (delimiter != NULL) {
|
||||||
addr_str.assign (name_, delimiter - name_);
|
addr_str.assign (name_, delimiter - name_);
|
||||||
@ -508,26 +506,26 @@ int zmq::tcp_address_mask_t::resolve (const char *name_, bool ipv4only_)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, socklen_t ss_len) const
|
const bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, const socklen_t ss_len) const
|
||||||
{
|
{
|
||||||
zmq_assert (ss != NULL && ss_len >= sizeof(struct sockaddr));
|
zmq_assert (address_mask != -1 && ss != NULL && ss_len >= sizeof(struct sockaddr));
|
||||||
|
|
||||||
if (ss->sa_family != address.generic.sa_family)
|
if (ss->sa_family != address.generic.sa_family)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (address_mask > 0) {
|
if (address_mask > 0) {
|
||||||
int mask;
|
int mask;
|
||||||
const int8_t *our_bytes, *their_bytes;
|
const uint8_t *our_bytes, *their_bytes;
|
||||||
if (ss->sa_family == AF_INET6) {
|
if (ss->sa_family == AF_INET6) {
|
||||||
zmq_assert (ss_len == sizeof (struct sockaddr_in6));
|
zmq_assert (ss_len == sizeof (struct sockaddr_in6));
|
||||||
their_bytes = (const int8_t *) &(((const struct sockaddr_in6 *) ss)->sin6_addr);
|
their_bytes = (const uint8_t *) &(((const struct sockaddr_in6 *) ss)->sin6_addr);
|
||||||
our_bytes = (const int8_t *) &address.ipv6.sin6_addr;
|
our_bytes = (const uint8_t *) &address.ipv6.sin6_addr;
|
||||||
mask = sizeof (struct in6_addr) * 8;
|
mask = sizeof (struct in6_addr) * 8;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
zmq_assert (ss_len == sizeof (struct sockaddr_in));
|
zmq_assert (ss_len == sizeof (struct sockaddr_in));
|
||||||
their_bytes = (const int8_t *) &(((const struct sockaddr_in *) ss)->sin_addr);
|
their_bytes = (const uint8_t *) &(((const struct sockaddr_in *) ss)->sin_addr);
|
||||||
our_bytes = (const int8_t *) &address.ipv4.sin_addr;
|
our_bytes = (const uint8_t *) &address.ipv4.sin_addr;
|
||||||
mask = sizeof (struct in_addr) * 8;
|
mask = sizeof (struct in_addr) * 8;
|
||||||
}
|
}
|
||||||
if (address_mask < mask) mask = address_mask;
|
if (address_mask < mask) mask = address_mask;
|
||||||
@ -538,7 +536,7 @@ const bool zmq::tcp_address_mask_t::match_address (const struct sockaddr *ss, so
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int last_byte_bits = (0xffU << (8 - (mask % 8))) & 0xffU;
|
uint8_t last_byte_bits = (0xffU << (8 - (mask % 8))) & 0xffU;
|
||||||
if (last_byte_bits) {
|
if (last_byte_bits) {
|
||||||
if ((their_bytes[full_bytes] & last_byte_bits) != (our_bytes[full_bytes] & last_byte_bits))
|
if ((their_bytes[full_bytes] & last_byte_bits) != (our_bytes[full_bytes] & last_byte_bits))
|
||||||
return false;
|
return false;
|
||||||
|
@ -81,7 +81,7 @@ namespace zmq
|
|||||||
|
|
||||||
const int mask () const;
|
const int mask () const;
|
||||||
|
|
||||||
const bool match_address (const struct sockaddr *sa, socklen_t ss_len) const;
|
const bool match_address (const struct sockaddr *ss, const socklen_t ss_len) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -257,7 +257,6 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
|
|||||||
|
|
||||||
if (!options.tcp_accept_filters.empty ()) {
|
if (!options.tcp_accept_filters.empty ()) {
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
//ss_len = 1;
|
|
||||||
for (options_t::tcp_accept_filters_t::size_type i = 0; i != options.tcp_accept_filters.size (); ++i) {
|
for (options_t::tcp_accept_filters_t::size_type i = 0; i != options.tcp_accept_filters.size (); ++i) {
|
||||||
if (options.tcp_accept_filters[i].match_address ((struct sockaddr *) &ss, ss_len)) {
|
if (options.tcp_accept_filters[i].match_address ((struct sockaddr *) &ss, ss_len)) {
|
||||||
matched = true;
|
matched = true;
|
||||||
@ -278,4 +277,3 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
|
|||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace zmq
|
|||||||
|
|
||||||
// Set address to listen on.
|
// Set address to listen on.
|
||||||
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 (std::string &addr_);
|
int get_address (std::string &addr_);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user