Commit b4be5fe2 authored by Simon Morlat's avatar Simon Morlat

implement dscp settings

parent 8d901812
......@@ -86,9 +86,20 @@ BELLESIP_EXPORT int belle_sip_stack_get_inactive_transport_timeout(const belle_s
**/
BELLESIP_EXPORT void belle_sip_stack_set_inactive_transport_timeout(belle_sip_stack_t *stack, int seconds);
void belle_sip_stack_push_pool(belle_sip_stack_t *stack);
void belle_sip_stack_pop_pool(belle_sip_stack_t *stack);
/**
* Set the default dscp value to be used for all SIP sockets created and used in the stack.
**/
BELLESIP_EXPORT void belle_sip_stack_set_default_dscp(belle_sip_stack_t *stack, int dscp);
/**
* Get the default dscp value to be used for all SIP sockets created and used in the stack.
**/
BELLESIP_EXPORT int belle_sip_stack_get_default_dscp(belle_sip_stack_t *stack);
BELLESIP_EXPORT void belle_sip_stack_push_pool(belle_sip_stack_t *stack);
BELLESIP_EXPORT void belle_sip_stack_pop_pool(belle_sip_stack_t *stack);
BELLE_SIP_END_DECLS
......
......@@ -478,6 +478,7 @@ struct belle_sip_stack{
int send_error; /* used to simulate network error. if <0, channel_send will return this value*/
int resolver_tx_delay; /*used to simulate network transmission delay, for tests*/
int resolver_send_error; /* used to simulate network error*/
int dscp;
};
belle_sip_hop_t* belle_sip_hop_new(const char* transport, const char *cname, const char* host,int port);
......
......@@ -53,6 +53,11 @@ int belle_sip_socket_set_nonblocking (belle_sip_socket_t sock)
return ioctlsocket(sock, FIONBIO , &nonBlock);
}
int belle_sip_socket_set_dscp(belle_sip_socket_t sock, int ai_family, int dscp){
belle_sip_warning("belle_sip_socket_set_dscp(): not implemented.");
return -1;
}
const char *belle_sip_get_socket_error_string(){
return belle_sip_get_socket_error_string_from_code(WSAGetLastError());
}
......@@ -116,6 +121,36 @@ int belle_sip_socket_set_nonblocking(belle_sip_socket_t sock){
return fcntl (sock, F_SETFL, fcntl(sock,F_GETFL) | O_NONBLOCK);
}
int belle_sip_socket_set_dscp(belle_sip_socket_t sock, int ai_family, int dscp){
int tos;
int proto;
int value_type;
int retval;
tos = (dscp << 2) & 0xFC;
switch (ai_family) {
case AF_INET:
proto=IPPROTO_IP;
value_type=IP_TOS;
break;
case AF_INET6:
proto=IPPROTO_IPV6;
#ifdef IPV6_TCLASS /*seems not defined by my libc*/
value_type=IPV6_TCLASS;
#else
value_type=IP_TOS;
#endif
break;
default:
belle_sip_error("Cannot set DSCP because socket family is unspecified.");
return -1;
}
retval = setsockopt(sock, proto, value_type, (const char*)&tos, sizeof(tos));
if (retval==-1)
belle_sip_error("Fail to set DSCP value on socket: %s",belle_sip_get_socket_error_string());
return retval;
}
#endif
......
......@@ -70,6 +70,7 @@ typedef unsigned char uint8_t;
BELLESIP_INTERNAL_EXPORT int belle_sip_init_sockets(void);
BELLESIP_INTERNAL_EXPORT void belle_sip_uninit_sockets(void);
int belle_sip_socket_set_nonblocking (belle_sip_socket_t sock);
int belle_sip_socket_set_dscp(belle_sip_socket_t sock, int ai_family, int dscp);
#if defined(WIN32)
......
......@@ -183,3 +183,12 @@ int belle_sip_stack_get_inactive_transport_timeout(const belle_sip_stack_t *stac
void belle_sip_stack_set_inactive_transport_timeout(belle_sip_stack_t *stack, int seconds){
stack->inactive_transport_timeout=seconds;
}
void belle_sip_stack_set_default_dscp(belle_sip_stack_t *stack, int dscp){
stack->dscp=dscp;
}
int belle_sip_stack_get_default_dscp(belle_sip_stack_t *stack){
return stack->dscp;
}
......@@ -179,6 +179,8 @@ int finalize_stream_connection(belle_sip_stream_channel_t *obj, struct sockaddr
#if TARGET_OS_IPHONE
stream_channel_enable_ios_background_mode(obj);
#endif
if (obj->base.stack->dscp)
belle_sip_socket_set_dscp(sock,obj->base.lp->ai_family,obj->base.stack->dscp);
return 0;
}else{
belle_sip_error("Connection failed for fd [%i]: cause [%s]",sock,belle_sip_get_socket_error_string_from_code(errnum));
......
......@@ -97,6 +97,11 @@ static belle_sip_socket_t create_server_socket(const char *addr, int port, int *
return -1;
}
freeaddrinfo(res);
err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(char*)&optval, sizeof (optval));
if (err == -1){
belle_sip_warning ("Fail to set SIP/UDP address reusable: %s.", belle_sip_get_socket_error_string());
}
err=listen(sock,64);
if (err==-1){
belle_sip_error("TCP listen() failed for %s port %i: %s",addr,port,belle_sip_get_socket_error_string());
......@@ -109,6 +114,8 @@ void belle_sip_stream_listening_point_setup_server_socket(belle_sip_stream_liste
obj->server_sock=create_server_socket(belle_sip_uri_get_host(obj->base.listening_uri),
belle_sip_uri_get_port(obj->base.listening_uri),&obj->base.ai_family);
if (obj->server_sock==(belle_sip_socket_t)-1) return;
if (obj->base.stack->dscp)
belle_sip_socket_set_dscp(obj->server_sock,obj->base.ai_family,obj->base.stack->dscp);
obj->source=belle_sip_socket_source_new(on_new_connection_cb,obj,obj->server_sock,BELLE_SIP_EVENT_READ,-1);
belle_sip_main_loop_add_source(obj->base.stack->ml,obj->source);
}
......
......@@ -108,7 +108,8 @@ static int belle_sip_udp_listening_point_init_socket(belle_sip_udp_listening_poi
if (lp->sock==(belle_sip_socket_t)-1){
return -1;
}
if (lp->base.stack->dscp)
belle_sip_socket_set_dscp(lp->sock,lp->base.ai_family,lp->base.stack->dscp);
lp->source=belle_sip_socket_source_new((belle_sip_source_func_t)on_udp_data,lp,lp->sock,BELLE_SIP_EVENT_READ,-1);
belle_sip_main_loop_add_source(((belle_sip_listening_point_t*)lp)->stack->ml,lp->source);
return 0;
......
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