Unix: namespace stream handle flags

This commit is contained in:
Bert Belder 2012-05-02 19:15:52 +02:00
parent 1ebe14e494
commit e38755485e
6 changed files with 49 additions and 38 deletions

View File

@ -84,17 +84,17 @@
/* flags */
enum {
UV_CLOSING = 0x01, /* uv_close() called but not finished. */
UV_CLOSED = 0x02, /* close(2) finished. */
UV_READING = 0x04, /* uv_read_start() called. */
UV_SHUTTING = 0x08, /* uv_shutdown() called but not complete. */
UV_SHUT = 0x10, /* Write side closed. */
UV_READABLE = 0x20, /* The stream is readable */
UV_WRITABLE = 0x40, /* The stream is writable */
UV_TCP_NODELAY = 0x080, /* Disable Nagle. */
UV_TCP_KEEPALIVE = 0x100, /* Turn on keep-alive. */
UV_TIMER_ACTIVE = 0x080,
UV_TIMER_REPEAT = 0x100
UV_CLOSING = 0x01, /* uv_close() called but not finished. */
UV_CLOSED = 0x02, /* close(2) finished. */
UV_STREAM_READING = 0x04, /* uv_read_start() called. */
UV_STREAM_SHUTTING = 0x08, /* uv_shutdown() called but not complete. */
UV_STREAM_SHUT = 0x10, /* Write side closed. */
UV_STREAM_READABLE = 0x20, /* The stream is readable */
UV_STREAM_WRITABLE = 0x40, /* The stream is writable */
UV_TCP_NODELAY = 0x080, /* Disable Nagle. */
UV_TCP_KEEPALIVE = 0x100, /* Turn on keep-alive. */
UV_TIMER_ACTIVE = 0x080,
UV_TIMER_REPEAT = 0x100
};
inline static void uv__req_init(uv_loop_t* loop,

View File

@ -163,7 +163,9 @@ void uv__pipe_close(uv_pipe_t* handle) {
void uv_pipe_open(uv_pipe_t* handle, uv_file fd) {
uv__stream_open((uv_stream_t*)handle, fd, UV_READABLE | UV_WRITABLE);
uv__stream_open((uv_stream_t*)handle,
fd,
UV_STREAM_READABLE | UV_STREAM_WRITABLE);
}
@ -204,7 +206,9 @@ void uv_pipe_connect(uv_connect_t* req,
goto out;
}
uv__stream_open((uv_stream_t*)handle, sockfd, UV_READABLE | UV_WRITABLE);
uv__stream_open((uv_stream_t*)handle,
sockfd,
UV_STREAM_READABLE | UV_STREAM_WRITABLE);
ev_io_start(handle->loop->ev, &handle->read_watcher);
ev_io_start(handle->loop->ev, &handle->write_watcher);

View File

@ -317,7 +317,8 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
assert(stdin_pipe[0] >= 0);
close(stdin_pipe[0]);
uv__nonblock(stdin_pipe[1], 1);
flags = UV_WRITABLE | (options.stdin_stream->ipc ? UV_READABLE : 0);
flags = UV_STREAM_WRITABLE |
(options.stdin_stream->ipc ? UV_STREAM_READABLE : 0);
uv__stream_open((uv_stream_t*)options.stdin_stream, stdin_pipe[1],
flags);
}
@ -327,7 +328,8 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
assert(stdout_pipe[1] >= 0);
close(stdout_pipe[1]);
uv__nonblock(stdout_pipe[0], 1);
flags = UV_READABLE | (options.stdout_stream->ipc ? UV_WRITABLE : 0);
flags = UV_STREAM_READABLE |
(options.stdout_stream->ipc ? UV_STREAM_WRITABLE : 0);
uv__stream_open((uv_stream_t*)options.stdout_stream, stdout_pipe[0],
flags);
}
@ -337,7 +339,8 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
assert(stderr_pipe[1] >= 0);
close(stderr_pipe[1]);
uv__nonblock(stderr_pipe[0], 1);
flags = UV_READABLE | (options.stderr_stream->ipc ? UV_WRITABLE : 0);
flags = UV_STREAM_READABLE |
(options.stderr_stream->ipc ? UV_STREAM_WRITABLE : 0);
uv__stream_open((uv_stream_t*)options.stderr_stream, stderr_pipe[0],
flags);
}

View File

