noderb 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/noderb_extension/libuv/AUTHORS +11 -1
- data/ext/noderb_extension/libuv/LICENSE +0 -8
- data/ext/noderb_extension/libuv/Makefile +5 -5
- data/ext/noderb_extension/libuv/README +11 -6
- data/ext/noderb_extension/libuv/common.gypi +158 -7
- data/ext/noderb_extension/libuv/config-unix.mk +34 -26
- data/ext/noderb_extension/libuv/gyp_uv +22 -4
- data/ext/noderb_extension/libuv/include/{eio.h → uv-private/eio.h} +2 -2
- data/ext/noderb_extension/libuv/include/{uv-unix.h → uv-private/uv-unix.h} +40 -0
- data/ext/noderb_extension/libuv/include/{uv-win.h → uv-private/uv-win.h} +96 -14
- data/ext/noderb_extension/libuv/include/uv.h +508 -83
- data/ext/noderb_extension/libuv/src/unix/cares.c +185 -0
- data/ext/noderb_extension/libuv/src/unix/core.c +828 -0
- data/ext/noderb_extension/libuv/src/{eio → unix/eio}/config_darwin.h +4 -0
- data/ext/noderb_extension/libuv/src/{eio → unix/eio}/config_linux.h +5 -15
- data/ext/noderb_extension/libuv/src/{eio → unix/eio}/eio.c +23 -2
- data/ext/noderb_extension/libuv/src/unix/error.c +102 -0
- data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config_linux.h +26 -15
- data/ext/noderb_extension/libuv/src/unix/fs.c +562 -0
- data/ext/noderb_extension/libuv/src/unix/internal.h +75 -0
- data/ext/noderb_extension/libuv/src/unix/pipe.c +282 -0
- data/ext/noderb_extension/libuv/src/unix/process.c +287 -0
- data/ext/noderb_extension/libuv/src/unix/stream.c +727 -0
- data/ext/noderb_extension/libuv/src/unix/tcp.c +226 -0
- data/ext/noderb_extension/libuv/src/unix/udp.c +524 -0
- data/ext/noderb_extension/libuv/src/{uv-eio.c → unix/uv-eio.c} +48 -27
- data/ext/noderb_extension/libuv/src/{uv-eio.h → unix/uv-eio.h} +1 -1
- data/ext/noderb_extension/libuv/src/uv-common.c +24 -14
- data/ext/noderb_extension/libuv/src/uv-common.h +12 -7
- data/ext/noderb_extension/libuv/src/win/async.c +14 -16
- data/ext/noderb_extension/libuv/src/win/cares.c +64 -79
- data/ext/noderb_extension/libuv/src/win/core.c +105 -53
- data/ext/noderb_extension/libuv/src/win/error.c +23 -13
- data/ext/noderb_extension/libuv/src/win/fs.c +807 -0
- data/ext/noderb_extension/libuv/src/win/getaddrinfo.c +61 -41
- data/ext/noderb_extension/libuv/src/win/handle.c +56 -30
- data/ext/noderb_extension/libuv/src/win/internal.h +134 -95
- data/ext/noderb_extension/libuv/src/win/loop-watcher.c +21 -18
- data/ext/noderb_extension/libuv/src/win/pipe.c +313 -158
- data/ext/noderb_extension/libuv/src/win/process.c +117 -131
- data/ext/noderb_extension/libuv/src/win/req.c +55 -31
- data/ext/noderb_extension/libuv/src/win/stdio.c +5 -5
- data/ext/noderb_extension/libuv/src/win/stream.c +19 -14
- data/ext/noderb_extension/libuv/src/win/tcp.c +278 -336
- data/ext/noderb_extension/libuv/src/win/threadpool.c +73 -0
- data/ext/noderb_extension/libuv/src/win/timer.c +44 -37
- data/ext/noderb_extension/libuv/src/win/udp.c +592 -0
- data/ext/noderb_extension/libuv/src/win/util.c +20 -6
- data/ext/noderb_extension/libuv/src/win/winapi.c +23 -6
- data/ext/noderb_extension/libuv/src/win/winapi.h +4206 -0
- data/ext/noderb_extension/libuv/src/win/winsock.c +270 -0
- data/ext/noderb_extension/libuv/src/win/winsock.h +134 -0
- data/ext/noderb_extension/libuv/test/benchmark-ares.c +10 -6
- data/ext/noderb_extension/libuv/test/benchmark-getaddrinfo.c +10 -7
- data/ext/noderb_extension/libuv/test/benchmark-list.h +21 -0
- data/ext/noderb_extension/libuv/test/benchmark-ping-pongs.c +11 -7
- data/ext/noderb_extension/libuv/test/benchmark-pound.c +147 -58
- data/ext/noderb_extension/libuv/test/benchmark-pump.c +29 -23
- data/ext/noderb_extension/libuv/test/benchmark-spawn.c +13 -10
- data/ext/noderb_extension/libuv/test/benchmark-udp-packet-storm.c +250 -0
- data/ext/noderb_extension/libuv/test/dns-server.c +11 -6
- data/ext/noderb_extension/libuv/test/echo-server.c +30 -22
- data/ext/noderb_extension/libuv/test/test-async.c +3 -3
- data/ext/noderb_extension/libuv/test/test-callback-stack.c +6 -6
- data/ext/noderb_extension/libuv/test/test-connection-fail.c +6 -5
- data/ext/noderb_extension/libuv/test/test-delayed-accept.c +13 -13
- data/ext/noderb_extension/libuv/test/test-fs.c +715 -0
- data/ext/noderb_extension/libuv/test/test-getaddrinfo.c +11 -8
- data/ext/noderb_extension/libuv/test/test-gethostbyname.c +8 -9
- data/ext/noderb_extension/libuv/test/test-getsockname.c +142 -16
- data/ext/noderb_extension/libuv/test/test-idle.c +4 -3
- data/ext/noderb_extension/libuv/test/test-list.h +29 -2
- data/ext/noderb_extension/libuv/test/test-loop-handles.c +9 -8
- data/ext/noderb_extension/libuv/test/test-ping-pong.c +9 -9
- data/ext/noderb_extension/libuv/test/test-pipe-bind-error.c +18 -14
- data/ext/noderb_extension/libuv/test/test-ref.c +17 -16
- data/ext/noderb_extension/libuv/test/test-shutdown-eof.c +5 -5
- data/ext/noderb_extension/libuv/test/test-spawn.c +17 -17
- data/ext/noderb_extension/libuv/test/test-tcp-bind-error.c +24 -18
- data/ext/noderb_extension/libuv/test/test-tcp-bind6-error.c +19 -14
- data/ext/noderb_extension/libuv/test/test-tcp-writealot.c +6 -5
- data/ext/noderb_extension/libuv/test/test-threadpool.c +59 -0
- data/ext/noderb_extension/libuv/test/test-timer-again.c +15 -12
- data/ext/noderb_extension/libuv/test/test-timer.c +8 -8
- data/ext/noderb_extension/libuv/test/test-udp-dgram-too-big.c +88 -0
- data/ext/noderb_extension/libuv/test/test-udp-ipv6.c +158 -0
- data/ext/noderb_extension/libuv/test/test-udp-send-and-recv.c +210 -0
- data/ext/noderb_extension/libuv/{all.gyp → uv.gyp} +75 -77
- data/ext/noderb_extension/libuv/vcbuild.bat +93 -0
- data/ext/noderb_extension/noderb.c +13 -0
- data/ext/noderb_extension/noderb_common.h +2 -1
- data/ext/noderb_extension/noderb_defer.c +54 -0
- data/ext/noderb_extension/noderb_defer.h +15 -0
- data/ext/noderb_extension/noderb_dns.c +1 -1
- data/ext/noderb_extension/noderb_fs.c +277 -0
- data/ext/noderb_extension/noderb_fs.h +27 -0
- data/ext/noderb_extension/noderb_process.c +5 -5
- data/ext/noderb_extension/noderb_tcp.c +10 -6
- data/ext/noderb_extension/noderb_timers.c +1 -1
- data/ext/noderb_extension/noderb_tools.c +42 -8
- data/ext/noderb_extension/noderb_tools.h +3 -1
- data/lib/noderb/defer.rb +25 -0
- data/lib/noderb/file.rb +119 -0
- data/lib/noderb/fs.rb +72 -0
- data/lib/noderb/version.rb +1 -1
- data/lib/noderb.rb +8 -0
- metadata +102 -266
- data/ext/noderb_extension/libuv/BSDmakefile +0 -2
- data/ext/noderb_extension/libuv/create-msvs-files.bat +0 -21
- data/ext/noderb_extension/libuv/deps/pthread-win32/ANNOUNCE +0 -482
- data/ext/noderb_extension/libuv/deps/pthread-win32/BUGS +0 -141
- data/ext/noderb_extension/libuv/deps/pthread-win32/Bmakefile +0 -268
- data/ext/noderb_extension/libuv/deps/pthread-win32/CONTRIBUTORS +0 -140
- data/ext/noderb_extension/libuv/deps/pthread-win32/COPYING +0 -150
- data/ext/noderb_extension/libuv/deps/pthread-win32/COPYING.LIB +0 -504
- data/ext/noderb_extension/libuv/deps/pthread-win32/ChangeLog +0 -5194
- data/ext/noderb_extension/libuv/deps/pthread-win32/FAQ +0 -451
- data/ext/noderb_extension/libuv/deps/pthread-win32/GNUmakefile +0 -593
- data/ext/noderb_extension/libuv/deps/pthread-win32/MAINTAINERS +0 -4
- data/ext/noderb_extension/libuv/deps/pthread-win32/Makefile +0 -516
- data/ext/noderb_extension/libuv/deps/pthread-win32/NEWS +0 -1245
- data/ext/noderb_extension/libuv/deps/pthread-win32/Nmakefile +0 -24
- data/ext/noderb_extension/libuv/deps/pthread-win32/Nmakefile.tests +0 -260
- data/ext/noderb_extension/libuv/deps/pthread-win32/PROGRESS +0 -4
- data/ext/noderb_extension/libuv/deps/pthread-win32/README +0 -601
- data/ext/noderb_extension/libuv/deps/pthread-win32/README.Borland +0 -57
- data/ext/noderb_extension/libuv/deps/pthread-win32/README.CV +0 -3036
- data/ext/noderb_extension/libuv/deps/pthread-win32/README.NONPORTABLE +0 -783
- data/ext/noderb_extension/libuv/deps/pthread-win32/README.Watcom +0 -62
- data/ext/noderb_extension/libuv/deps/pthread-win32/README.WinCE +0 -6
- data/ext/noderb_extension/libuv/deps/pthread-win32/TODO +0 -7
- data/ext/noderb_extension/libuv/deps/pthread-win32/WinCE-PORT +0 -222
- data/ext/noderb_extension/libuv/deps/pthread-win32/attr.c +0 -53
- data/ext/noderb_extension/libuv/deps/pthread-win32/autostatic.c +0 -69
- data/ext/noderb_extension/libuv/deps/pthread-win32/barrier.c +0 -47
- data/ext/noderb_extension/libuv/deps/pthread-win32/build/all.gyp +0 -207
- data/ext/noderb_extension/libuv/deps/pthread-win32/builddmc.bat +0 -9
- data/ext/noderb_extension/libuv/deps/pthread-win32/cancel.c +0 -44
- data/ext/noderb_extension/libuv/deps/pthread-win32/cleanup.c +0 -148
- data/ext/noderb_extension/libuv/deps/pthread-win32/condvar.c +0 -50
- data/ext/noderb_extension/libuv/deps/pthread-win32/config.h +0 -153
- data/ext/noderb_extension/libuv/deps/pthread-win32/context.h +0 -74
- data/ext/noderb_extension/libuv/deps/pthread-win32/create.c +0 -308
- data/ext/noderb_extension/libuv/deps/pthread-win32/dll.c +0 -92
- data/ext/noderb_extension/libuv/deps/pthread-win32/errno.c +0 -94
- data/ext/noderb_extension/libuv/deps/pthread-win32/exit.c +0 -44
- data/ext/noderb_extension/libuv/deps/pthread-win32/fork.c +0 -39
- data/ext/noderb_extension/libuv/deps/pthread-win32/global.c +0 -107
- data/ext/noderb_extension/libuv/deps/pthread-win32/implement.h +0 -944
- data/ext/noderb_extension/libuv/deps/pthread-win32/misc.c +0 -50
- data/ext/noderb_extension/libuv/deps/pthread-win32/mutex.c +0 -62
- data/ext/noderb_extension/libuv/deps/pthread-win32/need_errno.h +0 -145
- data/ext/noderb_extension/libuv/deps/pthread-win32/nonportable.c +0 -47
- data/ext/noderb_extension/libuv/deps/pthread-win32/private.c +0 -54
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.c +0 -66
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.dsp +0 -142
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.dsw +0 -29
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread.h +0 -1368
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_destroy.c +0 -79
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getdetachstate.c +0 -86
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getinheritsched.c +0 -51
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getschedparam.c +0 -52
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getschedpolicy.c +0 -61
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getscope.c +0 -54
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getstackaddr.c +0 -97
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_getstacksize.c +0 -100
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_init.c +0 -117
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setdetachstate.c +0 -91
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setinheritsched.c +0 -57
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setschedparam.c +0 -63
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setschedpolicy.c +0 -55
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setscope.c +0 -62
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setstackaddr.c +0 -97
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_attr_setstacksize.c +0 -110
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrier_destroy.c +0 -103
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrier_init.c +0 -69
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrier_wait.c +0 -104
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_destroy.c +0 -83
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_getpshared.c +0 -95
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_init.c +0 -85
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_barrierattr_setpshared.c +0 -119
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cancel.c +0 -189
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_destroy.c +0 -253
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_init.c +0 -167
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_signal.c +0 -231
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_cond_wait.c +0 -567
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_destroy.c +0 -86
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_getpshared.c +0 -97
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_init.c +0 -87
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_condattr_setpshared.c +0 -117
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_delay_np.c +0 -172
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_detach.c +0 -136
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_equal.c +0 -76
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_exit.c +0 -106
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getconcurrency.c +0 -45
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getschedparam.c +0 -75
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getspecific.c +0 -87
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getunique_np.c +0 -47
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_getw32threadhandle_np.c +0 -65
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_join.c +0 -157
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_key_create.c +0 -108
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_key_delete.c +0 -125
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_kill.c +0 -105
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_consistent.c +0 -187
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_destroy.c +0 -148
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_init.c +0 -130
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_lock.c +0 -269
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_timedlock.c +0 -324
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_trylock.c +0 -154
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutex_unlock.c +0 -175
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_destroy.c +0 -83
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_getkind_np.c +0 -44
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_getpshared.c +0 -95
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_getrobust.c +0 -113
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_gettype.c +0 -56
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_init.c +0 -86
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_setkind_np.c +0 -44
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_setpshared.c +0 -119
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_setrobust.c +0 -119
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_mutexattr_settype.c +0 -143
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_num_processors_np.c +0 -56
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_once.c +0 -79
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_destroy.c +0 -143
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_init.c +0 -109
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_rdlock.c +0 -102
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_timedrdlock.c +0 -109
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_timedwrlock.c +0 -139
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_tryrdlock.c +0 -102
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_trywrlock.c +0 -122
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_unlock.c +0 -93
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlock_wrlock.c +0 -133
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_destroy.c +0 -84
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_getpshared.c +0 -97
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_init.c +0 -83
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_rwlockattr_setpshared.c +0 -120
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_self.c +0 -141
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setcancelstate.c +0 -125
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setcanceltype.c +0 -126
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setconcurrency.c +0 -53
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setschedparam.c +0 -123
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_setspecific.c +0 -167
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_destroy.c +0 -111
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_init.c +0 -123
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_lock.c +0 -80
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_trylock.c +0 -77
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_spin_unlock.c +0 -71
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_testcancel.c +0 -103
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_timechange_handler_np.c +0 -108
- data/ext/noderb_extension/libuv/deps/pthread-win32/pthread_win32_attach_detach_np.c +0 -258
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_MCS_lock.c +0 -278
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_callUserDestroyRoutines.c +0 -232
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_calloc.c +0 -56
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_cond_check_need_init.c +0 -78
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_getprocessors.c +0 -91
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_is_attr.c +0 -47
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_mutex_check_need_init.c +0 -92
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_new.c +0 -94
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_processInitialize.c +0 -92
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_processTerminate.c +0 -105
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_relmillisecs.c +0 -132
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_reuse.c +0 -151
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_rwlock_cancelwrwait.c +0 -50
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_rwlock_check_need_init.c +0 -77
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_semwait.c +0 -135
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_spinlock_check_need_init.c +0 -78
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_threadDestroy.c +0 -79
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_threadStart.c +0 -357
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_throw.c +0 -189
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_timespec.c +0 -83
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_tkAssocCreate.c +0 -118
- data/ext/noderb_extension/libuv/deps/pthread-win32/ptw32_tkAssocDestroy.c +0 -114
- data/ext/noderb_extension/libuv/deps/pthread-win32/rwlock.c +0 -51
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched.c +0 -53
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched.h +0 -183
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched_get_priority_max.c +0 -134
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched_get_priority_min.c +0 -135
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched_getscheduler.c +0 -71
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched_setscheduler.c +0 -83
- data/ext/noderb_extension/libuv/deps/pthread-win32/sched_yield.c +0 -71
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_close.c +0 -58
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_destroy.c +0 -144
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_getvalue.c +0 -110
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_init.c +0 -169
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_open.c +0 -58
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_post.c +0 -128
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_post_multiple.c +0 -142
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_timedwait.c +0 -238
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_trywait.c +0 -117
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_unlink.c +0 -58
- data/ext/noderb_extension/libuv/deps/pthread-win32/sem_wait.c +0 -187
- data/ext/noderb_extension/libuv/deps/pthread-win32/semaphore.c +0 -69
- data/ext/noderb_extension/libuv/deps/pthread-win32/semaphore.h +0 -169
- data/ext/noderb_extension/libuv/deps/pthread-win32/signal.c +0 -179
- data/ext/noderb_extension/libuv/deps/pthread-win32/spin.c +0 -46
- data/ext/noderb_extension/libuv/deps/pthread-win32/sync.c +0 -43
- data/ext/noderb_extension/libuv/deps/pthread-win32/tsd.c +0 -44
- data/ext/noderb_extension/libuv/deps/pthread-win32/version.rc +0 -388
- data/ext/noderb_extension/libuv/deps/pthread-win32/w32_CancelableWait.c +0 -161
- data/ext/noderb_extension/libuv/doc/iocp-links.html +0 -574
- data/ext/noderb_extension/libuv/src/uv-unix.c +0 -2421
- data/ext/noderb_extension/libuv/src/win/ntdll.h +0 -130
- /data/ext/noderb_extension/libuv/include/{ev.h → uv-private/ev.h} +0 -0
- /data/ext/noderb_extension/libuv/include/{ngx-queue.h → uv-private/ngx-queue.h} +0 -0
- /data/ext/noderb_extension/libuv/include/{tree.h → uv-private/tree.h} +0 -0
- /data/ext/noderb_extension/libuv/src/{uv-cygwin.c → unix/cygwin.c} +0 -0
- /data/ext/noderb_extension/libuv/src/{uv-darwin.c → unix/darwin.c} +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/Changes +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/LICENSE +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/Makefile.am +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/aclocal.m4 +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/autogen.sh +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/config.h.in +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/config_cygwin.h +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/config_freebsd.h +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/config_sunos.h +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/configure.ac +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/demo.c +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/ecb.h +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/eio.3 +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/eio.pod +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/libeio.m4 +0 -0
- /data/ext/noderb_extension/libuv/src/{eio → unix/eio}/xthread.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/Changes +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/LICENSE +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/Makefile.am +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/Makefile.in +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/README +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/aclocal.m4 +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/autogen.sh +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config.guess +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config.h.in +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config.sub +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config_cygwin.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config_darwin.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config_freebsd.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/config_sunos.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/configure +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/configure.ac +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/depcomp +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev++.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev.3 +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev.pod +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_epoll.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_kqueue.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_poll.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_port.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_select.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_vars.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_win32.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ev_wrap.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/event.c +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/event.h +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/install-sh +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/libev.m4 +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/ltmain.sh +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/missing +0 -0
- /data/ext/noderb_extension/libuv/src/{ev → unix/ev}/mkinstalldirs +0 -0
- /data/ext/noderb_extension/libuv/src/{uv-freebsd.c → unix/freebsd.c} +0 -0
- /data/ext/noderb_extension/libuv/src/{uv-linux.c → unix/linux.c} +0 -0
- /data/ext/noderb_extension/libuv/src/{uv-sunos.c → unix/sunos.c} +0 -0
@@ -0,0 +1,727 @@
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
2
|
+
*
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
* furnished to do so, subject to the following conditions:
|
9
|
+
*
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
11
|
+
* all copies or substantial portions of the Software.
|
12
|
+
*
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
19
|
+
* IN THE SOFTWARE.
|
20
|
+
*/
|
21
|
+
|
22
|
+
#include "uv.h"
|
23
|
+
#include "internal.h"
|
24
|
+
|
25
|
+
#include <assert.h>
|
26
|
+
#include <errno.h>
|
27
|
+
#include <unistd.h>
|
28
|
+
#include <stdlib.h>
|
29
|
+
#include <sys/uio.h>
|
30
|
+
|
31
|
+
|
32
|
+
static void uv__stream_connect(uv_stream_t*);
|
33
|
+
static uv_write_t* uv__write(uv_stream_t* stream);
|
34
|
+
static void uv__read(uv_stream_t* stream);
|
35
|
+
|
36
|
+
|
37
|
+
static size_t uv__buf_count(uv_buf_t bufs[], int bufcnt) {
|
38
|
+
size_t total = 0;
|
39
|
+
int i;
|
40
|
+
|
41
|
+
for (i = 0; i < bufcnt; i++) {
|
42
|
+
total += bufs[i].len;
|
43
|
+
}
|
44
|
+
|
45
|
+
return total;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
|
50
|
+
socklen_t yes;
|
51
|
+
|
52
|
+
assert(fd >= 0);
|
53
|
+
stream->fd = fd;
|
54
|
+
|
55
|
+
((uv_handle_t*)stream)->flags |= flags;
|
56
|
+
|
57
|
+
/* Reuse the port address if applicable. */
|
58
|
+
yes = 1;
|
59
|
+
if (stream->type == UV_TCP
|
60
|
+
&& setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
|
61
|
+
uv_err_new(stream->loop, errno);
|
62
|
+
return -1;
|
63
|
+
}
|
64
|
+
|
65
|
+
/* Associate the fd with each ev_io watcher. */
|
66
|
+
ev_io_set(&stream->read_watcher, fd, EV_READ);
|
67
|
+
ev_io_set(&stream->write_watcher, fd, EV_WRITE);
|
68
|
+
|
69
|
+
/* These should have been set up by uv_tcp_init or uv_pipe_init. */
|
70
|
+
assert(stream->read_watcher.cb == uv__stream_io);
|
71
|
+
assert(stream->write_watcher.cb == uv__stream_io);
|
72
|
+
|
73
|
+
return 0;
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
void uv__server_io(EV_P_ ev_io* watcher, int revents) {
|
78
|
+
int fd;
|
79
|
+
struct sockaddr_storage addr;
|
80
|
+
uv_stream_t* stream = watcher->data;
|
81
|
+
|
82
|
+
assert(watcher == &stream->read_watcher ||
|
83
|
+
watcher == &stream->write_watcher);
|
84
|
+
assert(revents == EV_READ);
|
85
|
+
|
86
|
+
assert(!(stream->flags & UV_CLOSING));
|
87
|
+
|
88
|
+
if (stream->accepted_fd >= 0) {
|
89
|
+
ev_io_stop(EV_A, &stream->read_watcher);
|
90
|
+
return;
|
91
|
+
}
|
92
|
+
|
93
|
+
/* connection_cb can close the server socket while we're
|
94
|
+
* in the loop so check it on each iteration.
|
95
|
+
*/
|
96
|
+
while (stream->fd != -1) {
|
97
|
+
assert(stream->accepted_fd < 0);
|
98
|
+
fd = uv__accept(stream->fd, (struct sockaddr*)&addr, sizeof addr);
|
99
|
+
|
100
|
+
if (fd < 0) {
|
101
|
+
if (errno == EAGAIN) {
|
102
|
+
/* No problem. */
|
103
|
+
return;
|
104
|
+
} else if (errno == EMFILE) {
|
105
|
+
/* TODO special trick. unlock reserved socket, accept, close. */
|
106
|
+
return;
|
107
|
+
} else {
|
108
|
+
uv_err_new(stream->loop, errno);
|
109
|
+
stream->connection_cb((uv_stream_t*)stream, -1);
|
110
|
+
}
|
111
|
+
} else {
|
112
|
+
stream->accepted_fd = fd;
|
113
|
+
stream->connection_cb((uv_stream_t*)stream, 0);
|
114
|
+
if (stream->accepted_fd >= 0) {
|
115
|
+
/* The user hasn't yet accepted called uv_accept() */
|
116
|
+
ev_io_stop(stream->loop->ev, &stream->read_watcher);
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
int uv_accept(uv_stream_t* server, uv_stream_t* client) {
|
125
|
+
uv_stream_t* streamServer;
|
126
|
+
uv_stream_t* streamClient;
|
127
|
+
int saved_errno;
|
128
|
+
int status;
|
129
|
+
|
130
|
+
/* TODO document this */
|
131
|
+
assert(server->loop == client->loop);
|
132
|
+
|
133
|
+
saved_errno = errno;
|
134
|
+
status = -1;
|
135
|
+
|
136
|
+
streamServer = (uv_stream_t*)server;
|
137
|
+
streamClient = (uv_stream_t*)client;
|
138
|
+
|
139
|
+
if (streamServer->accepted_fd < 0) {
|
140
|
+
uv_err_new(server->loop, EAGAIN);
|
141
|
+
goto out;
|
142
|
+
}
|
143
|
+
|
144
|
+
if (uv__stream_open(streamClient, streamServer->accepted_fd,
|
145
|
+
UV_READABLE | UV_WRITABLE)) {
|
146
|
+
/* TODO handle error */
|
147
|
+
streamServer->accepted_fd = -1;
|
148
|
+
uv__close(streamServer->accepted_fd);
|
149
|
+
goto out;
|
150
|
+
}
|
151
|
+
|
152
|
+
ev_io_start(streamServer->loop->ev, &streamServer->read_watcher);
|
153
|
+
streamServer->accepted_fd = -1;
|
154
|
+
status = 0;
|
155
|
+
|
156
|
+
out:
|
157
|
+
errno = saved_errno;
|
158
|
+
return status;
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
|
163
|
+
switch (stream->type) {
|
164
|
+
case UV_TCP:
|
165
|
+
return uv_tcp_listen((uv_tcp_t*)stream, backlog, cb);
|
166
|
+
case UV_NAMED_PIPE:
|
167
|
+
return uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
|
168
|
+
default:
|
169
|
+
assert(0);
|
170
|
+
return -1;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
uv_write_t* uv_write_queue_head(uv_stream_t* stream) {
|
176
|
+
ngx_queue_t* q;
|
177
|
+
uv_write_t* req;
|
178
|
+
|
179
|
+
if (ngx_queue_empty(&stream->write_queue)) {
|
180
|
+
return NULL;
|
181
|
+
}
|
182
|
+
|
183
|
+
q = ngx_queue_head(&stream->write_queue);
|
184
|
+
if (!q) {
|
185
|
+
return NULL;
|
186
|
+
}
|
187
|
+
|
188
|
+
req = ngx_queue_data(q, struct uv_write_s, queue);
|
189
|
+
assert(req);
|
190
|
+
|
191
|
+
return req;
|
192
|
+
}
|
193
|
+
|
194
|
+
|
195
|
+
static void uv__drain(uv_stream_t* stream) {
|
196
|
+
uv_shutdown_t* req;
|
197
|
+
|
198
|
+
assert(!uv_write_queue_head(stream));
|
199
|
+
assert(stream->write_queue_size == 0);
|
200
|
+
|
201
|
+
ev_io_stop(stream->loop->ev, &stream->write_watcher);
|
202
|
+
|
203
|
+
/* Shutdown? */
|
204
|
+
if ((stream->flags & UV_SHUTTING) &&
|
205
|
+
!(stream->flags & UV_CLOSING) &&
|
206
|
+
!(stream->flags & UV_SHUT)) {
|
207
|
+
assert(stream->shutdown_req);
|
208
|
+
|
209
|
+
req = stream->shutdown_req;
|
210
|
+
|
211
|
+
if (shutdown(stream->fd, SHUT_WR)) {
|
212
|
+
/* Error. Report it. User should call uv_close(). */
|
213
|
+
uv_err_new(stream->loop, errno);
|
214
|
+
if (req->cb) {
|
215
|
+
req->cb(req, -1);
|
216
|
+
}
|
217
|
+
} else {
|
218
|
+
uv_err_new(stream->loop, 0);
|
219
|
+
((uv_handle_t*) stream)->flags |= UV_SHUT;
|
220
|
+
if (req->cb) {
|
221
|
+
req->cb(req, 0);
|
222
|
+
}
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
/* On success returns NULL. On error returns a pointer to the write request
|
229
|
+
* which had the error.
|
230
|
+
*/
|
231
|
+
static uv_write_t* uv__write(uv_stream_t* stream) {
|
232
|
+
uv_write_t* req;
|
233
|
+
struct iovec* iov;
|
234
|
+
int iovcnt;
|
235
|
+
ssize_t n;
|
236
|
+
|
237
|
+
assert(stream->fd >= 0);
|
238
|
+
|
239
|
+
/* TODO: should probably while(1) here until EAGAIN */
|
240
|
+
|
241
|
+
/* Get the request at the head of the queue. */
|
242
|
+
req = uv_write_queue_head(stream);
|
243
|
+
if (!req) {
|
244
|
+
assert(stream->write_queue_size == 0);
|
245
|
+
return NULL;
|
246
|
+
}
|
247
|
+
|
248
|
+
assert(req->handle == stream);
|
249
|
+
|
250
|
+
/* Cast to iovec. We had to have our own uv_buf_t instead of iovec
|
251
|
+
* because Windows's WSABUF is not an iovec.
|
252
|
+
*/
|
253
|
+
assert(sizeof(uv_buf_t) == sizeof(struct iovec));
|
254
|
+
iov = (struct iovec*) &(req->bufs[req->write_index]);
|
255
|
+
iovcnt = req->bufcnt - req->write_index;
|
256
|
+
|
257
|
+
/* Now do the actual writev. Note that we've been updating the pointers
|
258
|
+
* inside the iov each time we write. So there is no need to offset it.
|
259
|
+
*/
|
260
|
+
|
261
|
+
do {
|
262
|
+
if (iovcnt == 1) {
|
263
|
+
n = write(stream->fd, iov[0].iov_base, iov[0].iov_len);
|
264
|
+
} else {
|
265
|
+
n = writev(stream->fd, iov, iovcnt);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
while (n == -1 && errno == EINTR);
|
269
|
+
|
270
|
+
if (n < 0) {
|
271
|
+
if (errno != EAGAIN) {
|
272
|
+
/* Error */
|
273
|
+
uv_err_new(stream->loop, errno);
|
274
|
+
return req;
|
275
|
+
}
|
276
|
+
} else {
|
277
|
+
/* Successful write */
|
278
|
+
|
279
|
+
/* Update the counters. */
|
280
|
+
while (n >= 0) {
|
281
|
+
uv_buf_t* buf = &(req->bufs[req->write_index]);
|
282
|
+
size_t len = buf->len;
|
283
|
+
|
284
|
+
assert(req->write_index < req->bufcnt);
|
285
|
+
|
286
|
+
if ((size_t)n < len) {
|
287
|
+
buf->base += n;
|
288
|
+
buf->len -= n;
|
289
|
+
stream->write_queue_size -= n;
|
290
|
+
n = 0;
|
291
|
+
|
292
|
+
/* There is more to write. Break and ensure the watcher is pending. */
|
293
|
+
break;
|
294
|
+
|
295
|
+
} else {
|
296
|
+
/* Finished writing the buf at index req->write_index. */
|
297
|
+
req->write_index++;
|
298
|
+
|
299
|
+
assert((size_t)n >= len);
|
300
|
+
n -= len;
|
301
|
+
|
302
|
+
assert(stream->write_queue_size >= len);
|
303
|
+
stream->write_queue_size -= len;
|
304
|
+
|
305
|
+
if (req->write_index == req->bufcnt) {
|
306
|
+
/* Then we're done! */
|
307
|
+
assert(n == 0);
|
308
|
+
|
309
|
+
/* Pop the req off tcp->write_queue. */
|
310
|
+
ngx_queue_remove(&req->queue);
|
311
|
+
if (req->bufs != req->bufsml) {
|
312
|
+
free(req->bufs);
|
313
|
+
}
|
314
|
+
req->bufs = NULL;
|
315
|
+
|
316
|
+
/* Add it to the write_completed_queue where it will have its
|
317
|
+
* callback called in the near future.
|
318
|
+
* TODO: start trying to write the next request.
|
319
|
+
*/
|
320
|
+
ngx_queue_insert_tail(&stream->write_completed_queue, &req->queue);
|
321
|
+
ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE);
|
322
|
+
return NULL;
|
323
|
+
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
/* Either we've counted n down to zero or we've got EAGAIN. */
|
329
|
+
assert(n == 0 || n == -1);
|
330
|
+
|
331
|
+
/* We're not done. */
|
332
|
+
ev_io_start(stream->loop->ev, &stream->write_watcher);
|
333
|
+
|
334
|
+
return NULL;
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
static void uv__write_callbacks(uv_stream_t* stream) {
|
339
|
+
int callbacks_made = 0;
|
340
|
+
ngx_queue_t* q;
|
341
|
+
uv_write_t* req;
|
342
|
+
|
343
|
+
while (!ngx_queue_empty(&stream->write_completed_queue)) {
|
344
|
+
/* Pop a req off write_completed_queue. */
|
345
|
+
q = ngx_queue_head(&stream->write_completed_queue);
|
346
|
+
assert(q);
|
347
|
+
req = ngx_queue_data(q, struct uv_write_s, queue);
|
348
|
+
ngx_queue_remove(q);
|
349
|
+
|
350
|
+
/* NOTE: call callback AFTER freeing the request data. */
|
351
|
+
if (req->cb) {
|
352
|
+
req->cb(req, 0);
|
353
|
+
}
|
354
|
+
|
355
|
+
callbacks_made++;
|
356
|
+
}
|
357
|
+
|
358
|
+
assert(ngx_queue_empty(&stream->write_completed_queue));
|
359
|
+
|
360
|
+
/* Write queue drained. */
|
361
|
+
if (!uv_write_queue_head(stream)) {
|
362
|
+
uv__drain(stream);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
|
366
|
+
|
367
|
+
static void uv__read(uv_stream_t* stream) {
|
368
|
+
uv_buf_t buf;
|
369
|
+
ssize_t nread;
|
370
|
+
struct ev_loop* ev = stream->loop->ev;
|
371
|
+
|
372
|
+
/* XXX: Maybe instead of having UV_READING we just test if
|
373
|
+
* tcp->read_cb is NULL or not?
|
374
|
+
*/
|
375
|
+
while (stream->read_cb && ((uv_handle_t*)stream)->flags & UV_READING) {
|
376
|
+
assert(stream->alloc_cb);
|
377
|
+
buf = stream->alloc_cb((uv_handle_t*)stream, 64 * 1024);
|
378
|
+
|
379
|
+
assert(buf.len > 0);
|
380
|
+
assert(buf.base);
|
381
|
+
assert(stream->fd >= 0);
|
382
|
+
|
383
|
+
do {
|
384
|
+
nread = read(stream->fd, buf.base, buf.len);
|
385
|
+
}
|
386
|
+
while (nread < 0 && errno == EINTR);
|
387
|
+
|
388
|
+
if (nread < 0) {
|
389
|
+
/* Error */
|
390
|
+
if (errno == EAGAIN) {
|
391
|
+
/* Wait for the next one. */
|
392
|
+
if (stream->flags & UV_READING) {
|
393
|
+
ev_io_start(ev, &stream->read_watcher);
|
394
|
+
}
|
395
|
+
uv_err_new(stream->loop, EAGAIN);
|
396
|
+
stream->read_cb(stream, 0, buf);
|
397
|
+
return;
|
398
|
+
} else {
|
399
|
+
/* Error. User should call uv_close(). */
|
400
|
+
uv_err_new(stream->loop, errno);
|
401
|
+
stream->read_cb(stream, -1, buf);
|
402
|
+
assert(!ev_is_active(&stream->read_watcher));
|
403
|
+
return;
|
404
|
+
}
|
405
|
+
} else if (nread == 0) {
|
406
|
+
/* EOF */
|
407
|
+
uv_err_new_artificial(stream->loop, UV_EOF);
|
408
|
+
ev_io_stop(ev, &stream->read_watcher);
|
409
|
+
stream->read_cb(stream, -1, buf);
|
410
|
+
return;
|
411
|
+
} else {
|
412
|
+
/* Successful read */
|
413
|
+
stream->read_cb(stream, nread, buf);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
|
419
|
+
int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
|
420
|
+
assert((stream->type == UV_TCP || stream->type == UV_NAMED_PIPE) &&
|
421
|
+
"uv_shutdown (unix) only supports uv_handle_t right now");
|
422
|
+
assert(stream->fd >= 0);
|
423
|
+
|
424
|
+
if (!(stream->flags & UV_WRITABLE) ||
|
425
|
+
stream->flags & UV_SHUT ||
|
426
|
+
stream->flags & UV_CLOSED ||
|
427
|
+
stream->flags & UV_CLOSING) {
|
428
|
+
uv_err_new(stream->loop, EINVAL);
|
429
|
+
return -1;
|
430
|
+
}
|
431
|
+
|
432
|
+
/* Initialize request */
|
433
|
+
uv__req_init((uv_req_t*)req);
|
434
|
+
req->handle = stream;
|
435
|
+
req->cb = cb;
|
436
|
+
|
437
|
+
stream->shutdown_req = req;
|
438
|
+
req->type = UV_SHUTDOWN;
|
439
|
+
|
440
|
+
((uv_handle_t*)stream)->flags |= UV_SHUTTING;
|
441
|
+
|
442
|
+
|
443
|
+
ev_io_start(stream->loop->ev, &stream->write_watcher);
|
444
|
+
|
445
|
+
return 0;
|
446
|
+
}
|
447
|
+
|
448
|
+
|
449
|
+
void uv__stream_io(EV_P_ ev_io* watcher, int revents) {
|
450
|
+
uv_stream_t* stream = watcher->data;
|
451
|
+
|
452
|
+
assert(stream->type == UV_TCP ||
|
453
|
+
stream->type == UV_NAMED_PIPE);
|
454
|
+
assert(watcher == &stream->read_watcher ||
|
455
|
+
watcher == &stream->write_watcher);
|
456
|
+
assert(!(stream->flags & UV_CLOSING));
|
457
|
+
|
458
|
+
if (stream->connect_req) {
|
459
|
+
uv__stream_connect(stream);
|
460
|
+
} else {
|
461
|
+
assert(revents & (EV_READ | EV_WRITE));
|
462
|
+
assert(stream->fd >= 0);
|
463
|
+
|
464
|
+
if (revents & EV_READ) {
|
465
|
+
uv__read((uv_stream_t*)stream);
|
466
|
+
}
|
467
|
+
|
468
|
+
if (revents & EV_WRITE) {
|
469
|
+
uv_write_t* req = uv__write(stream);
|
470
|
+
if (req) {
|
471
|
+
/* Error. Notify the user. */
|
472
|
+
if (req->cb) {
|
473
|
+
req->cb(req, -1);
|
474
|
+
}
|
475
|
+
} else {
|
476
|
+
uv__write_callbacks(stream);
|
477
|
+
}
|
478
|
+
}
|
479
|
+
}
|
480
|
+
}
|
481
|
+
|
482
|
+
|
483
|
+
/**
|
484
|
+
* We get called here from directly following a call to connect(2).
|
485
|
+
* In order to determine if we've errored out or succeeded must call
|
486
|
+
* getsockopt.
|
487
|
+
*/
|
488
|
+
static void uv__stream_connect(uv_stream_t* stream) {
|
489
|
+
int error;
|
490
|
+
uv_connect_t* req = stream->connect_req;
|
491
|
+
socklen_t errorsize = sizeof(int);
|
492
|
+
|
493
|
+
assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE);
|
494
|
+
assert(req);
|
495
|
+
|
496
|
+
if (stream->delayed_error) {
|
497
|
+
/* To smooth over the differences between unixes errors that
|
498
|
+
* were reported synchronously on the first connect can be delayed
|
499
|
+
* until the next tick--which is now.
|
500
|
+
*/
|
501
|
+
error = stream->delayed_error;
|
502
|
+
stream->delayed_error = 0;
|
503
|
+
} else {
|
504
|
+
/* Normal situation: we need to get the socket error from the kernel. */
|
505
|
+
assert(stream->fd >= 0);
|
506
|
+
getsockopt(stream->fd, SOL_SOCKET, SO_ERROR, &error, &errorsize);
|
507
|
+
}
|
508
|
+
|
509
|
+
if (!error) {
|
510
|
+
ev_io_start(stream->loop->ev, &stream->read_watcher);
|
511
|
+
|
512
|
+
/* Successful connection */
|
513
|
+
stream->connect_req = NULL;
|
514
|
+
if (req->cb) {
|
515
|
+
req->cb(req, 0);
|
516
|
+
}
|
517
|
+
|
518
|
+
} else if (error == EINPROGRESS) {
|
519
|
+
/* Still connecting. */
|
520
|
+
return;
|
521
|
+
} else {
|
522
|
+
/* Error */
|
523
|
+
uv_err_new(stream->loop, error);
|
524
|
+
|
525
|
+
stream->connect_req = NULL;
|
526
|
+
if (req->cb) {
|
527
|
+
req->cb(req, -1);
|
528
|
+
}
|
529
|
+
}
|
530
|
+
}
|
531
|
+
|
532
|
+
|
533
|
+
int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
|
534
|
+
socklen_t addrlen, uv_connect_cb cb) {
|
535
|
+
int sockfd;
|
536
|
+
int r;
|
537
|
+
|
538
|
+
if (stream->fd <= 0) {
|
539
|
+
if ((sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0)) == -1) {
|
540
|
+
uv_err_new(stream->loop, errno);
|
541
|
+
return -1;
|
542
|
+
}
|
543
|
+
|
544
|
+
if (uv__stream_open(stream, sockfd, UV_READABLE | UV_WRITABLE)) {
|
545
|
+
uv__close(sockfd);
|
546
|
+
return -2;
|
547
|
+
}
|
548
|
+
}
|
549
|
+
|
550
|
+
uv__req_init((uv_req_t*)req);
|
551
|
+
req->cb = cb;
|
552
|
+
req->handle = stream;
|
553
|
+
req->type = UV_CONNECT;
|
554
|
+
ngx_queue_init(&req->queue);
|
555
|
+
|
556
|
+
if (stream->connect_req) {
|
557
|
+
uv_err_new(stream->loop, EALREADY);
|
558
|
+
return -1;
|
559
|
+
}
|
560
|
+
|
561
|
+
if (stream->type != UV_TCP) {
|
562
|
+
uv_err_new(stream->loop, ENOTSOCK);
|
563
|
+
return -1;
|
564
|
+
}
|
565
|
+
|
566
|
+
stream->connect_req = req;
|
567
|
+
|
568
|
+
do {
|
569
|
+
r = connect(stream->fd, addr, addrlen);
|
570
|
+
}
|
571
|
+
while (r == -1 && errno == EINTR);
|
572
|
+
|
573
|
+
stream->delayed_error = 0;
|
574
|
+
|
575
|
+
if (r != 0 && errno != EINPROGRESS) {
|
576
|
+
switch (errno) {
|
577
|
+
/* If we get a ECONNREFUSED wait until the next tick to report the
|
578
|
+
* error. Solaris wants to report immediately--other unixes want to
|
579
|
+
* wait.
|
580
|
+
*/
|
581
|
+
case ECONNREFUSED:
|
582
|
+
stream->delayed_error = errno;
|
583
|
+
break;
|
584
|
+
|
585
|
+
default:
|
586
|
+
uv_err_new(stream->loop, errno);
|
587
|
+
return -1;
|
588
|
+
}
|
589
|
+
}
|
590
|
+
|
591
|
+
assert(stream->write_watcher.data == stream);
|
592
|
+
ev_io_start(stream->loop->ev, &stream->write_watcher);
|
593
|
+
|
594
|
+
if (stream->delayed_error) {
|
595
|
+
ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE);
|
596
|
+
}
|
597
|
+
|
598
|
+
return 0;
|
599
|
+
}
|
600
|
+
|
601
|
+
|
602
|
+
/* The buffers to be written must remain valid until the callback is called.
|
603
|
+
* This is not required for the uv_buf_t array.
|
604
|
+
*/
|
605
|
+
int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt,
|
606
|
+
uv_write_cb cb) {
|
607
|
+
uv_stream_t* stream;
|
608
|
+
int empty_queue;
|
609
|
+
|
610
|
+
stream = (uv_stream_t*)handle;
|
611
|
+
|
612
|
+
/* Initialize the req */
|
613
|
+
uv__req_init((uv_req_t*) req);
|
614
|
+
req->cb = cb;
|
615
|
+
req->handle = handle;
|
616
|
+
ngx_queue_init(&req->queue);
|
617
|
+
|
618
|
+
assert((handle->type == UV_TCP || handle->type == UV_NAMED_PIPE)
|
619
|
+
&& "uv_write (unix) does not yet support other types of streams");
|
620
|
+
|
621
|
+
empty_queue = (stream->write_queue_size == 0);
|
622
|
+
|
623
|
+
if (stream->fd < 0) {
|
624
|
+
uv_err_new(stream->loop, EBADF);
|
625
|
+
return -1;
|
626
|
+
}
|
627
|
+
|
628
|
+
ngx_queue_init(&req->queue);
|
629
|
+
req->type = UV_WRITE;
|
630
|
+
|
631
|
+
|
632
|
+
if (bufcnt < UV_REQ_BUFSML_SIZE) {
|
633
|
+
req->bufs = req->bufsml;
|
634
|
+
}
|
635
|
+
else {
|
636
|
+
req->bufs = malloc(sizeof(uv_buf_t) * bufcnt);
|
637
|
+
}
|
638
|
+
|
639
|
+
memcpy(req->bufs, bufs, bufcnt * sizeof(uv_buf_t));
|
640
|
+
req->bufcnt = bufcnt;
|
641
|
+
|
642
|
+
/*
|
643
|
+
* fprintf(stderr, "cnt: %d bufs: %p bufsml: %p\n", bufcnt, req->bufs, req->bufsml);
|
644
|
+
*/
|
645
|
+
|
646
|
+
req->write_index = 0;
|
647
|
+
stream->write_queue_size += uv__buf_count(bufs, bufcnt);
|
648
|
+
|
649
|
+
/* Append the request to write_queue. */
|
650
|
+
ngx_queue_insert_tail(&stream->write_queue, &req->queue);
|
651
|
+
|
652
|
+
assert(!ngx_queue_empty(&stream->write_queue));
|
653
|
+
assert(stream->write_watcher.cb == uv__stream_io);
|
654
|
+
assert(stream->write_watcher.data == stream);
|
655
|
+
assert(stream->write_watcher.fd == stream->fd);
|
656
|
+
|
657
|
+
/* If the queue was empty when this function began, we should attempt to
|
658
|
+
* do the write immediately. Otherwise start the write_watcher and wait
|
659
|
+
* for the fd to become writable.
|
660
|
+
*/
|
661
|
+
if (empty_queue) {
|
662
|
+
if (uv__write(stream)) {
|
663
|
+
/* Error. uv_last_error has been set. */
|
664
|
+
return -1;
|
665
|
+
}
|
666
|
+
}
|
667
|
+
|
668
|
+
/* If the queue is now empty - we've flushed the request already. That
|
669
|
+
* means we need to make the callback. The callback can only be done on a
|
670
|
+
* fresh stack so we feed the event loop in order to service it.
|
671
|
+
*/
|
672
|
+
if (ngx_queue_empty(&stream->write_queue)) {
|
673
|
+
ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE);
|
674
|
+
} else {
|
675
|
+
/* Otherwise there is data to write - so we should wait for the file
|
676
|
+
* descriptor to become writable.
|
677
|
+
*/
|
678
|
+
ev_io_start(stream->loop->ev, &stream->write_watcher);
|
679
|
+
}
|
680
|
+
|
681
|
+
return 0;
|
682
|
+
}
|
683
|
+
|
684
|
+
|
685
|
+
int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) {
|
686
|
+
assert(stream->type == UV_TCP || stream->type == UV_NAMED_PIPE);
|
687
|
+
|
688
|
+
if (stream->flags & UV_CLOSING) {
|
689
|
+
uv_err_new(stream->loop, EINVAL);
|
690
|
+
return -1;
|
691
|
+
}
|
692
|
+
|
693
|
+
/* The UV_READING flag is irrelevant of the state of the tcp - it just
|
694
|
+
* expresses the desired state of the user.
|
695
|
+
*/
|
696
|
+
((uv_handle_t*)stream)->flags |= UV_READING;
|
697
|
+
|
698
|
+
/* TODO: try to do the read inline? */
|
699
|
+
/* TODO: keep track of tcp state. If we've gotten a EOF then we should
|
700
|
+
* not start the IO watcher.
|
701
|
+
*/
|
702
|
+
assert(stream->fd >= 0);
|
703
|
+
assert(alloc_cb);
|
704
|
+
|
705
|
+
stream->read_cb = read_cb;
|
706
|
+
stream->alloc_cb = alloc_cb;
|
707
|
+
|
708
|
+
/* These should have been set by uv_tcp_init. */
|
709
|
+
assert(stream->read_watcher.cb == uv__stream_io);
|
710
|
+
|
711
|
+
ev_io_start(stream->loop->ev, &stream->read_watcher);
|
712
|
+
return 0;
|
713
|
+
}
|
714
|
+
|
715
|
+
|
716
|
+
int uv_read_stop(uv_stream_t* stream) {
|
717
|
+
uv_tcp_t* tcp = (uv_tcp_t*)stream;
|
718
|
+
|
719
|
+
((uv_handle_t*)tcp)->flags &= ~UV_READING;
|
720
|
+
|
721
|
+
ev_io_stop(tcp->loop->ev, &tcp->read_watcher);
|
722
|
+
tcp->read_cb = NULL;
|
723
|
+
tcp->alloc_cb = NULL;
|
724
|
+
return 0;
|
725
|
+
}
|
726
|
+
|
727
|
+
|