summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/xs_bind.txt2
-rw-r--r--doc/xs_connect.txt2
-rw-r--r--src/ipc_connecter.cpp6
-rw-r--r--src/ipc_connecter.hpp8
-rw-r--r--src/session_base.cpp8
-rw-r--r--src/socket_base.cpp17
-rw-r--r--src/tcp_connecter.cpp7
-rw-r--r--src/tcp_connecter.hpp8
8 files changed, 37 insertions, 21 deletions
diff --git a/doc/xs_bind.txt b/doc/xs_bind.txt
index 3472f04..c6f472c 100644
--- a/doc/xs_bind.txt
+++ b/doc/xs_bind.txt
@@ -46,6 +46,8 @@ ERRORS
------
*EINVAL*::
The endpoint supplied is invalid.
+*ENAMETOOLONG*::
+The supplied name was too long.
*EPROTONOSUPPORT*::
The requested 'transport' protocol is not supported.
*ENOCOMPATPROTO*::
diff --git a/doc/xs_connect.txt b/doc/xs_connect.txt
index 02597da..00625d3 100644
--- a/doc/xs_connect.txt
+++ b/doc/xs_connect.txt
@@ -50,6 +50,8 @@ ERRORS
------
*EINVAL*::
The endpoint supplied is invalid.
+*ENAMETOOLONG*::
+The supplied name was too long.
*EPROTONOSUPPORT*::
The requested 'transport' protocol is not supported.
*ENOCOMPATPROTO*::
diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp
index 0722532..f620fd1 100644
--- a/src/ipc_connecter.cpp
+++ b/src/ipc_connecter.cpp
@@ -39,7 +39,7 @@
xs::ipc_connecter_t::ipc_connecter_t (class io_thread_t *io_thread_,
class session_base_t *session_, const options_t &options_,
- const char *address_, bool wait_) :
+ bool wait_) :
own_t (io_thread_, options_),
io_object_t (io_thread_),
s (retired_fd),
@@ -49,10 +49,6 @@ xs::ipc_connecter_t::ipc_connecter_t (class io_thread_t *io_thread_,
current_reconnect_ivl(options.reconnect_ivl),
reconnect_timer (NULL)
{
- // TODO: set_addess should be called separately, so that the error
- // can be propagated.
- int rc = set_address (address_);
- xs_assert (rc == 0);
}
xs::ipc_connecter_t::~ipc_connecter_t ()
diff --git a/src/ipc_connecter.hpp b/src/ipc_connecter.hpp
index e6c419d..a642266 100644
--- a/src/ipc_connecter.hpp
+++ b/src/ipc_connecter.hpp
@@ -45,9 +45,12 @@ namespace xs
// connection process.
ipc_connecter_t (xs::io_thread_t *io_thread_,
xs::session_base_t *session_, const options_t &options_,
- const char *address_, bool delay_);
+ bool delay_);
~ipc_connecter_t ();
+ // Set address to connect to.
+ int set_address (const char *addr_);
+
private:
// ID of the timer used to delay the reconnection.
@@ -72,9 +75,6 @@ namespace xs
// Returns the currently used interval
int get_new_reconnect_ivl ();
- // Set address to connect to.
- int set_address (const char *addr_);
-
// Open IPC connecting socket. Returns -1 in case of error,
// 0 if connect was successfull immediately. Returns -1 with
// EAGAIN errno if async connect was launched.
diff --git a/src/session_base.cpp b/src/session_base.cpp
index 35c4a4e..48d8811 100644
--- a/src/session_base.cpp
+++ b/src/session_base.cpp
@@ -422,8 +422,10 @@ void xs::session_base_t::start_connecting (bool wait_)
if (protocol == "tcp") {
tcp_connecter_t *connecter = new (std::nothrow) tcp_connecter_t (
- thread, this, options, address.c_str (), wait_);
+ thread, this, options, wait_);
alloc_assert (connecter);
+ int rc = connecter->set_address (address.c_str());
+ errno_assert (rc == 0);
launch_child (connecter);
return;
}
@@ -431,8 +433,10 @@ void xs::session_base_t::start_connecting (bool wait_)
#if !defined XS_HAVE_WINDOWS && !defined XS_HAVE_OPENVMS
if (protocol == "ipc") {
ipc_connecter_t *connecter = new (std::nothrow) ipc_connecter_t (
- thread, this, options, address.c_str (), wait_);
+ thread, this, options, wait_);
alloc_assert (connecter);
+ int rc = connecter->set_address (address.c_str());
+ errno_assert (rc == 0);
launch_child (connecter);
return;
}
diff --git a/src/socket_base.cpp b/src/socket_base.cpp
index ec5c8bd..8ee8bd3 100644
--- a/src/socket_base.cpp
+++ b/src/socket_base.cpp
@@ -39,6 +39,7 @@
#include "tcp_listener.hpp"
#include "ipc_listener.hpp"
#include "tcp_connecter.hpp"
+#include "ipc_connecter.hpp"
#include "io_thread.hpp"
#include "session_base.hpp"
#include "config.hpp"
@@ -491,6 +492,22 @@ int xs::socket_base_t::connect (const char *addr_)
io_thread_t *thread = choose_io_thread (options.affinity);
xs_assert (thread);
+ if (protocol == "tcp") {
+ tcp_connecter_t connecter (thread, NULL, options, false);
+ int rc = connecter.set_address (address.c_str());
+ if (rc != 0) {
+ return -1;
+ }
+ }
+
+ if (protocol == "ipc") {
+ ipc_connecter_t connecter (thread, NULL, options, false);
+ int rc = connecter.set_address (address.c_str());
+ if (rc != 0) {
+ return -1;
+ }
+ }
+
// Create session.
session_base_t *session = session_base_t::create (thread, true, this,
options, protocol.c_str (), address.c_str ());
diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp
index 5ae01e7..c605b8f 100644
--- a/src/tcp_connecter.cpp
+++ b/src/tcp_connecter.cpp
@@ -47,8 +47,7 @@
#endif
xs::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_,
- class session_base_t *session_, const options_t &options_,
- const char *address_, bool wait_) :
+ class session_base_t *session_, const options_t &options_, bool wait_) :
own_t (io_thread_, options_),
io_object_t (io_thread_),
s (retired_fd),
@@ -58,10 +57,6 @@ xs::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_,
current_reconnect_ivl(options.reconnect_ivl),
reconnect_timer (NULL)
{
- // TODO: set_addess should be called separately, so that the error
- // can be propagated.
- int rc = set_address (address_);
- errno_assert (rc == 0);
}
xs::tcp_connecter_t::~tcp_connecter_t ()
diff --git a/src/tcp_connecter.hpp b/src/tcp_connecter.hpp
index 26a0151..ee8f381 100644
--- a/src/tcp_connecter.hpp
+++ b/src/tcp_connecter.hpp
@@ -42,9 +42,12 @@ namespace xs
// connection process.
tcp_connecter_t (xs::io_thread_t *io_thread_,
xs::session_base_t *session_, const options_t &options_,
- const char *address_, bool delay_);
+ bool delay_);
~tcp_connecter_t ();
+ // Set address to connect to.
+ int set_address (const char *addr_);
+
private:
// Handlers for incoming commands.
@@ -66,9 +69,6 @@ namespace xs
// Returns the currently used interval
int get_new_reconnect_ivl ();
- // Set address to connect to.
- int set_address (const char *addr_);
-
// Open TCP connecting socket. Returns -1 in case of error,
// 0 if connect was successfull immediately. Returns -1 with
// EAGAIN errno if async connect was launched.