diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-01-31 13:03:02 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-01-31 13:05:00 -0800 |
commit | 313d2bb8d37dbc5602e464def90b3e7fa9f60924 (patch) | |
tree | b30451fa66e57041b608d482e6afee74ea47aefd | |
parent | 910f6f3df099c04fcd55bd6b20785cce69cb36ae (diff) | |
download | kgio-313d2bb8d37dbc5602e464def90b3e7fa9f60924.tar.gz |
This is probably a better name for it, libautocork is a nice name even though we won't use it directly.
-rw-r--r-- | ext/kgio/accept.c | 2 | ||||
-rw-r--r-- | ext/kgio/autopush.c (renamed from ext/kgio/nopush.c) | 86 | ||||
-rw-r--r-- | ext/kgio/kgio.h | 8 | ||||
-rw-r--r-- | ext/kgio/kgio_ext.c | 2 | ||||
-rw-r--r-- | ext/kgio/read_write.c | 4 | ||||
-rw-r--r-- | test/test_autopush.rb (renamed from test/test_nopush_smart.rb) | 24 |
6 files changed, 63 insertions, 63 deletions
diff --git a/ext/kgio/accept.c b/ext/kgio/accept.c index a147fec..2ddd75f 100644 --- a/ext/kgio/accept.c +++ b/ext/kgio/accept.c @@ -134,7 +134,7 @@ static VALUE acceptor(int argc, const VALUE *argv) } #if defined(__linux__) -# define post_accept kgio_nopush_accept +# define post_accept kgio_autopush_accept #else # define post_accept(a,b,c,d) for(;0;) #endif diff --git a/ext/kgio/nopush.c b/ext/kgio/autopush.c index c8a7619..8264c29 100644 --- a/ext/kgio/nopush.c +++ b/ext/kgio/autopush.c @@ -14,23 +14,23 @@ #include "kgio.h" -enum nopush_state { - NOPUSH_STATE_IGNORE = -1, - NOPUSH_STATE_WRITER = 0, - NOPUSH_STATE_WRITTEN = 1, - NOPUSH_STATE_ACCEPTOR = 2 +enum autopush_state { + AUTOPUSH_STATE_IGNORE = -1, + AUTOPUSH_STATE_WRITER = 0, + AUTOPUSH_STATE_WRITTEN = 1, + AUTOPUSH_STATE_ACCEPTOR = 2 }; -struct nopush_socket { +struct autopush_socket { VALUE io; - enum nopush_state state; + enum autopush_state state; }; static int enabled; static long capa; -static struct nopush_socket *active; +static struct autopush_socket *active; -static void set_acceptor_state(struct nopush_socket *nps, int fd); +static void set_acceptor_state(struct autopush_socket *aps, int fd); static void flush_pending_data(int fd); static void grow(int fd) @@ -39,55 +39,55 @@ static void grow(int fd) size_t size; assert(new_capa > capa && "grow()-ing for low fd"); - size = new_capa * sizeof(struct nopush_socket); + size = new_capa * sizeof(struct autopush_socket); active = xrealloc(active, size); while (capa < new_capa) { - struct nopush_socket *nps = &active[capa++]; + struct autopush_socket *aps = &active[capa++]; - nps->io = Qnil; - nps->state = NOPUSH_STATE_IGNORE; + aps->io = Qnil; + aps->state = AUTOPUSH_STATE_IGNORE; } } -static VALUE s_get_nopush_smart(VALUE self) +static VALUE s_get_autopush(VALUE self) { return enabled ? Qtrue : Qfalse; } -static VALUE s_set_nopush_smart(VALUE self, VALUE val) +static VALUE s_set_autopush(VALUE self, VALUE val) { enabled = RTEST(val); return val; } -void init_kgio_nopush(void) +void init_kgio_autopush(void) { VALUE m = rb_define_module("Kgio"); - rb_define_singleton_method(m, "nopush_smart?", s_get_nopush_smart, 0); - rb_define_singleton_method(m, "nopush_smart=", s_set_nopush_smart, 1); + rb_define_singleton_method(m, "autopush?", s_get_autopush, 0); + rb_define_singleton_method(m, "autopush=", s_set_autopush, 1); } /* * called after a successful write, just mark that we've put something * in the skb and will need to uncork on the next write. */ -void kgio_nopush_send(VALUE io, int fd) +void kgio_autopush_send(VALUE io, int fd) { - struct nopush_socket *nps; + struct autopush_socket *aps; if (fd >= capa) return; - nps = &active[fd]; - if (nps->io == io && nps->state == NOPUSH_STATE_WRITER) - nps->state = NOPUSH_STATE_WRITTEN; + aps = &active[fd]; + if (aps->io == io && aps->state == AUTOPUSH_STATE_WRITER) + aps->state = AUTOPUSH_STATE_WRITTEN; } /* called on successful accept() */ -void kgio_nopush_accept(VALUE accept_io, VALUE io, int accept_fd, int fd) +void kgio_autopush_accept(VALUE accept_io, VALUE io, int accept_fd, int fd) { - struct nopush_socket *accept_nps, *client_nps; + struct autopush_socket *accept_aps, *client_aps; if (!enabled) return; @@ -96,40 +96,40 @@ void kgio_nopush_accept(VALUE accept_io, VALUE io, int accept_fd, int fd) if (fd >= capa || accept_fd >= capa) grow(fd > accept_fd ? fd : accept_fd); - accept_nps = &active[accept_fd]; + accept_aps = &active[accept_fd]; - if (accept_nps->io != accept_io) { - accept_nps->io = accept_io; - set_acceptor_state(accept_nps, fd); + if (accept_aps->io != accept_io) { + accept_aps->io = accept_io; + set_acceptor_state(accept_aps, fd); } - client_nps = &active[fd]; - client_nps->io = io; - if (accept_nps->state == NOPUSH_STATE_ACCEPTOR) - client_nps->state = NOPUSH_STATE_WRITER; + client_aps = &active[fd]; + client_aps->io = io; + if (accept_aps->state == AUTOPUSH_STATE_ACCEPTOR) + client_aps->state = AUTOPUSH_STATE_WRITER; else - client_nps->state = NOPUSH_STATE_IGNORE; + client_aps->state = AUTOPUSH_STATE_IGNORE; } -void kgio_nopush_recv(VALUE io, int fd) +void kgio_autopush_recv(VALUE io, int fd) { - struct nopush_socket *nps; + struct autopush_socket *aps; if (fd >= capa) return; - nps = &active[fd]; - if (nps->io != io || nps->state != NOPUSH_STATE_WRITTEN) + aps = &active[fd]; + if (aps->io != io || aps->state != AUTOPUSH_STATE_WRITTEN) return; /* reset internal state and flush corked buffers */ - nps->state = NOPUSH_STATE_WRITER; + aps->state = AUTOPUSH_STATE_WRITER; if (enabled) flush_pending_data(fd); } #ifdef __linux__ #include <netinet/tcp.h> -static void set_acceptor_state(struct nopush_socket *nps, int fd) +static void set_acceptor_state(struct autopush_socket *aps, int fd) { int corked = 0; socklen_t optlen = sizeof(int); @@ -138,11 +138,11 @@ static void set_acceptor_state(struct nopush_socket *nps, int fd) if (errno != EOPNOTSUPP) rb_sys_fail("getsockopt(SOL_TCP, TCP_CORK)"); errno = 0; - nps->state = NOPUSH_STATE_IGNORE; + aps->state = AUTOPUSH_STATE_IGNORE; } else if (corked) { - nps->state = NOPUSH_STATE_ACCEPTOR; + aps->state = AUTOPUSH_STATE_ACCEPTOR; } else { - nps->state = NOPUSH_STATE_IGNORE; + aps->state = AUTOPUSH_STATE_IGNORE; } } diff --git a/ext/kgio/kgio.h b/ext/kgio/kgio.h index cf117b6..f1e2c1d 100644 --- a/ext/kgio/kgio.h +++ b/ext/kgio/kgio.h @@ -33,11 +33,11 @@ void init_kgio_wait(void); void init_kgio_read_write(void); void init_kgio_accept(void); void init_kgio_connect(void); -void init_kgio_nopush(void); +void init_kgio_autopush(void); -void kgio_nopush_accept(VALUE, VALUE, int, int); -void kgio_nopush_recv(VALUE, int); -void kgio_nopush_send(VALUE, int); +void kgio_autopush_accept(VALUE, VALUE, int, int); +void kgio_autopush_recv(VALUE, int); +void kgio_autopush_send(VALUE, int); VALUE kgio_call_wait_writable(VALUE io); VALUE kgio_call_wait_readable(VALUE io); diff --git a/ext/kgio/kgio_ext.c b/ext/kgio/kgio_ext.c index 1ebdaae..d106d05 100644 --- a/ext/kgio/kgio_ext.c +++ b/ext/kgio/kgio_ext.c @@ -6,5 +6,5 @@ void Init_kgio_ext(void) init_kgio_read_write(); init_kgio_connect(); init_kgio_accept(); - init_kgio_nopush(); + init_kgio_autopush(); } diff --git a/ext/kgio/read_write.c b/ext/kgio/read_write.c index a954865..ddf800b 100644 --- a/ext/kgio/read_write.c +++ b/ext/kgio/read_write.c @@ -164,7 +164,7 @@ static VALUE my_recv(int io_wait, int argc, VALUE *argv, VALUE io) long n; prepare_read(&a, argc, argv, io); - kgio_nopush_recv(io, a.fd); + kgio_autopush_recv(io, a.fd); if (a.len > 0) { retry: @@ -322,7 +322,7 @@ retry: if (write_check(&a, n, "send", io_wait) != 0) goto retry; if (TYPE(a.buf) != T_SYMBOL) - kgio_nopush_send(io, a.fd); + kgio_autopush_send(io, a.fd); return a.buf; } diff --git a/test/test_nopush_smart.rb b/test/test_autopush.rb index 6d4a698..2fa49be 100644 --- a/test/test_nopush_smart.rb +++ b/test/test_autopush.rb @@ -4,12 +4,12 @@ RUBY_PLATFORM =~ /linux/ and require 'strace' $-w = true require 'kgio' -class TestNoPushSmart < Test::Unit::TestCase +class TestAutopush < Test::Unit::TestCase TCP_CORK = 3 def setup - Kgio.nopush_smart = false - assert_equal false, Kgio.nopush_smart? + Kgio.autopush = false + assert_equal false, Kgio.autopush? @host = ENV["TEST_HOST"] || '127.0.0.1' @srv = Kgio::TCPServer.new(@host, 0) @@ -19,8 +19,8 @@ class TestNoPushSmart < Test::Unit::TestCase @port = @srv.addr[1] end - def test_nopush_smart_true_unix - Kgio.nopush_smart = true + def test_autopush_true_unix + Kgio.autopush = true tmp = Tempfile.new('kgio_unix') @path = tmp.path File.unlink(@path) @@ -42,9 +42,9 @@ class TestNoPushSmart < Test::Unit::TestCase File.unlink(@path) rescue nil end - def test_nopush_smart_false - Kgio.nopush_smart = nil - assert_equal false, Kgio.nopush_smart? + def test_autopush_false + Kgio.autopush = nil + assert_equal false, Kgio.autopush? @wr = Kgio::TCPSocket.new(@host, @port) io, err = Strace.me { @rd = @srv.kgio_accept } @@ -62,9 +62,9 @@ class TestNoPushSmart < Test::Unit::TestCase assert_equal "HI\n", rbuf end if RUBY_PLATFORM =~ /linux/ - def test_nopush_smart_true - Kgio.nopush_smart = true - assert_equal true, Kgio.nopush_smart? + def test_autopush_true + Kgio.autopush = true + assert_equal true, Kgio.autopush? @wr = Kgio::TCPSocket.new(@host, @port) io, err = Strace.me { @rd = @srv.kgio_accept } assert_nil err @@ -105,6 +105,6 @@ class TestNoPushSmart < Test::Unit::TestCase end if RUBY_PLATFORM =~ /linux/ def teardown - Kgio.nopush_smart = false + Kgio.autopush = false end end |