Commit d0e7de25 authored by Simon Morlat's avatar Simon Morlat

fix source problems on windows (polling FD_WRITE was not working as

expected.)
parent 64fb2a40
......@@ -227,17 +227,21 @@ struct belle_sip_source{
unsigned long id;
belle_sip_fd_t fd;
unsigned short events,revents;
#ifdef WIN32
unsigned short armed_events;
unsigned short pad;
#endif
int timeout;
void *data;
uint64_t expire_ms;
int index; /* index in pollfd table */
belle_sip_source_func_t notify;
belle_sip_source_remove_callback_t on_remove;
belle_sip_socket_t sock;
unsigned char cancelled;
unsigned char expired;
unsigned char oneshot;
unsigned char notify_required; /*for testing purpose, use to ask for being scheduled*/
belle_sip_socket_t sock;
};
void belle_sip_socket_source_init(belle_sip_source_t *s, belle_sip_source_func_t func, void *data, belle_sip_socket_t fd, unsigned int events, unsigned int timeout_value_ms);
......
......@@ -92,9 +92,11 @@ static void belle_sip_source_to_poll(belle_sip_source_t *s, belle_sip_pollfd_t *
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());
if (events!=s->armed_events){
s->armed_events=events;
err=WSAEventSelect(s->sock,s->fd,events);
if (err!=0) belle_sip_error("WSAEventSelect() failed: %s",belle_sip_get_socket_error_string());
}
}
}
......@@ -103,19 +105,22 @@ static unsigned int belle_sip_source_get_revents(belle_sip_source_t *s,belle_sip
int err;
unsigned int ret=0;
/*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{
if (WaitForSingleObjectEx(s->fd,0,FALSE)==WAIT_OBJECT_0){
if (WaitForSingleObjectEx(s->fd,0,FALSE)==WAIT_OBJECT_0){
if (s->sock!=(belle_sip_socket_t)-1){
/*special treatments for windows sockets*/
err=WSAEnumNetworkEvents(s->sock,s->fd,&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;
}
s->armed_events=0;
}else{
ret=BELLE_SIP_EVENT_READ;
ResetEvent(s->fd);
}
......
......@@ -1017,14 +1017,14 @@ static void _send_message(belle_sip_channel_t *obj){
size_t off;
int ret;
if (obj->ewouldblock_buffer){
while (obj->ewouldblock_buffer){
sendret=send_buffer(obj,(const char*)obj->ewouldblock_buffer+obj->ewouldblock_offset,obj->ewouldblock_size-obj->ewouldblock_offset);
if (sendret>0){
obj->ewouldblock_offset+=sendret;
if (obj->ewouldblock_offset==obj->ewouldblock_size){
free_ewouldblock_buffer(obj);
}
return; /*we prefer poll again to be sure we can write*/
/* continue to expedite the ewouldblock error until we it is completed or get a new ewouldblock*/
}else if (belle_sip_error_code_is_would_block(-sendret)) {
/*we got an ewouldblock again. Nothing to do, we'll be called later in order to retry*/
return;
......
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