tport: added TPTAG_TOS()

darcs-hash:20061207003355-8fcfa-e9a956858ce8162313812664271dbcb133c59214.gz
parent 74b81da2
......@@ -258,6 +258,13 @@ TPORT_DLL extern tag_typedef_t tptag_stun_server;
TPORT_DLL extern tag_typedef_t tptag_stun_server_ref;
#define TPTAG_STUN_SERVER_REF(x) tptag_stun_server_ref, tag_bool_vr(&(x))
TPORT_DLL extern tag_typedef_t tptag_tos;
/** Sets the IP TOS for the socket. */
#define TPTAG_TOS(x) tptag_tos, tag_int_v((x))
TPORT_DLL extern tag_typedef_t tptag_tos_ref;
#define TPTAG_TOS_REF(x) tptag_tos_ref, tag_int_vr(&(x))
SOFIA_END_DECLS
#endif /* !defined TPORT_TAG_H */
......@@ -303,6 +303,17 @@ int tport_has_sigcomp(tport_t const *self)
return self->tp_name->tpn_comp != NULL;
}
/** Set IP TOS for socket */
void tport_set_tos(su_socket_t socket, su_addrinfo_t *ai, int tos)
{
if (tos >= 0 &&
ai->ai_family == AF_INET &&
setsockopt(socket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
SU_DEBUG_3(("tport: setsockopt(IP_TOS): %s\n",
su_strerror(su_errno())));
}
}
static
tport_t *tport_connect(tport_primary_t *pri, su_addrinfo_t *ai,
tp_name_t const *tpn);
......@@ -455,6 +466,7 @@ tport_t *tport_tcreate(tp_stack_t *stack,
tpp->tpp_timeout = UINT_MAX;
tpp->tpp_sigcomp_lifetime = UINT_MAX;
tpp->tpp_stun_server = 1;
tpp->tpp_tos = -1; /* set invalid, valid values are 0-255 */
tpn = mr->mr_master->tp_name;
tpn->tpn_proto = "*";
......@@ -824,6 +836,11 @@ tport_t *tport_alloc_secondary(tport_primary_t *pri,
su_home_zap(self->tp_home);
return NULL;
}
/* Set IP TOS if it is set in primary */
tport_set_tos(socket,
pri->pri_primary->tp_addrinfo,
pri->pri_params->tpp_tos);
}
else {
su_close(socket);
......@@ -1099,6 +1116,7 @@ int tport_get_params(tport_t const *self,
TPTAG_THRPSIZE(tpp->tpp_thrpsize),
TPTAG_THRPRQSIZE(tpp->tpp_thrprqsize),
TAG_IF(pri, TPTAG_PUBLIC(pri ? pri->pri_public : 0)),
TPTAG_TOS(tpp->tpp_tos),
TAG_END());
ta_end(ta);
......@@ -1148,6 +1166,7 @@ int tport_set_params(tport_t *self,
TPTAG_REUSE_REF(reusable),
TPTAG_COMPARTMENT_REF(cc),
TPTAG_STUN_SERVER_REF(stun_server),
TPTAG_TOS_REF(tpp->tpp_tos),
TAG_END());
ta_end(ta);
......
......@@ -101,6 +101,7 @@ typedef struct {
unsigned tpp_qsize; /**< Size of queue */
unsigned tpp_drop; /**< Packet drop probablity */
int tpp_tos; /**< IP TOS */
unsigned tpp_conn_orient:1; /**< Connection-orienteded */
unsigned tpp_sdwn_error:1; /**< If true, shutdown is error. */
......@@ -365,6 +366,8 @@ int tport_primary_compression(tport_primary_t *pri,
char const *compression,
tagi_t const *tl);
void tport_set_tos(su_socket_t socket, su_addrinfo_t *ai, int tos);
tport_t *tport_base_connect(tport_primary_t *pri,
su_addrinfo_t *ai,
su_addrinfo_t *name,
......
......@@ -77,3 +77,4 @@ tag_typedef_t tptag_thrpsize = UINTTAG_TYPEDEF(thrpsize);
tag_typedef_t tptag_thrprqsize = UINTTAG_TYPEDEF(thrprqsize);
tag_typedef_t tptag_http_connect = STRTAG_TYPEDEF(http_connect);
tag_typedef_t tptag_stun_server = BOOLTAG_TYPEDEF(stun_server);
tag_typedef_t tptag_tos = INTTAG_TYPEDEF(tos);
......@@ -125,6 +125,9 @@ int tport_stream_init_primary(tport_primary_t *pri,
{
pri->pri_primary->tp_socket = socket;
/* Set IP TOS if set */
tport_set_tos(socket, ai, pri->pri_params->tpp_tos);
#if defined(__linux__)
/* Linux does not allow reusing TCP port while this one is open,
so we can safely call su_setreuseaddr() before bind(). */
......
......@@ -115,6 +115,8 @@ int tport_udp_init_primary(tport_primary_t *pri,
if (tport_bind_socket(s, ai, return_culprit) < 0)
return -1;
tport_set_tos(s, ai, pri->pri_params->tpp_tos);
#if HAVE_IP_RECVERR
if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) {
int const one = 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