about summary refs log tree commit homepage
path: root/ext/kgio/accept.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-08-16 01:52:15 +0000
committerEric Wong <normalperson@yhbt.net>2013-08-16 01:57:04 +0000
commit9f30805bc4ff65ad4ca0be9dfb26b1a9bdc70c51 (patch)
treec974cbd69173710607707545817b66883c5b650f /ext/kgio/accept.c
parent8be51237720fd18cb45188f29c717bbac0ca1964 (diff)
downloadkgio-9f30805bc4ff65ad4ca0be9dfb26b1a9bdc70c51.tar.gz
check syscall returns against < 0 instead of == -1
This may help us avoid errors in case of C library bugs,
and also results in smaller code:

$ ~/linux/scripts/bloat-o-meter before.so after.so
add/remove: 0/0 grow/shrink: 0/9 up/down: 0/-66 (-66)
function                                     old     new   delta
s_trywrite                                   160     159      -1
kgio_write                                   160     159      -1
kgio_trywrite                                160     159      -1
my_recv                                      616     610      -6
my_peek                                      616     610      -6
stream_connect                               456     448      -8
my_socket                                    222     213      -9
my_writev                                   1703    1687     -16
write_check                                  427     409     -18
Diffstat (limited to 'ext/kgio/accept.c')
-rw-r--r--ext/kgio/accept.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/ext/kgio/accept.c b/ext/kgio/accept.c
index 5f07532..503b5e9 100644
--- a/ext/kgio/accept.c
+++ b/ext/kgio/accept.c
@@ -68,7 +68,7 @@ static VALUE xaccept(void *ptr)
         int rv;
 
         rv = accept_fn(a->fd, a->addr, a->addrlen, a->flags);
-        if (rv == -1 && errno == ENOSYS && accept_fn != my_accept4) {
+        if (rv < 0 && errno == ENOSYS && accept_fn != my_accept4) {
                 accept_fn = my_accept4;
                 rv = accept_fn(a->fd, a->addr, a->addrlen, a->flags);
         }
@@ -170,7 +170,7 @@ my_accept(struct accept_args *a, int force_nonblock)
 
 retry:
         client_fd = thread_accept(a, force_nonblock);
-        if (client_fd == -1) {
+        if (client_fd < 0) {
                 switch (errno) {
                 case EAGAIN:
                         if (force_nonblock)