Commit d5c7927d authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Fix windows socket errors.

parent 84842639
......@@ -89,13 +89,8 @@ static inline int inet_aton(const char *ip, struct in_addr *p){
return 0;
}
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
#ifndef EINPROGRESS
#define EINPROGRESS WSAEINPROGRESS
#endif
#define BELLESIP_EWOULDBLOCK WSAEWOULDBLOCK
#define BELLESIP_EINPROGRESS WSAEINPROGRESS
#else
......@@ -109,6 +104,9 @@ static inline int get_socket_error(void){
#define belle_sip_get_socket_error_string() strerror(errno)
#define belle_sip_get_socket_error_string_from_code(code) strerror(code)
#define BELLESIP_EWOULDBLOCK EWOULDBLOCK
#define BELLESIP_EINPROGRESS EINPROGRESS
#endif
......
......@@ -35,7 +35,7 @@ int stream_channel_send(belle_sip_channel_t *obj, const void *buf, size_t buflen
int err;
err=send(sock,buf,buflen,0);
if (err==(belle_sip_socket_t)-1){
belle_sip_error("Could not send stream packet on channel [%p]: %s",obj,strerror(errno));
belle_sip_error("Could not send stream packet on channel [%p]: %s",obj,belle_sip_get_socket_error_string());
return -errno;
}
return err;
......@@ -46,7 +46,7 @@ int stream_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
int err;
err=recv(sock,buf,buflen,0);
if (err==(belle_sip_socket_t)-1){
belle_sip_error("Could not receive stream packet: %s",strerror(errno));
belle_sip_error("Could not receive stream packet: %s",belle_sip_get_socket_error_string());
return -errno;
}
return err;
......@@ -82,7 +82,7 @@ int stream_channel_connect(belle_sip_channel_t *obj, const struct addrinfo *ai){
belle_sip_source_set_events((belle_sip_source_t*)obj,BELLE_SIP_EVENT_WRITE|BELLE_SIP_EVENT_ERROR);
err = connect(sock,ai->ai_addr,ai->ai_addrlen);
if (err != 0 && get_socket_error()!=EINPROGRESS && get_socket_error()!=EWOULDBLOCK) {
if (err != 0 && get_socket_error()!=BELLESIP_EINPROGRESS && get_socket_error()!=BELLESIP_EWOULDBLOCK) {
belle_sip_error("stream connect failed %s",belle_sip_get_socket_error_string());
close_socket(sock);
return -1;
......
......@@ -75,7 +75,7 @@ static ssize_t tls_channel_pull_func(gnutls_transport_ptr_t obj, void* buff, siz
int err=recv(
belle_sip_source_get_socket((belle_sip_source_t *)obj),buff,bufflen,0);
if (err==-1){
if (get_socket_error()!=EWOULDBLOCK){
if (get_socket_error()!=BELLESIP_EWOULDBLOCK){
belle_sip_error("tls_channel_pull_func: %s",belle_sip_get_socket_error_string());
}else gnutls_transport_set_errno(channel->session,EAGAIN); /*necessary on windows*/
}
......
......@@ -39,7 +39,7 @@ static int udp_channel_send(belle_sip_channel_t *obj, const void *buf, size_t bu
int err;
err=sendto(chan->sock,buf,buflen,0,obj->peer->ai_addr,obj->peer->ai_addrlen);
if (err==-1){
belle_sip_error("channel [%p]: could not send UDP packet because [%s]",obj,strerror(errno));
belle_sip_error("channel [%p]: could not send UDP packet because [%s]",obj,belle_sip_get_socket_error_string());
return -errno;
}
return err;
......@@ -52,8 +52,8 @@ static int udp_channel_recv(belle_sip_channel_t *obj, void *buf, size_t buflen){
socklen_t addrlen=sizeof(addr);
err=recvfrom(chan->sock,buf,buflen,0,(struct sockaddr*)&addr,&addrlen);
if (err==-1 && errno!=EWOULDBLOCK){
belle_sip_error("Could not receive UDP packet: %s",strerror(errno));
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;
}
return err;
......
......@@ -76,13 +76,13 @@ static belle_sip_socket_t create_udp_socket(const char *addr, int port){
}
sock=socket(res->ai_family,res->ai_socktype,res->ai_protocol);
if (sock==-1){
belle_sip_error("Cannot create UDP socket: %s",strerror(errno));
belle_sip_error("Cannot create UDP socket: %s",belle_sip_get_socket_error_string());
freeaddrinfo(res);
return -1;
}
err=bind(sock,res->ai_addr,res->ai_addrlen);
if (err==-1){
belle_sip_error("udp bind() failed for %s port %i: %s",addr,port,strerror(errno));
belle_sip_error("udp bind() failed for %s port %i: %s",addr,port,belle_sip_get_socket_error_string());
close_socket(sock);
freeaddrinfo(res);
return -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