From 6996ef6f1a0a50a754608df9444e425d0900b143 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Sat, 29 Aug 2009 09:41:50 +0200 Subject: improved error handling --- src/ip.cpp | 3 ++- src/tcp_listener.cpp | 9 ++++----- src/tcp_listener.hpp | 5 +---- src/zmq_listener.cpp | 4 ---- 4 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ip.cpp b/src/ip.cpp index 05a267e..0d14fcf 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -285,7 +285,8 @@ int zmq::resolve_ip_hostname (sockaddr_in *addr_, const char *hostname_) // Separate the hostname. std::string hostname (hostname_, delimiter - hostname_); - // Resolve host name. + // Resolve host name. Some of the error info is lost in case of error, + // however, there's no way to report EAI errors via errno. addrinfo req; memset (&req, 0, sizeof (req)); req.ai_family = AF_INET; diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 937618d..de62879 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -55,11 +55,10 @@ zmq::tcp_listener_t::~tcp_listener_t () int zmq::tcp_listener_t::set_address (const char *addr_) { // Convert the interface into sockaddr_in structure. - return resolve_ip_interface (&addr, addr_); -} + int rc = resolve_ip_interface (&addr, addr_); + if (rc != 0) + return rc; -int zmq::tcp_listener_t::open () -{ // Create a listening socket. s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) @@ -67,7 +66,7 @@ int zmq::tcp_listener_t::open () // Allow reusing of the address. int flag = 1; - int rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)); + rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int)); errno_assert (rc == 0); // Set the non-blocking flag. diff --git a/src/tcp_listener.hpp b/src/tcp_listener.hpp index 2a8bc23..62498dc 100644 --- a/src/tcp_listener.hpp +++ b/src/tcp_listener.hpp @@ -35,14 +35,11 @@ namespace zmq tcp_listener_t (); ~tcp_listener_t (); - // Set up the address to listen on. Address is in + // Start listening on the interface. Address is in // : format. Interface name may be '*' // to bind to all the interfaces. int set_address (const char *addr_); - // Open TCP listining socket. - int open (); - // Close the listening socket. int close (); diff --git a/src/zmq_listener.cpp b/src/zmq_listener.cpp index 97164c1..35e4428 100644 --- a/src/zmq_listener.cpp +++ b/src/zmq_listener.cpp @@ -41,10 +41,6 @@ int zmq::zmq_listener_t::set_address (const char *addr_) void zmq::zmq_listener_t::process_plug () { - // Open the listening socket. - int rc = tcp_listener.open (); - zmq_assert (rc == 0); - // Start polling for incoming connections. handle = add_fd (tcp_listener.get_fd ()); set_pollin (handle); -- cgit v1.2.3