From e71495c84a4323158a348f5bd43af542f307a1b1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 23 May 2012 22:48:56 +0200 Subject: [PATCH] unix: turn field stream->blocking into a flag Saves 4 bytes. --- include/uv-private/uv-unix.h | 1 - src/unix/internal.h | 13 +++++++------ src/unix/stream.c | 9 ++++----- src/unix/tty.c | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index 71253bc9..fed7f8de 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -159,7 +159,6 @@ struct uv__io_s { int delayed_error; \ uv_connection_cb connection_cb; \ int accepted_fd; \ - int blocking; /* UV_TCP */ diff --git a/src/unix/internal.h b/src/unix/internal.h index 328d76d7..f42fead0 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -84,17 +84,18 @@ /* flags */ enum { - UV_CLOSING = 0x01, /* uv_close() called but not finished. */ - UV_CLOSED = 0x02, /* close(2) finished. */ + 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_REPEAT = 0x100, - UV__PENDING = 0x800 + UV_STREAM_BLOCKING = 0x80, /* Synchronous writes. */ + UV_TCP_NODELAY = 0x100, /* Disable Nagle. */ + UV_TCP_KEEPALIVE = 0x200, /* Turn on keep-alive. */ + UV_TIMER_REPEAT = 0x100, + UV__PENDING = 0x800 }; inline static int uv__has_pending_handles(const uv_loop_t* loop) { diff --git a/src/unix/stream.c b/src/unix/stream.c index bb5351a4..516a4690 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -67,7 +67,6 @@ void uv__stream_init(uv_loop_t* loop, stream->accepted_fd = -1; stream->fd = -1; stream->delayed_error = 0; - stream->blocking = 0; ngx_queue_init(&stream->write_queue); ngx_queue_init(&stream->write_completed_queue); stream->write_queue_size = 0; @@ -444,7 +443,7 @@ start: stream->write_queue_size -= uv__write_req_size(req); uv__write_req_finish(req); return; - } else if (stream->blocking) { + } else if (stream->flags & UV_STREAM_BLOCKING) { /* If this is a blocking stream, try again. */ goto start; } @@ -465,7 +464,7 @@ start: n = 0; /* There is more to write. */ - if (stream->blocking) { + if (stream->flags & UV_STREAM_BLOCKING) { /* * If we're blocking then we should not be enabling the write * watcher - instead we need to try again. @@ -501,7 +500,7 @@ start: assert(n == 0 || n == -1); /* Only non-blocking streams should use the write_watcher. */ - assert(!stream->blocking); + assert(!(stream->flags & UV_STREAM_BLOCKING)); /* We're not done. */ uv__io_start(stream->loop, &stream->write_watcher); @@ -931,7 +930,7 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt, * if this assert fires then somehow the blocking stream isn't being * sufficently flushed in uv__write. */ - assert(!stream->blocking); + assert(!(stream->flags & UV_STREAM_BLOCKING)); uv__io_start(stream->loop, &stream->write_watcher); } diff --git a/src/unix/tty.c b/src/unix/tty.c index 572d19c6..7193db8b 100644 --- a/src/unix/tty.c +++ b/src/unix/tty.c @@ -42,7 +42,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) { } else { /* Note: writable tty we set to blocking mode. */ uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE); - tty->blocking = 1; + tty->flags |= UV_STREAM_BLOCKING; } loop->counters.tty_init++;