From 6107bd554b5c77218341f8a2f48ef631178410ce Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 7 May 2011 19:14:13 -0700 Subject: [PATCH] Fix bind tests for macos --- oio-unix.c | 21 +++++++++++++++++++-- oio-unix.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/oio-unix.c b/oio-unix.c index db259112..d062a7d4 100644 --- a/oio-unix.c +++ b/oio-unix.c @@ -213,8 +213,20 @@ int oio_bind(oio_handle* handle, struct sockaddr* addr) { } r = bind(handle->fd, addr, addrsize); - oio_err_new(handle, errno); - return r; + + if (r) { + switch (errno) { + case EADDRINUSE: + handle->delayed_error = errno; + return 0; + + default: + oio_err_new(handle, errno); + return -1; + } + } + + return 0; } @@ -317,6 +329,11 @@ int oio_accept(oio_handle* server, oio_handle* client, int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb) { assert(handle->fd >= 0); + if (handle->delayed_error) { + oio_err_new(handle, handle->delayed_error); + return -1; + } + int r = listen(handle->fd, backlog); if (r < 0) { oio_err_new(handle, errno); diff --git a/oio-unix.h b/oio-unix.h index 480dc65b..39bd76bd 100644 --- a/oio-unix.h +++ b/oio-unix.h @@ -49,6 +49,7 @@ typedef struct { #define oio_handle_private_fields \ int fd; \ int flags; \ + int delayed_error; \ oio_read_cb read_cb; \ oio_accept_cb accept_cb; \ int accepted_fd; \