librb: some win32 fixes

This commit is contained in:
William Pitcock 2016-03-20 00:33:19 -05:00
parent b68dee9bcb
commit dc7e6b42ca
4 changed files with 18 additions and 16 deletions

View file

@ -36,8 +36,10 @@
#ifdef _WIN32
#define rb_get_errno() do { errno = WSAGetLastError(); WSASetLastError(errno); } while(0)
typedef SOCKET rb_platform_fd_t;
#else
#define rb_get_errno()
typedef int rb_platform_fd_t;
#endif
#define rb_hash_fd(x) ((x ^ (x >> RB_FD_HASH_BITS) ^ (x >> (RB_FD_HASH_BITS * 2))) & RB_FD_HASH_MASK)
@ -104,7 +106,7 @@ struct _fde
* filedescriptor. Think though: when do you think we'll need more?
*/
rb_dlink_node node;
int fd; /* So we can use the rb_fde_t as a callback ptr */
rb_platform_fd_t fd; /* So we can use the rb_fde_t as a callback ptr */
uint8_t flags;
uint8_t type;
int pflags;
@ -136,7 +138,7 @@ typedef struct timer_data
extern rb_dlink_list *rb_fd_table;
static inline rb_fde_t *
rb_find_fd(int fd)
rb_find_fd(rb_platform_fd_t fd)
{
rb_dlink_list *hlist;
rb_dlink_node *ptr;

View file

@ -154,7 +154,7 @@ int rb_get_fd(rb_fde_t *F);
const char *rb_get_ssl_strerror(rb_fde_t *F);
int rb_get_ssl_certfp(rb_fde_t *F, uint8_t certfp[RB_SSL_CERTFP_LEN], int method);
rb_fde_t *rb_get_fde(int fd);
rb_fde_t *rb_get_fde(rb_platform_fd_t fd);
int rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasize, pid_t pid);
int rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int count);

View file

@ -79,7 +79,7 @@ static int rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2);
#endif
static inline rb_fde_t *
add_fd(int fd)
add_fd(rb_platform_fd_t fd)
{
rb_fde_t *F = rb_find_fd(fd);
@ -230,7 +230,7 @@ rb_set_nb(rb_fde_t *F)
{
int nonb = 0;
int res;
int fd;
rb_platform_fd_t fd;
if(F == NULL)
return 0;
fd = F->fd;
@ -409,7 +409,7 @@ rb_accept_tcp(rb_fde_t *F, ACPRE * precb, ACCB * callback, void *data)
}
/*
* void rb_connect_tcp(int fd, struct sockaddr *dest,
* void rb_connect_tcp(rb_platform_fd_t fd, struct sockaddr *dest,
* struct sockaddr *clocal, int socklen,
* CNCB *callback, void *data, int timeout)
* Input: An fd to connect with, a host and port to connect to,
@ -496,7 +496,7 @@ rb_connect_timeout(rb_fde_t *F, void *notused)
rb_connect_callback(F, RB_ERR_TIMEOUT);
}
/* static void rb_connect_tryconnect(int fd, void *notused)
/* static void rb_connect_tryconnect(rb_platform_fd_t fd, void *notused)
* Input: The fd, the handler data(unused).
* Output: None.
* Side-effects: Try and connect with pending connect data for the FD. If
@ -627,7 +627,7 @@ int
rb_pipe(rb_fde_t **F1, rb_fde_t **F2, const char *desc)
{
#ifndef _WIN32
int fd[2];
rb_platform_fd_t fd[2];
if(number_fd >= rb_maxconnections)
{
errno = ENFILE;
@ -677,7 +677,7 @@ rb_fde_t *
rb_socket(int family, int sock_type, int proto, const char *note)
{
rb_fde_t *F;
int fd;
rb_platform_fd_t fd;
/* First, make sure we aren't going to run out of file descriptors */
if(rb_unlikely(number_fd >= rb_maxconnections))
{
@ -821,7 +821,7 @@ rb_fdlist_init(int closeall, int maxfds, size_t heapsize)
/* Called to open a given filedescriptor */
rb_fde_t *
rb_open(int fd, uint8_t type, const char *desc)
rb_open(rb_platform_fd_t fd, uint8_t type, const char *desc)
{
rb_fde_t *F;
lrb_assert(fd >= 0);
@ -979,7 +979,7 @@ rb_get_fd(rb_fde_t *F)
}
rb_fde_t *
rb_get_fde(int fd)
rb_get_fde(rb_platform_fd_t fd)
{
return rb_find_fd(fd);
}
@ -1609,7 +1609,7 @@ rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2)
struct sockaddr_in addr[2];
rb_socklen_t size = sizeof(struct sockaddr_in);
rb_fde_t *F[2];
unsigned int fd[2];
unsigned rb_platform_fd_t fd[2];
int i, got;
unsigned short port;
struct timeval wait = { 0, 100000 };
@ -1713,7 +1713,7 @@ rb_inet_socketpair_udp(rb_fde_t **newF1, rb_fde_t **newF2)
int
rb_inet_socketpair(int family, int type, int protocol, int fd[2])
rb_inet_socketpair(int family, int type, int protocol, rb_platform_fd_t fd[2])
{
int listener = -1;
int connector = -1;
@ -2136,7 +2136,7 @@ rb_recv_fd_buf(rb_fde_t *F, void *data, size_t datasize, rb_fde_t **xF, int nfds
struct stat st;
uint8_t stype = RB_FD_UNKNOWN;
const char *desc;
int fd, len, x, rfds;
rb_platform_fd_t fd, len, x, rfds;
int control_len = CMSG_SPACE(sizeof(int) * nfds);

View file

@ -94,7 +94,7 @@ rb_spawn_process(const char *path, const char **argv)
}
pid_t
rb_waitpid(int pid, int *status, int flags)
rb_waitpid(pid_t pid, int *status, int flags)
{
DWORD timeout = (flags & WNOHANG) ? 0 : INFINITE;
HANDLE hProcess;
@ -152,7 +152,7 @@ rb_setenv(const char *name, const char *value, int overwrite)
}
int
rb_kill(int pid, int sig)
rb_kill(pid_t pid, int sig)
{
HANDLE hProcess;
int ret = -1;