Windows fixes.

This commit is contained in:
Jan Vidar Krey 2011-02-05 17:11:23 +01:00
parent bf4ad5624a
commit e5bb7057de
4 changed files with 20 additions and 8 deletions

View File

@ -144,8 +144,6 @@ int main_loop()
hub_set_variables(hub, &acl);
break;
hub_event_loop(hub);
hub_free_variables(hub);

View File

@ -83,8 +83,7 @@ size_t net_get_max_sockets()
return 1024;
#else
#ifdef WIN32
LOG_WARN("Windows system, limited to 4096 connections.");
return 4096;
return FD_SETSIZE;
#else
LOG_WARN("System does not have getrlimit(): constrained to 1024 sockets");
return 1024;
@ -650,12 +649,16 @@ const char* net_get_local_address(int fd)
if (getsockname(fd, (struct sockaddr*) name, &namelen) != -1)
{
#ifndef WINSOCK
int af = storage.ss_family;
if (af == AF_INET6)
{
net_address_to_string(af, (void*) &name6->sin6_addr, address, INET6_ADDRSTRLEN);
}
else
#else
int af = AF_INET;
#endif
{
net_address_to_string(af, (void*) &name4->sin_addr, address, INET6_ADDRSTRLEN);
}

View File

@ -35,6 +35,7 @@ struct net_backend_select
struct net_connection_select** conns;
fd_set rfds;
fd_set wfds;
fd_set xfds;
int maxfd;
struct net_backend_common* common;
};
@ -58,6 +59,7 @@ int net_backend_poll_select(struct net_backend* data, int ms)
FD_ZERO(&backend->rfds);
FD_ZERO(&backend->wfds);
FD_ZERO(&backend->xfds);
backend->maxfd = -1;
for (n = 0, found = 0; found < backend->common->num && n < backend->common->max; n++)
@ -73,10 +75,14 @@ int net_backend_poll_select(struct net_backend* data, int ms)
}
backend->maxfd++;
res = select(backend->maxfd, &backend->rfds, &backend->wfds, 0, &tval);
if (res == -1 && errno == EINTR)
res = select(backend->maxfd, &backend->rfds, &backend->wfds, &backend->xfds, &tval);
if (res == -1)
{
printf("Error: %d\n", net_error());
}
if (res == -1 && net_error() == EINTR)
return 0;
return res;
}
@ -122,11 +128,13 @@ void net_con_backend_add_select(struct net_backend* data, struct net_connection*
{
struct net_backend_select* backend = (struct net_backend_select*) data;
backend->conns[con->sd] = (struct net_connection_select*) con;
con->flags |= (events & (NET_EVENT_READ | NET_EVENT_WRITE));
}
void net_con_backend_mod_select(struct net_backend* data, struct net_connection* con, int events)
{
con->flags |= (events & (NET_EVENT_READ | NET_EVENT_WRITE));;
con->flags |= (events & (NET_EVENT_READ | NET_EVENT_WRITE));
}
void net_con_backend_del_select(struct net_backend* data, struct net_connection* con)

View File

@ -37,6 +37,9 @@
#endif
#ifdef WINSOCK
#ifndef FD_SETSIZE
#define FD_SETSIZE 4096
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#else