Commit 2c395ec6 authored by Pekka Pessi's avatar Pekka Pessi

tport.h, tport.c: added new attribute tport_is_connected()

If tport_is_connected() return true if connection-oriented transport has an
established connection.

darcs-hash:20061205163213-65a35-5b6eae0241438515046e4fdd2cc510e8e2480621.gz
parent 32455cce
......@@ -276,6 +276,9 @@ TPORT_DLL int tport_is_closed(tport_t const *self);
/** Test if transport has been shut down (added to @VERSION_1_12_4 ) */
TPORT_DLL int tport_is_shutdown(tport_t const *self);
/** Test if transport is connected. @NEW_1_12_5 */
TPORT_DLL int tport_is_connected(tport_t const *self);
/** Set transport magic. */
TPORT_DLL void tport_set_magic(tport_t *self, tp_magic_t *magic);
......
......@@ -285,6 +285,12 @@ static inline int tport_is_bound(tport_t const *self)
return self->tp_protoname != NULL;
}
/** Test if transport connection has been established. @NEW_1_12_5 */
inline int tport_is_connected(tport_t const *self)
{
return self->tp_is_connected;
}
/** MTU for transport */
static inline unsigned tport_mtu(tport_t const *self)
{
......@@ -680,7 +686,7 @@ tport_primary_t *tport_listen(tport_master_t *mr,
tp->tp_index = index;
}
pri->pri_primary->tp_connected = 0;
pri->pri_primary->tp_has_connection = 0;
SU_DEBUG_5(("%s(%p): %s " TPN_FORMAT "\n",
__func__, pri, "listening at",
......@@ -941,6 +947,7 @@ tport_t *tport_base_connect(tport_primary_t *pri,
}
else {
what = "connected";
self->tp_is_connected = 1;
}
if (su_wait_create(wait, s, self->tp_events = events) == -1)
......@@ -2305,7 +2312,7 @@ void tport_error_report(tport_t *self, int errcode,
addr = NULL;
/* Mark this connection as unusable */
if (errcode > 0 && tport_is_connected(self))
if (errcode > 0 && tport_has_connection(self))
self->tp_reusable = 0;
if (addr == NULL && tport_is_connection_oriented(self))
......@@ -2333,7 +2340,7 @@ void tport_error_report(tport_t *self, int errcode,
}
/* Close connection */
if (!self->tp_closed && errcode > 0 && tport_is_connected(self))
if (!self->tp_closed && errcode > 0 && tport_has_connection(self))
tport_close(self);
}
......@@ -2389,6 +2396,7 @@ int tport_accept(tport_primary_t *pri, int events)
self->tp_index = i;
self->tp_conn_orient = 1;
self->tp_is_connected = 1;
self->tp_events = events;
if (tport_setname(self, pri->pri_protoname, ai, NULL) != -1) {
......@@ -2468,6 +2476,8 @@ static int tport_connected(su_root_magic_t *magic, su_wait_t *w, tport_t *self)
return 0;
}
self->tp_is_connected = 1;
su_root_deregister(mr->mr_root, self->tp_index);
self->tp_index = -1;
self->tp_events = SU_WAIT_IN | SU_WAIT_ERR;
......@@ -2628,7 +2638,7 @@ void tport_recv_event(tport_t *self)
if (!su_is_blocking(error)) {
tport_error_report(self, error, NULL);
/* Failure: shutdown socket */
if (tport_is_connected(self))
if (tport_has_connection(self))
tport_close(self);
return;
}
......@@ -3321,7 +3331,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
if (tport_is_connection_oriented(self)) {
tport_error_report(self, error, NULL);
if (tport_is_connected(self))
if (tport_has_connection(self))
tport_close(self);
}
......
......@@ -127,7 +127,7 @@ struct tport_s {
unsigned tp_accepted:1; /**< Originally server? */
unsigned tp_conn_orient:1; /**< Is connection-oriented */
unsigned tp_connected : 1; /**< Has real connection */
unsigned tp_has_connection:1; /**< Has real connection */
unsigned tp_reusable:1; /**< Can this connection be reused */
unsigned tp_closed : 1; /**< This transport is closed */
/**< Remote end has sent FIN (2) or we should not just read */
......@@ -137,6 +137,7 @@ struct tport_s {
unsigned tp_has_keepalive:1;
unsigned tp_has_stun_server:1;
unsigned tp_trunc:1;
unsigned tp_is_connected:1; /**< Connection is established */
unsigned:0;
tport_t *tp_left, *tp_right, *tp_dad; /**< Links in tport tree */
......@@ -352,10 +353,10 @@ static inline int tport_is_connection_oriented(tport_t const *self)
return self->tp_conn_orient;
}
/** Test if transport has actual connection. */
static inline int tport_is_connected(tport_t const *self)
/** Test if transport involves connection. @NEW_1_12_5 */
static inline int tport_has_connection(tport_t const *self)
{
return self->tp_connected;
return self->tp_has_connection;
}
void tport_has_been_updated(tport_t *tport);
......
......@@ -172,7 +172,7 @@ static int tport_sctp_init_client(tport_primary_t *pri,
static int tport_sctp_init_secondary(tport_t *self, int socket, int accepted,
char const **return_reason)
{
self->tp_connected = 1;
self->tp_has_connection = 1;
if (su_setblocking(socket, 0) < 0)
return *return_reason = "su_setblocking", -1;
......
......@@ -168,7 +168,7 @@ int tport_tcp_init_secondary(tport_t *self, int socket, int accepted,
{
int one = 1;
self->tp_connected = 1;
self->tp_has_connection = 1;
if (setsockopt(socket, SOL_TCP, TCP_NODELAY, (void *)&one, sizeof one) == -1)
return *return_reason = "TCP_NODELAY", -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment