uv-unix: pipes API implementation

Based on UNIX sockets to avoid the vagaries of FIFOs
in asynchronous mode. Currently unlinks stale sockets
before binding and cleans them up again after shutdown.
This commit is contained in:
Ben Noordhuis 2011-07-19 00:58:02 +02:00
parent 4d31f838b0
commit 4eff34da43
4 changed files with 655 additions and 263 deletions

View File

@ -67,25 +67,27 @@ typedef struct {
#define UV_STREAM_PRIVATE_FIELDS \
uv_read_cb read_cb; \
uv_alloc_cb alloc_cb;
/* UV_TCP */
#define UV_TCP_PRIVATE_FIELDS \
int delayed_error; \
uv_connection_cb connection_cb; \
int accepted_fd; \
uv_alloc_cb alloc_cb; \
uv_connect_t *connect_req; \
uv_shutdown_t *shutdown_req; \
ev_io read_watcher; \
ev_io write_watcher; \
ngx_queue_t write_queue; \
ngx_queue_t write_completed_queue;
ngx_queue_t write_completed_queue; \
int delayed_error; \
uv_connection_cb connection_cb; \
int accepted_fd;
/* UV_TCP */
#define UV_TCP_PRIVATE_FIELDS
/* UV_NAMED_PIPE */
#define UV_PIPE_PRIVATE_TYPEDEF
#define UV_PIPE_PRIVATE_FIELDS
#define UV_PIPE_PRIVATE_FIELDS \
UV_TCP_PRIVATE_FIELDS \
const char* pipe_fname; /* strdup'ed */ \
/* UV_PREPARE */ \

File diff suppressed because it is too large Load Diff

View File

@ -124,7 +124,7 @@ static uv_buf_t echo_alloc(uv_stream_t* handle, size_t suggested_size) {
static void on_connection(uv_handle_t* server, int status) {
uv_handle_t* handle;
uv_stream_t* stream;
int r;
if (status != 0) {
@ -132,25 +132,31 @@ static void on_connection(uv_handle_t* server, int status) {
}
ASSERT(status == 0);
if (serverType == TCP) {
handle = (uv_handle_t*) malloc(sizeof(uv_tcp_t));
ASSERT(handle != NULL);
switch (serverType) {
case TCP:
stream = malloc(sizeof(uv_tcp_t));
ASSERT(stream != NULL);
uv_tcp_init((uv_tcp_t*)stream);
break;
uv_tcp_init((uv_tcp_t*)handle);
} else {
handle = (uv_handle_t*) malloc(sizeof(uv_pipe_t));
ASSERT(handle != NULL);
case PIPE:
stream = malloc(sizeof(uv_pipe_t));
ASSERT(stream != NULL);
uv_pipe_init((uv_pipe_t*)stream);
break;
uv_pipe_init((uv_pipe_t*)handle);
default:
ASSERT(0 && "Bad serverType");
abort();
}
/* associate server with stream */
handle->data = server;
stream->data = server;
r = uv_accept(server, (uv_stream_t*)handle);
r = uv_accept(server, stream);
ASSERT(r == 0);
r = uv_read_start((uv_stream_t*)handle, echo_alloc, after_read);
r = uv_read_start(stream, echo_alloc, after_read);
ASSERT(r == 0);
}
@ -233,22 +239,19 @@ static int pipe_echo_start(char* pipeName) {
r = uv_pipe_init(&pipeServer);
if (r) {
/* TODO: Error codes */
fprintf(stderr, "Pipe creation error\n");
fprintf(stderr, "uv_pipe_init: %s\n", uv_strerror(uv_last_error()));
return 1;
}
r = uv_pipe_bind(&pipeServer, pipeName);
if (r) {
/* TODO: Error codes */
fprintf(stderr, "create error\n");
fprintf(stderr, "uv_pipe_bind: %s\n", uv_strerror(uv_last_error()));
return 1;
}
r = uv_pipe_listen(&pipeServer, on_connection);
if (r) {
/* TODO: Error codes */
fprintf(stderr, "Listen error on IPv6\n");
fprintf(stderr, "uv_pipe_listen: %s\n", uv_strerror(uv_last_error()));
return 1;
}

View File

@ -33,8 +33,7 @@
#ifdef _WIN32
# define TEST_PIPENAME "\\\\.\\pipe\\uv-test"
#else
# /* TODO: define unix pipe name */
# define TEST_PIPENAME ""
# define TEST_PIPENAME "/tmp/uv-test-sock"
#endif
typedef enum {