Port to Solaris
This commit is contained in:
parent
f0de01379f
commit
2f4e65a1b2
2
README
2
README
@ -11,6 +11,8 @@ Studio or MingW.
|
|||||||
|
|
||||||
Linux 2.6 and MacOS using the GCC toolchain.
|
Linux 2.6 and MacOS using the GCC toolchain.
|
||||||
|
|
||||||
|
Solaris 121 and later using GCC toolchain.
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
The goal of this library is to provide high-concurrency high-performance I/O
|
The goal of this library is to provide high-concurrency high-performance I/O
|
||||||
|
|||||||
@ -26,6 +26,10 @@ LINKFLAGS=-lm
|
|||||||
TESTS=test/echo-server.c test/test-*.c
|
TESTS=test/echo-server.c test/test-*.c
|
||||||
BENCHMARKS=test/echo-server.c test/benchmark-*.c
|
BENCHMARKS=test/echo-server.c test/benchmark-*.c
|
||||||
|
|
||||||
|
ifeq (SunOS,$(uname_S))
|
||||||
|
LINKFLAGS+=-lsocket -lnsl
|
||||||
|
endif
|
||||||
|
|
||||||
RUNNER_CFLAGS=$(CFLAGS) -D_GNU_SOURCE # Need _GNU_SOURCE for strdup?
|
RUNNER_CFLAGS=$(CFLAGS) -D_GNU_SOURCE # Need _GNU_SOURCE for strdup?
|
||||||
RUNNER_LINKFLAGS=$(LINKFLAGS) -pthread
|
RUNNER_LINKFLAGS=$(LINKFLAGS) -pthread
|
||||||
RUNNER_LIBS=
|
RUNNER_LIBS=
|
||||||
|
|||||||
46
oio-unix.c
46
oio-unix.c
@ -40,7 +40,7 @@ static oio_alloc_cb alloc_cb;
|
|||||||
|
|
||||||
void oio__tcp_io(EV_P_ ev_io* watcher, int revents);
|
void oio__tcp_io(EV_P_ ev_io* watcher, int revents);
|
||||||
void oio__next(EV_P_ ev_idle* watcher, int revents);
|
void oio__next(EV_P_ ev_idle* watcher, int revents);
|
||||||
static void oio_tcp_connect(oio_handle_t* handle);
|
static void oio__tcp_connect(oio_handle_t* handle);
|
||||||
int oio_tcp_open(oio_handle_t*, int fd);
|
int oio_tcp_open(oio_handle_t*, int fd);
|
||||||
static void oio__finish_close(oio_handle_t* handle);
|
static void oio__finish_close(oio_handle_t* handle);
|
||||||
|
|
||||||
@ -682,7 +682,7 @@ void oio__tcp_io(EV_P_ ev_io* watcher, int revents) {
|
|||||||
assert(!oio_flag_is_set(handle, OIO_CLOSING));
|
assert(!oio_flag_is_set(handle, OIO_CLOSING));
|
||||||
|
|
||||||
if (handle->connect_req) {
|
if (handle->connect_req) {
|
||||||
oio_tcp_connect(handle);
|
oio__tcp_connect(handle);
|
||||||
} else {
|
} else {
|
||||||
if (revents & EV_READ) {
|
if (revents & EV_READ) {
|
||||||
oio__read(handle);
|
oio__read(handle);
|
||||||
@ -700,15 +700,26 @@ void oio__tcp_io(EV_P_ ev_io* watcher, int revents) {
|
|||||||
* In order to determine if we've errored out or succeeded must call
|
* In order to determine if we've errored out or succeeded must call
|
||||||
* getsockopt.
|
* getsockopt.
|
||||||
*/
|
*/
|
||||||
static void oio_tcp_connect(oio_handle_t* handle) {
|
static void oio__tcp_connect(oio_handle_t* handle) {
|
||||||
|
int error;
|
||||||
|
socklen_t errorsize = sizeof(int);
|
||||||
|
|
||||||
assert(handle->fd >= 0);
|
assert(handle->fd >= 0);
|
||||||
|
|
||||||
oio_req_t* req = handle->connect_req;
|
oio_req_t* req = handle->connect_req;
|
||||||
assert(req);
|
assert(req);
|
||||||
|
|
||||||
int error;
|
if (handle->delayed_error) {
|
||||||
socklen_t errorsize = sizeof(int);
|
/* To smooth over the differences between unixes errors that
|
||||||
getsockopt(handle->fd, SOL_SOCKET, SO_ERROR, &error, &errorsize);
|
* were reported synchronously on the first connect can be delayed
|
||||||
|
* until the next tick--which is now.
|
||||||
|
*/
|
||||||
|
error = handle->delayed_error;
|
||||||
|
handle->delayed_error = 0;
|
||||||
|
} else {
|
||||||
|
/* Normal situation: we need to get the socket error from the kernel. */
|
||||||
|
getsockopt(handle->fd, SOL_SOCKET, SO_ERROR, &error, &errorsize);
|
||||||
|
}
|
||||||
|
|
||||||
if (!error) {
|
if (!error) {
|
||||||
ev_io_start(EV_DEFAULT_ &handle->read_watcher);
|
ev_io_start(EV_DEFAULT_ &handle->read_watcher);
|
||||||
@ -723,8 +734,8 @@ static void oio_tcp_connect(oio_handle_t* handle) {
|
|||||||
} else if (error == EINPROGRESS) {
|
} else if (error == EINPROGRESS) {
|
||||||
/* Still connecting. */
|
/* Still connecting. */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
/* Error */
|
||||||
oio_err_t err = oio_err_new(handle, error);
|
oio_err_t err = oio_err_new(handle, error);
|
||||||
|
|
||||||
handle->connect_req = NULL;
|
handle->connect_req = NULL;
|
||||||
@ -773,14 +784,31 @@ int oio_connect(oio_req_t* req, struct sockaddr* addr) {
|
|||||||
int addrsize = sizeof(struct sockaddr_in);
|
int addrsize = sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
int r = connect(handle->fd, addr, addrsize);
|
int r = connect(handle->fd, addr, addrsize);
|
||||||
|
handle->delayed_error = 0;
|
||||||
|
|
||||||
if (r != 0 && errno != EINPROGRESS) {
|
if (r != 0 && errno != EINPROGRESS) {
|
||||||
oio_err_new(handle, errno);
|
switch (errno) {
|
||||||
return -1;
|
/* If we get a ECONNREFUSED wait until the next tick to report the
|
||||||
|
* error. Solaris wants to report immediately--other unixes want to
|
||||||
|
* wait.
|
||||||
|
*/
|
||||||
|
case ECONNREFUSED:
|
||||||
|
handle->delayed_error = errno;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
oio_err_new(handle, errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(handle->write_watcher.data == handle);
|
assert(handle->write_watcher.data == handle);
|
||||||
ev_io_start(EV_DEFAULT_ &handle->write_watcher);
|
ev_io_start(EV_DEFAULT_ &handle->write_watcher);
|
||||||
|
|
||||||
|
if (handle->delayed_error) {
|
||||||
|
ev_feed_event(EV_DEFAULT_ &handle->write_watcher, EV_WRITE);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,7 +40,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
/* A specific process was requested. */
|
/* A specific process was requested. */
|
||||||
run_process(argv[1]);
|
return run_process(argv[1]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Run all benchmarks. */
|
/* Run all benchmarks. */
|
||||||
|
|||||||
@ -47,7 +47,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
/* A specific process was requested. */
|
/* A specific process was requested. */
|
||||||
run_process(argv[1]);
|
return run_process(argv[1]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Count the number of tests. */
|
/* Count the number of tests. */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user