Skip to content

Commit

Permalink
vtcp connection string simplified
Browse files Browse the repository at this point in the history
Till now, vtcp connection contained both port and subport.
Now the port, if not specified, defaults to 9220.

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
  • Loading branch information
sustrik committed Aug 4, 2011
1 parent be48970 commit 2423051
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
28 changes: 20 additions & 8 deletions src/vtcp_connecter.cpp
Expand Up @@ -83,15 +83,27 @@ int zmq::vtcp_connecter_t::set_address (const char *addr_)
{
const char *delimiter = strrchr (addr_, '.');
if (!delimiter) {
errno = EINVAL;
return -1;
delimiter = strrchr (addr_, ':');
if (!delimiter) {
errno = EINVAL;
return -1;
}
std::string addr_str (addr_, delimiter - addr_);
addr_str += ":9220";
std::string subport_str (delimiter + 1);
subport = (vtcp_subport_t) atoi (subport_str.c_str ());
int rc = resolve_ip_hostname (&addr, &addr_len, addr_str.c_str ());
if (rc != 0)
return -1;
}
else {
std::string addr_str (addr_, delimiter - addr_);
std::string subport_str (delimiter + 1);
subport = (vtcp_subport_t) atoi (subport_str.c_str ());
int rc = resolve_ip_hostname (&addr, &addr_len, addr_str.c_str ());
if (rc != 0)
return -1;
}
std::string addr_str (addr_, delimiter - addr_);
std::string subport_str (delimiter + 1);
subport = (vtcp_subport_t) atoi (subport_str.c_str ());
int rc = resolve_ip_hostname (&addr, &addr_len, addr_str.c_str ());
if (rc != 0)
return -1;

return 0;
}
Expand Down
16 changes: 10 additions & 6 deletions src/vtcp_listener.cpp
Expand Up @@ -59,15 +59,19 @@ int zmq::vtcp_listener_t::set_address (const char *addr_)
}

// Parse port and subport.
uint16_t port;
uint32_t subport;
const char *delimiter = strrchr (addr_, '.');
if (!delimiter) {
errno = EINVAL;
return -1;
port = 9220;
subport = (uint32_t) atoi (addr_ + 2);
}
else {
std::string port_str (addr_ + 2, delimiter - addr_ - 2);
std::string subport_str (delimiter + 1);
port = (uint16_t) atoi (port_str.c_str ());
subport = (uint32_t) atoi (subport_str.c_str ());
}
std::string port_str (addr_ + 2, delimiter - addr_ - 2);
std::string subport_str (delimiter + 1);
uint16_t port = (uint16_t) atoi (port_str.c_str ());
uint32_t subport = (uint32_t) atoi (subport_str.c_str ());

// Start listening.
s = vtcp_bind (port, subport);
Expand Down

0 comments on commit 2423051

Please sign in to comment.