mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-29 00:32:34 +08:00
Code cleanup
This commit is contained in:
parent
fa3ae97480
commit
079ff8b759
@ -32,7 +32,7 @@ zmq::address_t::address_t (
|
||||
: protocol (protocol_),
|
||||
address (address_)
|
||||
{
|
||||
memset (&resolved, 0, sizeof (resolved));
|
||||
memset (&resolved, 0, sizeof resolved);
|
||||
}
|
||||
|
||||
zmq::address_t::~address_t ()
|
||||
@ -53,7 +53,8 @@ zmq::address_t::~address_t ()
|
||||
}
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_TIPC
|
||||
else if (protocol == "tipc") {
|
||||
else
|
||||
if (protocol == "tipc") {
|
||||
if (resolved.tipc_addr) {
|
||||
delete resolved.tipc_addr;
|
||||
resolved.tipc_addr = 0;
|
||||
@ -66,20 +67,20 @@ int zmq::address_t::to_string (std::string &addr_) const
|
||||
{
|
||||
if (protocol == "tcp") {
|
||||
if (resolved.tcp_addr)
|
||||
return resolved.tcp_addr->to_string(addr_);
|
||||
return resolved.tcp_addr->to_string (addr_);
|
||||
}
|
||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||
else
|
||||
else
|
||||
if (protocol == "ipc") {
|
||||
if (resolved.ipc_addr)
|
||||
return resolved.ipc_addr->to_string(addr_);
|
||||
return resolved.ipc_addr->to_string (addr_);
|
||||
}
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_TIPC
|
||||
else if (protocol == "tipc") {
|
||||
if (resolved.tipc_addr) {
|
||||
return resolved.tipc_addr->to_string(addr_);
|
||||
}
|
||||
else
|
||||
if (protocol == "tipc") {
|
||||
if (resolved.tipc_addr)
|
||||
return resolved.tipc_addr->to_string (addr_);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -28,17 +28,16 @@
|
||||
|
||||
zmq::ipc_address_t::ipc_address_t ()
|
||||
{
|
||||
memset (&address, 0, sizeof (address));
|
||||
memset (&address, 0, sizeof address);
|
||||
}
|
||||
|
||||
zmq::ipc_address_t::ipc_address_t (const sockaddr *sa, socklen_t sa_len)
|
||||
{
|
||||
zmq_assert(sa && sa_len > 0);
|
||||
zmq_assert (sa && sa_len > 0);
|
||||
|
||||
memset (&address, 0, sizeof (address));
|
||||
if (sa->sa_family == AF_UNIX) {
|
||||
memset (&address, 0, sizeof address);
|
||||
if (sa->sa_family == AF_UNIX)
|
||||
memcpy(&address, sa, sa_len);
|
||||
}
|
||||
}
|
||||
|
||||
zmq::ipc_address_t::~ipc_address_t ()
|
||||
@ -47,11 +46,11 @@ zmq::ipc_address_t::~ipc_address_t ()
|
||||
|
||||
int zmq::ipc_address_t::resolve (const char *path_)
|
||||
{
|
||||
if (strlen (path_) >= sizeof (address.sun_path)) {
|
||||
if (strlen (path_) >= sizeof address.sun_path) {
|
||||
errno = ENAMETOOLONG;
|
||||
return -1;
|
||||
}
|
||||
if (path_[0] == '@' && !path_[1]) {
|
||||
if (path_ [0] == '@' && !path_ [1]) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
@ -59,7 +58,7 @@ int zmq::ipc_address_t::resolve (const char *path_)
|
||||
address.sun_family = AF_UNIX;
|
||||
strcpy (address.sun_path, path_);
|
||||
/* Abstract sockets start with '\0' */
|
||||
if (path_[0] == '@')
|
||||
if (path_ [0] == '@')
|
||||
*address.sun_path = '\0';
|
||||
return 0;
|
||||
}
|
||||
@ -73,7 +72,7 @@ int zmq::ipc_address_t::to_string (std::string &addr_)
|
||||
|
||||
std::stringstream s;
|
||||
s << "ipc://";
|
||||
if (!address.sun_path[0] && address.sun_path[1])
|
||||
if (!address.sun_path [0] && address.sun_path [1])
|
||||
s << "@" << address.sun_path + 1;
|
||||
else
|
||||
s << address.sun_path;
|
||||
@ -88,9 +87,9 @@ const sockaddr *zmq::ipc_address_t::addr () const
|
||||
|
||||
socklen_t zmq::ipc_address_t::addrlen () const
|
||||
{
|
||||
if (!address.sun_path[0] && address.sun_path[1])
|
||||
return (socklen_t) strlen(address.sun_path + 1) + sizeof (sa_family_t) + 1;
|
||||
return (socklen_t) sizeof (address);
|
||||
if (!address.sun_path [0] && address.sun_path [1])
|
||||
return (socklen_t) strlen (address.sun_path + 1) + sizeof (sa_family_t) + 1;
|
||||
return (socklen_t) sizeof address;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -41,7 +41,7 @@ namespace zmq
|
||||
~ipc_address_t ();
|
||||
|
||||
// This function sets up the address for UNIX domain transport.
|
||||
int resolve (const char* path_);
|
||||
int resolve (const char *path_);
|
||||
|
||||
// The opposite to resolve()
|
||||
int to_string (std::string &addr_);
|
||||
@ -56,7 +56,7 @@ namespace zmq
|
||||
ipc_address_t (const ipc_address_t&);
|
||||
const ipc_address_t &operator = (const ipc_address_t&);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -116,7 +116,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
|
||||
(void) ipv6_;
|
||||
|
||||
// Create a socket.
|
||||
int sd = open_socket (AF_INET, SOCK_DGRAM, 0);
|
||||
const int sd = open_socket (AF_INET, SOCK_DGRAM, 0);
|
||||
errno_assert (sd != -1);
|
||||
|
||||
struct ifreq ifr;
|
||||
@ -125,7 +125,7 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
|
||||
strncpy (ifr.ifr_name, nic_, sizeof ifr.ifr_name);
|
||||
|
||||
// Fetch interface address.
|
||||
int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof (struct ifreq));
|
||||
const int rc = ioctl (sd, SIOCGIFADDR, (caddr_t) &ifr, sizeof ifr);
|
||||
|
||||
// Clean up.
|
||||
close (sd);
|
||||
|
@ -28,17 +28,16 @@
|
||||
|
||||
zmq::tipc_address_t::tipc_address_t ()
|
||||
{
|
||||
memset (&address, 0, sizeof (address));
|
||||
memset (&address, 0, sizeof address);
|
||||
}
|
||||
|
||||
zmq::tipc_address_t::tipc_address_t (const sockaddr *sa, socklen_t sa_len)
|
||||
{
|
||||
zmq_assert(sa && sa_len > 0);
|
||||
zmq_assert (sa && sa_len > 0);
|
||||
|
||||
memset (&address, 0, sizeof (address));
|
||||
if (sa->sa_family == AF_TIPC) {
|
||||
memcpy(&address, sa, sa_len);
|
||||
}
|
||||
memset (&address, 0, sizeof address);
|
||||
if (sa->sa_family == AF_TIPC)
|
||||
memcpy (&address, sa, sa_len);
|
||||
}
|
||||
|
||||
zmq::tipc_address_t::~tipc_address_t ()
|
||||
@ -47,15 +46,15 @@ zmq::tipc_address_t::~tipc_address_t ()
|
||||
|
||||
int zmq::tipc_address_t::resolve (const char *name)
|
||||
{
|
||||
int res;
|
||||
unsigned int type = 0;
|
||||
unsigned int lower = 0;
|
||||
unsigned int upper = 0;
|
||||
|
||||
res = sscanf(name, "{%u,%u,%u}", &type, &lower, &upper);
|
||||
const int res = sscanf (name, "{%u,%u,%u}", &type, &lower, &upper);
|
||||
if (res == 3)
|
||||
goto nameseq;
|
||||
else if (res == 2 && type > TIPC_RESERVED_TYPES) {
|
||||
else
|
||||
if (res == 2 && type > TIPC_RESERVED_TYPES) {
|
||||
address.family = AF_TIPC;
|
||||
address.addrtype = TIPC_ADDR_NAME;
|
||||
address.addr.name.name.type = type;
|
||||
@ -63,7 +62,7 @@ int zmq::tipc_address_t::resolve (const char *name)
|
||||
/* Since we can't specify lookup domain when connecting
|
||||
* (and we're not sure that we want it to be configurable)
|
||||
* Change from 'closest first' approach, to search entire zone */
|
||||
address.addr.name.domain = tipc_addr(1, 0, 0);
|
||||
address.addr.name.domain = tipc_addr (1, 0, 0);
|
||||
address.scope = 0;
|
||||
return 0;
|
||||
}
|
||||
@ -71,7 +70,7 @@ int zmq::tipc_address_t::resolve (const char *name)
|
||||
return EINVAL;
|
||||
nameseq:
|
||||
if (type < TIPC_RESERVED_TYPES || upper < lower)
|
||||
return EINVAL;
|
||||
return EINVAL;
|
||||
address.family = AF_TIPC;
|
||||
address.addrtype = TIPC_ADDR_NAMESEQ;
|
||||
address.addr.nameseq.type = type;
|
||||
@ -102,8 +101,7 @@ const sockaddr *zmq::tipc_address_t::addr () const
|
||||
|
||||
socklen_t zmq::tipc_address_t::addrlen () const
|
||||
{
|
||||
return (socklen_t) sizeof (address);
|
||||
return (socklen_t) sizeof address;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace zmq
|
||||
~tipc_address_t ();
|
||||
|
||||
// This function sets up the address "{type, lower, upper}" for TIPC transport
|
||||
int resolve (const char* name);
|
||||
int resolve (const char *name);
|
||||
|
||||
// The opposite to resolve()
|
||||
int to_string (std::string &addr_);
|
||||
|
Loading…
x
Reference in New Issue
Block a user