Fix bind tests for macos

This commit is contained in:
Ryan Dahl 2011-05-07 19:14:13 -07:00
parent 850e4072e7
commit 6107bd554b
2 changed files with 20 additions and 2 deletions

View File

@ -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);

View File

@ -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; \