Commit ddfe6cc9 authored by Simon Morlat's avatar Simon Morlat
Browse files

works on windows over UDP.

parent fd0a2df6
......@@ -79,18 +79,22 @@ static unsigned int belle_sip_source_get_revents(belle_sip_source_t *s,belle_sip
typedef HANDLE belle_sip_pollfd_t;
static void belle_sip_source_to_poll(belle_sip_source_t *s, belle_sip_pollfd_t *pfd,int i){
int err;
long events=0;
pfd[i]=s->fd;
s->index=i;
pfd[i]=s->fd;
if (s->events & BELLE_SIP_EVENT_READ)
events|=FD_READ;
if (s->events & BELLE_SIP_EVENT_WRITE)
events|=FD_WRITE;
err=WSAEventSelect(s->sock,s->fd,events);
if (err!=0) belle_sip_error("WSAEventSelect() failed: %i",err);
/*special treatments for windows sockets*/
if (s->sock!=(belle_sip_socket_t)-1){
int err;
long events=0;
if (s->events & BELLE_SIP_EVENT_READ)
events|=FD_READ;
if (s->events & BELLE_SIP_EVENT_WRITE)
events|=FD_WRITE;
err=WSAEventSelect(s->sock,s->fd,events);
if (err!=0) belle_sip_error("WSAEventSelect() failed: %s",belle_sip_get_socket_error_string());
}
}
static unsigned int belle_sip_source_get_revents(belle_sip_source_t *s,belle_sip_pollfd_t *pfd){
......@@ -98,15 +102,18 @@ static unsigned int belle_sip_source_get_revents(belle_sip_source_t *s,belle_sip
int err;
unsigned int ret=0;
err=WSAEnumNetworkEvents(s->sock,NULL,&revents);
if (err!=0){
belle_sip_error("WSAEnumNetworkEvents() failed: %i",err);
return 0;
}
if (revents.lNetworkEvents & FD_READ)
ret|=BELLE_SIP_EVENT_READ;
if (revents.lNetworkEvents & FD_WRITE)
ret|=BELLE_SIP_EVENT_WRITE;
/*special treatments for windows sockets*/
if (s->sock!=(belle_sip_socket_t)-1){
err=WSAEnumNetworkEvents(s->sock,NULL,&revents);
if (err!=0){
belle_sip_error("WSAEnumNetworkEvents() failed: %s socket=%x",belle_sip_get_socket_error_string(),(unsigned int)s->sock);
return 0;
}
if (revents.lNetworkEvents & FD_READ)
ret|=BELLE_SIP_EVENT_READ;
if (revents.lNetworkEvents & FD_WRITE)
ret|=BELLE_SIP_EVENT_WRITE;
}else ret=BELLE_SIP_EVENT_READ;
return ret;
}
......@@ -140,6 +147,7 @@ static void belle_sip_source_init(belle_sip_source_t *s, belle_sip_source_func_t
s->timeout=timeout_value_ms;
s->data=data;
s->notify=func;
s->sock=(belle_sip_socket_t)-1;
}
void belle_sip_source_uninit(belle_sip_source_t *obj){
......@@ -154,7 +162,6 @@ void belle_sip_source_uninit(belle_sip_source_t *obj){
}
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t sock, unsigned int events, unsigned int timeout_value_ms){
s->sock=sock;
#ifdef WIN32
/*on windows, the fd to poll is not the socket */
belle_sip_fd_t fd=(belle_sip_fd_t)-1;
......@@ -167,6 +174,7 @@ void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t
#else
belle_sip_source_init(s,func,data,sock,events,timeout_value_ms);
#endif
s->sock=sock;
}
void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_fd_t fd, unsigned int events, unsigned int timeout_value_ms){
......
......@@ -95,7 +95,7 @@ static belle_sip_socket_t create_udp_socket(const char *addr, int port){
* If the channel does not exist, create it */
static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events){
int err;
unsigned char buf[1];
unsigned char buf[4096];
struct sockaddr_storage addr;
socklen_t addrlen=sizeof(addr);
......@@ -103,7 +103,7 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
belle_sip_message("udp_listening_point: data to read.");
err=recvfrom(lp->sock,(void*)buf,sizeof(buf),MSG_PEEK,(struct sockaddr*)&addr,&addrlen);
if (err==-1){
belle_sip_error("udp_listening_point: recvfrom() failed: %s",strerror(errno));
belle_sip_error("udp_listening_point: recvfrom() failed: %s",belle_sip_get_socket_error_string());
}else{
belle_sip_channel_t *chan;
struct addrinfo ai={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