Commit 8d49d185 authored by Benjamin REIS's avatar Benjamin REIS

apply IOS10 bg policy to udp channel & better uses of errno

parent c32eb6f8
......@@ -1165,13 +1165,13 @@ int belle_sip_get_src_addr_for(const struct sockaddr *dest, socklen_t destlen, s
}
if (connect(sock,dest,destlen)==-1){
belle_sip_error("belle_sip_get_src_addr_for: connect() failed: %s",belle_sip_get_socket_error_string());
ret = -get_socket_error();
belle_sip_error("belle_sip_get_src_addr_for: connect() failed: %s",belle_sip_get_socket_error_string_from_code(-ret));
goto fail;
}
if (getsockname(sock,src,srclen)==-1){
belle_sip_error("belle_sip_get_src_addr_for: getsockname() failed: %s",belle_sip_get_socket_error_string());
ret = -get_socket_error();
belle_sip_error("belle_sip_get_src_addr_for: getsockname() failed: %s",belle_sip_get_socket_error_string_from_code(-ret));
goto fail;
}
......
......@@ -44,7 +44,7 @@ int stream_channel_send(belle_sip_stream_channel_t *obj, const void *buf, size_t
if (err==(belle_sip_socket_t)-1){
int errnum=get_socket_error();
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());
belle_sip_error("Could not send stream packet on channel [%p]: %s",obj,belle_sip_get_socket_error_string_from_code(errnum));
}
return -errnum;
}
......@@ -55,16 +55,16 @@ int stream_channel_recv(belle_sip_stream_channel_t *obj, void *buf, size_t bufle
belle_sip_socket_t sock = belle_sip_source_get_socket((belle_sip_source_t*)obj);
int err=bctbx_recv(sock,buf,buflen,0);
if (strcmp(belle_sip_get_socket_error_string(), "Socket is not connected") == 0) { //Do NOT treat it as an error
belle_sip_message("Socket is not connected because of IOS10 background policy");
obj->base.closed_by_remote = TRUE;
return 0;
}
if (err==(belle_sip_socket_t)-1){
int errnum=get_socket_error();
if (errnum == BCTBX_ENOTCONN) { //Do NOT treat it as an error
belle_sip_message("Socket is not connected because of IOS10 background policy");
obj->base.closed_by_remote = TRUE;
return 0;
}
if (!belle_sip_error_code_is_would_block(errnum)){
belle_sip_error("Could not receive stream packet: %s",belle_sip_get_socket_error_string());
belle_sip_error("Could not receive stream packet: %s",belle_sip_get_socket_error_string_from_code(errnum));
}
return -errnum;
}
......
......@@ -51,15 +51,21 @@ static int udp_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
static int udp_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
belle_sip_udp_channel_t *chan=(belle_sip_udp_channel_t *)obj;
int err;
int errnum;
struct sockaddr_storage addr;
socklen_t addrlen=sizeof(addr);
belle_sip_socket_t sock=belle_sip_source_get_socket((belle_sip_source_t*)chan);
err=(int)bctbx_recvfrom(sock,buf,buflen,0,(struct sockaddr*)&addr,&addrlen);
if (err==-1 && get_socket_error()!=BELLESIP_EWOULDBLOCK){
belle_sip_error("Could not receive UDP packet: %s",belle_sip_get_socket_error_string());
return -errno;
errnum = get_socket_error();
if (err==-1 && errnum!=BELLESIP_EWOULDBLOCK){
if (errnum == BCTBX_ENOTCONN) { //Do NOT treat it as an error
belle_sip_message("Socket is not connected because of IOS10 background policy");
obj->closed_by_remote = TRUE;
return 0;
}
belle_sip_error("Could not receive UDP packet: %s",belle_sip_get_socket_error_string_from_code(errnum));
return -errnum;
}
return err;
}
......
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