Commit ed0b4da7 authored by Simon Morlat's avatar Simon Morlat

fix crash, and add log for EWOULDBLOCK error while sending

parent 803b16b7
......@@ -242,12 +242,10 @@ int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents
return BELLE_SIP_CONTINUE;
} else if (num == 0) {
channel_set_state(obj,BELLE_SIP_CHANNEL_DISCONNECTED);
belle_sip_channel_close(obj);
return BELLE_SIP_STOP;
} else {
belle_sip_error("Receive error on channel [%p]",obj);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
belle_sip_channel_close(obj);
return BELLE_SIP_STOP;
}
return BELLE_SIP_CONTINUE;
......@@ -255,8 +253,8 @@ int belle_sip_channel_process_data(belle_sip_channel_t *obj,unsigned int revents
static int channel_inactive_timeout(void *data, unsigned int event){
belle_sip_channel_t *obj=(belle_sip_channel_t *)data;
belle_sip_message("Channel [%p]: inactivity timeout reached.",obj);
channel_set_state(obj,BELLE_SIP_CHANNEL_DISCONNECTED);
belle_sip_channel_close(obj);
return BELLE_SIP_STOP;
}
......@@ -397,6 +395,11 @@ belle_sip_message_t* belle_sip_channel_pick_message(belle_sip_channel_t *obj) {
static void channel_invoke_state_listener(belle_sip_channel_t *obj){
belle_sip_list_t* list=belle_sip_list_copy(obj->listeners); /*copy list because error state alter this list (I.E by provider)*/
if (obj->state==BELLE_SIP_CHANNEL_DISCONNECTED || obj->state==BELLE_SIP_CHANNEL_ERROR){
belle_sip_channel_close(obj);
}
BELLE_SIP_INVOKE_LISTENERS_ARG1_ARG2(list,belle_sip_channel_listener_t,on_state_changed,obj,obj->state);
belle_sip_list_free(list);
}
......@@ -437,7 +440,6 @@ static void _send_message(belle_sip_channel_t *obj, belle_sip_message_t *msg){
,obj->peer_name
,obj->peer_port);
channel_set_state(obj,BELLE_SIP_CHANNEL_ERROR);
belle_sip_channel_close(obj);
}else{
belle_sip_message("channel [%p]: message sent to [%s://%s:%i] \n%s"
,obj
......@@ -581,7 +583,6 @@ int belle_sip_channel_queue_message(belle_sip_channel_t *obj, belle_sip_message_
void belle_sip_channel_force_close(belle_sip_channel_t *obj){
obj->force_close=1;
channel_set_state(obj,BELLE_SIP_CHANNEL_DISCONNECTED);
belle_sip_channel_close(obj);
}
......@@ -149,7 +149,9 @@ static int send_keep_alive(belle_sip_channel_t* obj) {
/*keep alive*/
const char* crlfcrlf = "\r\n\r\n";
int size=strlen(crlfcrlf);
if (belle_sip_channel_send(obj,crlfcrlf,size)<0){
int err=belle_sip_channel_send(obj,crlfcrlf,size);
if (err<=0 && !belle_sip_error_code_is_would_block(-err) && err!=-EINTR){
belle_sip_error("channel [%p]: could not send [%i] bytes of keep alive from [%s://%s:%i] to [%s:%i]" ,obj
,size
,belle_sip_channel_get_transport_name(obj)
......
......@@ -137,7 +137,7 @@ static inline int get_socket_error(void){
#endif
#define belle_sip_error_code_is_would_block(err) ((err)==BELLESIP_EWOULDBLOCK || (err)==BELLESIP_EINPROGRESS)
#endif
......@@ -44,8 +44,10 @@ int stream_channel_send(belle_sip_stream_channel_t *obj, const void *buf, size_t
err=send(sock,buf,buflen,0);
if (err==(belle_sip_socket_t)-1){
int errnum=get_socket_error();
if (errnum!=BELLESIP_EINPROGRESS && errnum!=BELLESIP_EWOULDBLOCK){
if (!belle_sip_error_code_is_would_block(errnum)){
belle_sip_error("Could not send stream packet on channel [%p]: %s",obj,belle_sip_get_socket_error_string());
}else{
belle_sip_warning("Channel [%p]: stream_channel_send EWOULDBLOCK",obj);
}
return -errnum;
}
......@@ -58,7 +60,7 @@ int stream_channel_recv(belle_sip_stream_channel_t *obj, void *buf, size_t bufle
err=recv(sock,buf,buflen,0);
if (err==(belle_sip_socket_t)-1){
int errnum=get_socket_error();
if (errnum!=BELLESIP_EINPROGRESS && errnum!=BELLESIP_EWOULDBLOCK){
if (!belle_sip_error_code_is_would_block(errnum)){
belle_sip_error("Could not receive stream packet: %s",belle_sip_get_socket_error_string());
}
return -errnum;
......
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