summaryrefslogtreecommitdiff
path: root/lib/send.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-03-01 14:34:21 +0100
committerLinus Nordberg <linus@nordberg.se>2013-03-01 14:34:21 +0100
commitf3252b34114236c65624862d2a572f5e290e8cc8 (patch)
tree7a7f720b89443c1cd2dd80290ed039e10d0f7d67 /lib/send.c
parentcb9748d119ec0ebd4e8e1bbecb5ef86a65a56061 (diff)
Revamping for listeners.
Split rs_connection into rs_baseconn plus rs_connection and rs_listener. Connections now has a state variable. Connect buffer event and fd of _source_ connection, not that of conn->active_peer. The connection object referred to by a peer is not meant for using as a connection, only for reporting errors on. Make sure things are sane even when not using a config file. Bump library interface version to 1.0.0 since it's changed.
Diffstat (limited to 'lib/send.c')
-rw-r--r--lib/send.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/send.c b/lib/send.c
index 6b76958..fab89a9 100644
--- a/lib/send.c
+++ b/lib/send.c
@@ -24,12 +24,12 @@ _conn_open (struct rs_connection *conn, struct rs_message *msg)
if (event_init_eventbase (conn))
return -1;
- if (!conn->active_peer)
+ if (!conn->base_.active_peer)
peer_pick_peer (conn);
- if (!conn->active_peer)
+ if (!conn->base_.active_peer)
return rs_err_conn_push_fl (conn, RSE_NOPEER, __FILE__, __LINE__, NULL);
- if (event_init_socket (conn, conn->active_peer))
+ if (event_init_socket (conn, conn->base_.active_peer))
return -1;
if (conn->base_.realm->type == RS_CONN_TYPE_TCP
@@ -37,7 +37,7 @@ _conn_open (struct rs_connection *conn, struct rs_message *msg)
{
if (tcp_init_connect_timer (conn))
return -1;
- if (event_init_bufferevent (conn, conn->active_peer))
+ if (event_init_bufferevent (conn, conn->base_.active_peer))
return -1;
}
else
@@ -48,9 +48,9 @@ _conn_open (struct rs_connection *conn, struct rs_message *msg)
return -1;
}
- if (!conn->is_connected)
- if (!conn->is_connecting)
- event_do_connect (conn);
+ if (conn->state != RS_CONN_STATE_CONNECTED
+ && conn->state != RS_CONN_STATE_CONNECTING)
+ event_do_connect (conn);
return RSE_OK;
}
@@ -58,7 +58,8 @@ _conn_open (struct rs_connection *conn, struct rs_message *msg)
static int
_conn_is_open_p (struct rs_connection *conn)
{
- return conn->active_peer && conn->is_connected;
+ return conn->state == RS_CONN_STATE_CONNECTED
+ && conn->base_.active_peer != NULL;
}
/* User callback used when we're dispatching for user. */
@@ -92,7 +93,7 @@ rs_message_send (struct rs_message *msg, void *user_data)
assert (conn->base_.ctx);
assert (conn->base_.ctx->evb);
- assert (conn->active_peer);
+ assert (conn->base_.active_peer);
assert (conn->base_.fd >= 0);
conn->base_.user_data = user_data;