@ -153,7 +153,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
}
}
if (stream->flags & UV_SHUTTING) {
if (stream->flags & UV_STREAM_SHUTTING) {
uv_shutdown_t* req = stream->shutdown_req;
if (req && req->cb) {
uv__set_artificial_error(stream->loop, UV_EINTR);
@ -234,7 +234,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) {
}
if (uv__stream_open(streamClient, streamServer->accepted_fd,
UV_READABLE | UV_WRITABLE)) {
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
/* TODO handle error */
close(streamServer->accepted_fd);
streamServer->accepted_fd = -1;
@ -293,9 +293,9 @@ static void uv__drain(uv_stream_t* stream) {
ev_io_stop(stream->loop->ev, &stream->write_watcher);
/* Shutdown? */
if ((stream->flags & UV_SHUTTING) &&
if ((stream->flags & UV_STREAM_SHUTTING) &&
!(stream->flags & UV_CLOSING) &&
!(stream->flags & UV_SHUT)) {
!(stream->flags & UV_STREAM_SHUT)) {
assert(stream->shutdown_req);
req = stream->shutdown_req;
@ -309,7 +309,7 @@ static void uv__drain(uv_stream_t* stream) {
}
} else {
uv__set_sys_error(stream->loop, 0);
((uv_handle_t*) stream)->flags |= UV_SHUT;
((uv_handle_t*) stream)->flags |= UV_STREAM_SHUT;
if (req->cb) {
req->cb(req, 0);
}
@ -558,11 +558,11 @@ static void uv__read(uv_stream_t* stream) {
char cmsg_space[64];
struct ev_loop* ev = stream->loop->ev;
/* XXX: Maybe instead of having UV_READING we just test if
/* XXX: Maybe instead of having UV_STREAM_READING we just test if
* tcp->read_cb is NULL or not?
*/
while ((stream->read_cb || stream->read2_cb) &&
stream->flags & UV_READING) {
stream->flags & UV_STREAM_READING) {
assert(stream->alloc_cb);
buf = stream->alloc_cb((uv_handle_t*)stream, 64 * 1024);
@ -598,7 +598,7 @@ static void uv__read(uv_stream_t* stream) {
/* Error */
if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* Wait for the next one. */
if (stream->flags & UV_READING) {
if (stream->flags & UV_STREAM_READING) {
ev_io_start(ev, &stream->read_watcher);
}
uv__set_sys_error(stream->loop, EAGAIN);
@ -691,8 +691,8 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
"uv_shutdown (unix) only supports uv_handle_t right now");
assert(stream->fd >= 0);
if (!(stream->flags & UV_WRITABLE) ||
stream->flags & UV_SHUT ||
if (!(stream->flags & UV_STREAM_WRITABLE) ||
stream->flags & UV_STREAM_SHUT ||
stream->flags & UV_CLOSED ||
stream->flags & UV_CLOSING) {
uv__set_sys_error(stream->loop, EINVAL);
@ -705,7 +705,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
req->cb = cb;
stream->shutdown_req = req;
((uv_handle_t*)stream)->flags |= UV_SHUTTING;
((uv_handle_t*)stream)->flags |= UV_STREAM_SHUTTING;
ev_io_start(stream->loop->ev, &stream->write_watcher);
@ -792,7 +792,7 @@ static void uv__stream_connect(uv_stream_t* stream) {
int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
socklen_t addrlen, uv_connect_cb cb) {
socklen_t addrlen, uv_connect_cb cb) {
int sockfd;
int r;
@ -802,7 +802,9 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
return -1;
}
if (uv__stream_open(stream, sockfd, UV_READABLE | UV_WRITABLE)) {
if (uv__stream_open(stream,
sockfd,
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
close(sockfd);
return -2;
}
@ -956,10 +958,10 @@ int uv__read_start_common(uv_stream_t* stream, uv_alloc_cb alloc_cb,
return -1;
}
/* The UV_READING flag is irrelevant of the state of the tcp - it just
/* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just
* expresses the desired state of the user.
*/
((uv_handle_t*)stream)->flags |= UV_READING;
((uv_handle_t*)stream)->flags |= UV_STREAM_READING;
/* TODO: try to do the read inline? */
/* TODO: keep track of tcp state. If we've gotten a EOF then we should
@ -994,7 +996,7 @@ int uv_read2_start(uv_stream_t* stream, uv_alloc_cb alloc_cb,
int uv_read_stop(uv_stream_t* stream) {
ev_io_stop(stream->loop->ev, &stream->read_watcher);
stream->flags &= ~UV_READING;
stream->flags &= ~UV_STREAM_READING;
stream->read_cb = NULL;
stream->read2_cb = NULL;
stream->alloc_cb = NULL;
@ -1003,12 +1005,12 @@ int uv_read_stop(uv_stream_t* stream) {
int uv_is_readable(const uv_stream_t* stream) {
return stream->flags & UV_READABLE;
return stream->flags & UV_STREAM_READABLE;
}
int uv_is_writable(const uv_stream_t* stream) {
return stream->flags & UV_WRITABLE;
return stream->flags & UV_STREAM_WRITABLE;
}

View File

@ -50,7 +50,9 @@ static int uv__bind(uv_tcp_t* tcp,
goto out;
}
if (uv__stream_open((uv_stream_t*)tcp, tcp->fd, UV_READABLE | UV_WRITABLE)) {
if (uv__stream_open((uv_stream_t*)tcp,
tcp->fd,
UV_STREAM_READABLE | UV_STREAM_WRITABLE)) {
close(tcp->fd);
tcp->fd = -1;
status = -2;
@ -181,7 +183,7 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
return -1;
}
if (uv__stream_open((uv_stream_t*)tcp, tcp->fd, UV_READABLE)) {
if (uv__stream_open((uv_stream_t*)tcp, tcp->fd, UV_STREAM_READABLE)) {
close(tcp->fd);
tcp->fd = -1;
return -1;

View File

@ -38,10 +38,10 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
if (readable) {
uv__nonblock(fd, 1);
uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE);
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_READABLE);
} else {
/* Note: writable tty we set to blocking mode. */
uv__stream_open((uv_stream_t*)tty, fd, UV_WRITABLE);
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE);
tty->blocking = 1;
}