noderb 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -25,271 +25,93 @@
|
|
|
25
25
|
#include "../uv-common.h"
|
|
26
26
|
#include "internal.h"
|
|
27
27
|
|
|
28
|
+
|
|
28
29
|
/*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* Threshold of active tcp streams for which to preallocate tcp read buffers.
|
|
31
|
+
* (Due to node slab allocator performing poorly under this pattern,
|
|
32
|
+
* the optimization is temporarily disabled (threshold=0). This will be
|
|
33
|
+
* revisited once node allocator is improved.)
|
|
31
34
|
*/
|
|
32
|
-
|
|
33
|
-
# define WSAID_ACCEPTEX \
|
|
34
|
-
{0xb5367df1, 0xcbac, 0x11cf, \
|
|
35
|
-
{0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
|
|
36
|
-
|
|
37
|
-
# define WSAID_CONNECTEX \
|
|
38
|
-
{0x25a207b9, 0xddf3, 0x4660, \
|
|
39
|
-
{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}}
|
|
40
|
-
|
|
41
|
-
# define WSAID_GETACCEPTEXSOCKADDRS \
|
|
42
|
-
{0xb5367df2, 0xcbac, 0x11cf, \
|
|
43
|
-
{0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
|
|
44
|
-
|
|
45
|
-
# define WSAID_DISCONNECTEX \
|
|
46
|
-
{0x7fda2e11, 0x8630, 0x436f, \
|
|
47
|
-
{0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}
|
|
48
|
-
|
|
49
|
-
# define WSAID_TRANSMITFILE \
|
|
50
|
-
{0xb5367df0, 0xcbac, 0x11cf, \
|
|
51
|
-
{0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
|
|
52
|
-
|
|
53
|
-
typedef BOOL PASCAL (*LPFN_ACCEPTEX)
|
|
54
|
-
(SOCKET sListenSocket,
|
|
55
|
-
SOCKET sAcceptSocket,
|
|
56
|
-
PVOID lpOutputBuffer,
|
|
57
|
-
DWORD dwReceiveDataLength,
|
|
58
|
-
DWORD dwLocalAddressLength,
|
|
59
|
-
DWORD dwRemoteAddressLength,
|
|
60
|
-
LPDWORD lpdwBytesReceived,
|
|
61
|
-
LPOVERLAPPED lpOverlapped);
|
|
62
|
-
|
|
63
|
-
typedef BOOL PASCAL (*LPFN_CONNECTEX)
|
|
64
|
-
(SOCKET s,
|
|
65
|
-
const struct sockaddr* name,
|
|
66
|
-
int namelen,
|
|
67
|
-
PVOID lpSendBuffer,
|
|
68
|
-
DWORD dwSendDataLength,
|
|
69
|
-
LPDWORD lpdwBytesSent,
|
|
70
|
-
LPOVERLAPPED lpOverlapped);
|
|
71
|
-
|
|
72
|
-
typedef void PASCAL (*LPFN_GETACCEPTEXSOCKADDRS)
|
|
73
|
-
(PVOID lpOutputBuffer,
|
|
74
|
-
DWORD dwReceiveDataLength,
|
|
75
|
-
DWORD dwLocalAddressLength,
|
|
76
|
-
DWORD dwRemoteAddressLength,
|
|
77
|
-
LPSOCKADDR* LocalSockaddr,
|
|
78
|
-
LPINT LocalSockaddrLength,
|
|
79
|
-
LPSOCKADDR* RemoteSockaddr,
|
|
80
|
-
LPINT RemoteSockaddrLength);
|
|
81
|
-
|
|
82
|
-
typedef BOOL PASCAL (*LPFN_DISCONNECTEX)
|
|
83
|
-
(SOCKET hSocket,
|
|
84
|
-
LPOVERLAPPED lpOverlapped,
|
|
85
|
-
DWORD dwFlags,
|
|
86
|
-
DWORD reserved);
|
|
87
|
-
|
|
88
|
-
typedef BOOL PASCAL (*LPFN_TRANSMITFILE)
|
|
89
|
-
(SOCKET hSocket,
|
|
90
|
-
HANDLE hFile,
|
|
91
|
-
DWORD nNumberOfBytesToWrite,
|
|
92
|
-
DWORD nNumberOfBytesPerSend,
|
|
93
|
-
LPOVERLAPPED lpOverlapped,
|
|
94
|
-
LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
|
|
95
|
-
DWORD dwFlags);
|
|
96
|
-
#endif
|
|
35
|
+
const unsigned int uv_active_tcp_streams_threshold = 0;
|
|
97
36
|
|
|
98
37
|
/*
|
|
99
|
-
*
|
|
38
|
+
* Number of simultaneous pending AcceptEx calls.
|
|
100
39
|
*/
|
|
101
|
-
|
|
102
|
-
# define SO_UPDATE_CONNECT_CONTEXT 0x7010
|
|
103
|
-
#endif
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
/* Pointers to winsock extension functions to be retrieved dynamically */
|
|
107
|
-
static LPFN_CONNECTEX pConnectEx;
|
|
108
|
-
static LPFN_ACCEPTEX pAcceptEx;
|
|
109
|
-
static LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs;
|
|
110
|
-
static LPFN_DISCONNECTEX pDisconnectEx;
|
|
111
|
-
static LPFN_TRANSMITFILE pTransmitFile;
|
|
112
|
-
|
|
113
|
-
/* IPv6 version of these extension functions */
|
|
114
|
-
static LPFN_CONNECTEX pConnectEx6;
|
|
115
|
-
static LPFN_ACCEPTEX pAcceptEx6;
|
|
116
|
-
static LPFN_GETACCEPTEXSOCKADDRS pGetAcceptExSockAddrs6;
|
|
117
|
-
static LPFN_DISCONNECTEX pDisconnectEx6;
|
|
118
|
-
static LPFN_TRANSMITFILE pTransmitFile6;
|
|
119
|
-
|
|
120
|
-
/* Ip address used to bind to any port at any interface */
|
|
121
|
-
static struct sockaddr_in uv_addr_ip4_any_;
|
|
122
|
-
static struct sockaddr_in6 uv_addr_ip6_any_;
|
|
40
|
+
const unsigned int uv_simultaneous_server_accepts = 32;
|
|
123
41
|
|
|
124
42
|
/* A zero-size buffer for use by uv_tcp_read */
|
|
125
43
|
static char uv_zero_[] = "";
|
|
126
44
|
|
|
127
|
-
/*
|
|
128
|
-
static
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
/*
|
|
132
|
-
* Retrieves the pointer to a winsock extension function.
|
|
133
|
-
*/
|
|
134
|
-
static BOOL uv_get_extension_function(SOCKET socket, GUID guid,
|
|
135
|
-
void **target) {
|
|
136
|
-
DWORD result, bytes;
|
|
137
|
-
|
|
138
|
-
result = WSAIoctl(socket,
|
|
139
|
-
SIO_GET_EXTENSION_FUNCTION_POINTER,
|
|
140
|
-
&guid,
|
|
141
|
-
sizeof(guid),
|
|
142
|
-
(void*)target,
|
|
143
|
-
sizeof(*target),
|
|
144
|
-
&bytes,
|
|
145
|
-
NULL,
|
|
146
|
-
NULL);
|
|
147
|
-
|
|
148
|
-
if (result == SOCKET_ERROR) {
|
|
149
|
-
*target = NULL;
|
|
150
|
-
return FALSE;
|
|
151
|
-
} else {
|
|
152
|
-
return TRUE;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
45
|
+
/* Counter to keep track of active tcp streams */
|
|
46
|
+
static unsigned int active_tcp_streams = 0;
|
|
156
47
|
|
|
157
|
-
/*
|
|
158
|
-
* Setup tcp subsystem
|
|
159
|
-
*/
|
|
160
|
-
void uv_winsock_startup() {
|
|
161
|
-
const GUID wsaid_connectex = WSAID_CONNECTEX;
|
|
162
|
-
const GUID wsaid_acceptex = WSAID_ACCEPTEX;
|
|
163
|
-
const GUID wsaid_getacceptexsockaddrs = WSAID_GETACCEPTEXSOCKADDRS;
|
|
164
|
-
const GUID wsaid_disconnectex = WSAID_DISCONNECTEX;
|
|
165
|
-
const GUID wsaid_transmitfile = WSAID_TRANSMITFILE;
|
|
166
|
-
|
|
167
|
-
WSADATA wsa_data;
|
|
168
|
-
int errorno;
|
|
169
|
-
SOCKET dummy;
|
|
170
|
-
SOCKET dummy6;
|
|
171
|
-
|
|
172
|
-
/* Initialize winsock */
|
|
173
|
-
errorno = WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
|
174
|
-
if (errorno != 0) {
|
|
175
|
-
uv_fatal_error(errorno, "WSAStartup");
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/* Set implicit binding address used by connectEx */
|
|
179
|
-
uv_addr_ip4_any_ = uv_ip4_addr("0.0.0.0", 0);
|
|
180
|
-
uv_addr_ip6_any_ = uv_ip6_addr("::1", 0);
|
|
181
|
-
|
|
182
|
-
/* Retrieve the needed winsock extension function pointers. */
|
|
183
|
-
dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
|
184
|
-
if (dummy == INVALID_SOCKET) {
|
|
185
|
-
uv_fatal_error(WSAGetLastError(), "socket");
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (!uv_get_extension_function(dummy,
|
|
189
|
-
wsaid_connectex,
|
|
190
|
-
(void**)&pConnectEx) ||
|
|
191
|
-
!uv_get_extension_function(dummy,
|
|
192
|
-
wsaid_acceptex,
|
|
193
|
-
(void**)&pAcceptEx) ||
|
|
194
|
-
!uv_get_extension_function(dummy,
|
|
195
|
-
wsaid_getacceptexsockaddrs,
|
|
196
|
-
(void**)&pGetAcceptExSockAddrs) ||
|
|
197
|
-
!uv_get_extension_function(dummy,
|
|
198
|
-
wsaid_disconnectex,
|
|
199
|
-
(void**)&pDisconnectEx) ||
|
|
200
|
-
!uv_get_extension_function(dummy,
|
|
201
|
-
wsaid_transmitfile,
|
|
202
|
-
(void**)&pTransmitFile)) {
|
|
203
|
-
uv_fatal_error(WSAGetLastError(),
|
|
204
|
-
"WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER)");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (closesocket(dummy) == SOCKET_ERROR) {
|
|
208
|
-
uv_fatal_error(WSAGetLastError(), "closesocket");
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/* optional IPv6 versions of winsock extension functions */
|
|
212
|
-
dummy6 = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP);
|
|
213
|
-
if (dummy6 != INVALID_SOCKET) {
|
|
214
|
-
uv_allow_ipv6 = TRUE;
|
|
215
|
-
|
|
216
|
-
if (!uv_get_extension_function(dummy6,
|
|
217
|
-
wsaid_connectex,
|
|
218
|
-
(void**)&pConnectEx6) ||
|
|
219
|
-
!uv_get_extension_function(dummy6,
|
|
220
|
-
wsaid_acceptex,
|
|
221
|
-
(void**)&pAcceptEx6) ||
|
|
222
|
-
!uv_get_extension_function(dummy6,
|
|
223
|
-
wsaid_getacceptexsockaddrs,
|
|
224
|
-
(void**)&pGetAcceptExSockAddrs6) ||
|
|
225
|
-
!uv_get_extension_function(dummy6,
|
|
226
|
-
wsaid_disconnectex,
|
|
227
|
-
(void**)&pDisconnectEx6) ||
|
|
228
|
-
!uv_get_extension_function(dummy6,
|
|
229
|
-
wsaid_transmitfile,
|
|
230
|
-
(void**)&pTransmitFile6)) {
|
|
231
|
-
uv_allow_ipv6 = FALSE;
|
|
232
|
-
}
|
|
233
48
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
static int uv_tcp_set_socket(uv_tcp_t* handle, SOCKET socket) {
|
|
49
|
+
static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle,
|
|
50
|
+
SOCKET socket) {
|
|
242
51
|
DWORD yes = 1;
|
|
243
52
|
|
|
244
53
|
assert(handle->socket == INVALID_SOCKET);
|
|
245
54
|
|
|
246
55
|
/* Set the socket to nonblocking mode */
|
|
247
56
|
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
|
|
248
|
-
uv_set_sys_error(WSAGetLastError());
|
|
57
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
249
58
|
return -1;
|
|
250
59
|
}
|
|
251
60
|
|
|
252
61
|
/* Make the socket non-inheritable */
|
|
253
62
|
if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) {
|
|
254
|
-
uv_set_sys_error(GetLastError());
|
|
63
|
+
uv_set_sys_error(loop, GetLastError());
|
|
255
64
|
return -1;
|
|
256
65
|
}
|
|
257
66
|
|
|
258
67
|
/* Associate it with the I/O completion port. */
|
|
259
68
|
/* Use uv_handle_t pointer as completion key. */
|
|
260
69
|
if (CreateIoCompletionPort((HANDLE)socket,
|
|
261
|
-
|
|
70
|
+
loop->iocp,
|
|
262
71
|
(ULONG_PTR)socket,
|
|
263
72
|
0) == NULL) {
|
|
264
|
-
uv_set_sys_error(GetLastError());
|
|
73
|
+
uv_set_sys_error(loop, GetLastError());
|
|
265
74
|
return -1;
|
|
266
75
|
}
|
|
267
76
|
|
|
77
|
+
if (pSetFileCompletionNotificationModes) {
|
|
78
|
+
if (pSetFileCompletionNotificationModes((HANDLE) socket,
|
|
79
|
+
FILE_SKIP_SET_EVENT_ON_HANDLE |
|
|
80
|
+
FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
|
|
81
|
+
handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
|
|
82
|
+
} else if (GetLastError() != ERROR_INVALID_FUNCTION) {
|
|
83
|
+
uv_set_sys_error(loop, GetLastError());
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
268
88
|
handle->socket = socket;
|
|
269
89
|
|
|
270
90
|
return 0;
|
|
271
91
|
}
|
|
272
92
|
|
|
273
93
|
|
|
274
|
-
int uv_tcp_init(uv_tcp_t* handle) {
|
|
275
|
-
uv_stream_init((uv_stream_t*)handle);
|
|
94
|
+
int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) {
|
|
95
|
+
uv_stream_init(loop, (uv_stream_t*)handle);
|
|
276
96
|
|
|
97
|
+
handle->accept_reqs = NULL;
|
|
98
|
+
handle->pending_accepts = NULL;
|
|
277
99
|
handle->socket = INVALID_SOCKET;
|
|
278
100
|
handle->type = UV_TCP;
|
|
279
101
|
handle->reqs_pending = 0;
|
|
280
|
-
handle->accept_socket = INVALID_SOCKET;
|
|
281
102
|
|
|
282
|
-
|
|
103
|
+
loop->counters.tcp_init++;
|
|
283
104
|
|
|
284
105
|
return 0;
|
|
285
106
|
}
|
|
286
107
|
|
|
287
108
|
|
|
288
|
-
void uv_tcp_endgame(uv_tcp_t* handle) {
|
|
109
|
+
void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
|
|
289
110
|
uv_err_t err;
|
|
290
111
|
int status;
|
|
291
112
|
|
|
292
|
-
if (handle->flags &
|
|
113
|
+
if (handle->flags & UV_HANDLE_CONNECTION &&
|
|
114
|
+
handle->flags & UV_HANDLE_SHUTTING &&
|
|
293
115
|
!(handle->flags & UV_HANDLE_SHUT) &&
|
|
294
116
|
handle->write_reqs_pending == 0) {
|
|
295
117
|
|
|
@@ -302,7 +124,7 @@ void uv_tcp_endgame(uv_tcp_t* handle) {
|
|
|
302
124
|
}
|
|
303
125
|
if (handle->shutdown_req->cb) {
|
|
304
126
|
if (status == -1) {
|
|
305
|
-
|
|
127
|
+
loop->last_error = err;
|
|
306
128
|
}
|
|
307
129
|
handle->shutdown_req->cb(handle->shutdown_req, status);
|
|
308
130
|
}
|
|
@@ -314,16 +136,24 @@ void uv_tcp_endgame(uv_tcp_t* handle) {
|
|
|
314
136
|
assert(!(handle->flags & UV_HANDLE_CLOSED));
|
|
315
137
|
handle->flags |= UV_HANDLE_CLOSED;
|
|
316
138
|
|
|
139
|
+
if (!(handle->flags & UV_HANDLE_CONNECTION) && handle->accept_reqs) {
|
|
140
|
+
free(handle->accept_reqs);
|
|
141
|
+
handle->accept_reqs = NULL;
|
|
142
|
+
}
|
|
143
|
+
|
|
317
144
|
if (handle->close_cb) {
|
|
318
145
|
handle->close_cb((uv_handle_t*)handle);
|
|
319
146
|
}
|
|
320
147
|
|
|
321
|
-
|
|
148
|
+
active_tcp_streams--;
|
|
149
|
+
|
|
150
|
+
uv_unref(loop);
|
|
322
151
|
}
|
|
323
152
|
}
|
|
324
153
|
|
|
325
154
|
|
|
326
|
-
static int uv__bind(uv_tcp_t* handle, int domain,
|
|
155
|
+
static int uv__bind(uv_loop_t* loop, uv_tcp_t* handle, int domain,
|
|
156
|
+
struct sockaddr* addr, int addrsize) {
|
|
327
157
|
DWORD err;
|
|
328
158
|
int r;
|
|
329
159
|
SOCKET sock;
|
|
@@ -331,11 +161,11 @@ static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int add
|
|
|
331
161
|
if (handle->socket == INVALID_SOCKET) {
|
|
332
162
|
sock = socket(domain, SOCK_STREAM, 0);
|
|
333
163
|
if (sock == INVALID_SOCKET) {
|
|
334
|
-
uv_set_sys_error(WSAGetLastError());
|
|
164
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
335
165
|
return -1;
|
|
336
166
|
}
|
|
337
167
|
|
|
338
|
-
if (uv_tcp_set_socket(handle, sock) == -1) {
|
|
168
|
+
if (uv_tcp_set_socket(loop, handle, sock) == -1) {
|
|
339
169
|
closesocket(sock);
|
|
340
170
|
return -1;
|
|
341
171
|
}
|
|
@@ -347,10 +177,10 @@ static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int add
|
|
|
347
177
|
err = WSAGetLastError();
|
|
348
178
|
if (err == WSAEADDRINUSE) {
|
|
349
179
|
/* Some errors are not to be reported until connect() or listen() */
|
|
350
|
-
handle->
|
|
180
|
+
handle->bind_error = uv_new_sys_error(err);
|
|
351
181
|
handle->flags |= UV_HANDLE_BIND_ERROR;
|
|
352
182
|
} else {
|
|
353
|
-
uv_set_sys_error(err);
|
|
183
|
+
uv_set_sys_error(loop, err);
|
|
354
184
|
return -1;
|
|
355
185
|
}
|
|
356
186
|
}
|
|
@@ -362,32 +192,46 @@ static int uv__bind(uv_tcp_t* handle, int domain, struct sockaddr* addr, int add
|
|
|
362
192
|
|
|
363
193
|
|
|
364
194
|
int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
|
|
195
|
+
uv_loop_t* loop = handle->loop;
|
|
196
|
+
|
|
365
197
|
if (addr.sin_family != AF_INET) {
|
|
366
|
-
uv_set_sys_error(WSAEFAULT);
|
|
198
|
+
uv_set_sys_error(loop, WSAEFAULT);
|
|
367
199
|
return -1;
|
|
368
200
|
}
|
|
369
201
|
|
|
370
|
-
return uv__bind(
|
|
202
|
+
return uv__bind(loop,
|
|
203
|
+
handle,
|
|
204
|
+
AF_INET,
|
|
205
|
+
(struct sockaddr*)&addr,
|
|
206
|
+
sizeof(struct sockaddr_in));
|
|
371
207
|
}
|
|
372
208
|
|
|
373
209
|
|
|
374
210
|
int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) {
|
|
211
|
+
uv_loop_t* loop = handle->loop;
|
|
212
|
+
|
|
375
213
|
if (addr.sin6_family != AF_INET6) {
|
|
376
|
-
uv_set_sys_error(WSAEFAULT);
|
|
214
|
+
uv_set_sys_error(loop, WSAEFAULT);
|
|
377
215
|
return -1;
|
|
378
216
|
}
|
|
217
|
+
|
|
379
218
|
if (uv_allow_ipv6) {
|
|
380
219
|
handle->flags |= UV_HANDLE_IPV6;
|
|
381
|
-
return uv__bind(
|
|
220
|
+
return uv__bind(loop,
|
|
221
|
+
handle,
|
|
222
|
+
AF_INET6,
|
|
223
|
+
(struct sockaddr*)&addr,
|
|
224
|
+
sizeof(struct sockaddr_in6));
|
|
225
|
+
|
|
382
226
|
} else {
|
|
383
|
-
|
|
227
|
+
uv_set_sys_error(loop, WSAEAFNOSUPPORT);
|
|
384
228
|
return -1;
|
|
385
229
|
}
|
|
386
230
|
}
|
|
387
231
|
|
|
388
232
|
|
|
389
|
-
static void uv_tcp_queue_accept(uv_tcp_t* handle) {
|
|
390
|
-
|
|
233
|
+
static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) {
|
|
234
|
+
uv_loop_t* loop = handle->loop;
|
|
391
235
|
BOOL success;
|
|
392
236
|
DWORD bytes;
|
|
393
237
|
SOCKET accept_socket;
|
|
@@ -395,10 +239,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle) {
|
|
|
395
239
|
LPFN_ACCEPTEX pAcceptExFamily;
|
|
396
240
|
|
|
397
241
|
assert(handle->flags & UV_HANDLE_LISTENING);
|
|
398
|
-
assert(
|
|
399
|
-
|
|
400
|
-
/* Prepare the uv_req structure. */
|
|
401
|
-
req = &handle->accept_req;
|
|
242
|
+
assert(req->accept_socket == INVALID_SOCKET);
|
|
402
243
|
|
|
403
244
|
/* choose family and extension function */
|
|
404
245
|
if ((handle->flags & UV_HANDLE_IPV6) != 0) {
|
|
@@ -412,8 +253,8 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle) {
|
|
|
412
253
|
/* Open a socket for the accepted connection. */
|
|
413
254
|
accept_socket = socket(family, SOCK_STREAM, 0);
|
|
414
255
|
if (accept_socket == INVALID_SOCKET) {
|
|
415
|
-
req
|
|
416
|
-
uv_insert_pending_req(req);
|
|
256
|
+
SET_REQ_ERROR(req, WSAGetLastError());
|
|
257
|
+
uv_insert_pending_req(loop, (uv_req_t*)req);
|
|
417
258
|
handle->reqs_pending++;
|
|
418
259
|
return;
|
|
419
260
|
}
|
|
@@ -423,30 +264,34 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle) {
|
|
|
423
264
|
|
|
424
265
|
success = pAcceptExFamily(handle->socket,
|
|
425
266
|
accept_socket,
|
|
426
|
-
(void*)
|
|
267
|
+
(void*)req->accept_buffer,
|
|
427
268
|
0,
|
|
428
269
|
sizeof(struct sockaddr_storage),
|
|
429
270
|
sizeof(struct sockaddr_storage),
|
|
430
271
|
&bytes,
|
|
431
272
|
&req->overlapped);
|
|
432
273
|
|
|
433
|
-
if (
|
|
274
|
+
if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
|
|
275
|
+
/* Process the req without IOCP. */
|
|
276
|
+
req->accept_socket = accept_socket;
|
|
277
|
+
handle->reqs_pending++;
|
|
278
|
+
uv_insert_pending_req(loop, (uv_req_t*)req);
|
|
279
|
+
} else if (UV_SUCCEEDED_WITH_IOCP(success)) {
|
|
280
|
+
/* The req will be processed with IOCP. */
|
|
281
|
+
req->accept_socket = accept_socket;
|
|
282
|
+
handle->reqs_pending++;
|
|
283
|
+
} else {
|
|
434
284
|
/* Make this req pending reporting an error. */
|
|
435
|
-
req
|
|
436
|
-
uv_insert_pending_req(req);
|
|
285
|
+
SET_REQ_ERROR(req, WSAGetLastError());
|
|
286
|
+
uv_insert_pending_req(loop, (uv_req_t*)req);
|
|
437
287
|
handle->reqs_pending++;
|
|
438
288
|
/* Destroy the preallocated client socket. */
|
|
439
289
|
closesocket(accept_socket);
|
|
440
|
-
return;
|
|
441
290
|
}
|
|
442
|
-
|
|
443
|
-
handle->accept_socket = accept_socket;
|
|
444
|
-
|
|
445
|
-
handle->reqs_pending++;
|
|
446
291
|
}
|
|
447
292
|
|
|
448
293
|
|
|
449
|
-
static void uv_tcp_queue_read(uv_tcp_t* handle) {
|
|
294
|
+
static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) {
|
|
450
295
|
uv_req_t* req;
|
|
451
296
|
uv_buf_t buf;
|
|
452
297
|
int result;
|
|
@@ -458,8 +303,20 @@ static void uv_tcp_queue_read(uv_tcp_t* handle) {
|
|
|
458
303
|
req = &handle->read_req;
|
|
459
304
|
memset(&req->overlapped, 0, sizeof(req->overlapped));
|
|
460
305
|
|
|
461
|
-
|
|
462
|
-
|
|
306
|
+
/*
|
|
307
|
+
* Preallocate a read buffer if the number of active streams is below
|
|
308
|
+
* the threshold.
|
|
309
|
+
*/
|
|
310
|
+
if (active_tcp_streams < uv_active_tcp_streams_threshold) {
|
|
311
|
+
handle->flags &= ~UV_HANDLE_ZERO_READ;
|
|
312
|
+
handle->read_buffer = handle->alloc_cb((uv_handle_t*) handle, 65536);
|
|
313
|
+
assert(handle->read_buffer.len > 0);
|
|
314
|
+
buf = handle->read_buffer;
|
|
315
|
+
} else {
|
|
316
|
+
handle->flags |= UV_HANDLE_ZERO_READ;
|
|
317
|
+
buf.base = (char*) &uv_zero_;
|
|
318
|
+
buf.len = 0;
|
|
319
|
+
}
|
|
463
320
|
|
|
464
321
|
flags = 0;
|
|
465
322
|
result = WSARecv(handle->socket,
|
|
@@ -469,31 +326,42 @@ static void uv_tcp_queue_read(uv_tcp_t* handle) {
|
|
|
469
326
|
&flags,
|
|
470
327
|
&req->overlapped,
|
|
471
328
|
NULL);
|
|
472
|
-
|
|
329
|
+
|
|
330
|
+
if (UV_SUCCEEDED_WITHOUT_IOCP(result == 0)) {
|
|
331
|
+
/* Process the req without IOCP. */
|
|
332
|
+
handle->flags |= UV_HANDLE_READ_PENDING;
|
|
333
|
+
req->overlapped.InternalHigh = bytes;
|
|
334
|
+
handle->reqs_pending++;
|
|
335
|
+
uv_insert_pending_req(loop, req);
|
|
336
|
+
} else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) {
|
|
337
|
+
/* The req will be processed with IOCP. */
|
|
338
|
+
handle->flags |= UV_HANDLE_READ_PENDING;
|
|
339
|
+
handle->reqs_pending++;
|
|
340
|
+
} else {
|
|
473
341
|
/* Make this req pending reporting an error. */
|
|
474
|
-
req
|
|
475
|
-
uv_insert_pending_req(req);
|
|
342
|
+
SET_REQ_ERROR(req, WSAGetLastError());
|
|
343
|
+
uv_insert_pending_req(loop, req);
|
|
476
344
|
handle->reqs_pending++;
|
|
477
|
-
return;
|
|
478
345
|
}
|
|
479
|
-
|
|
480
|
-
handle->flags |= UV_HANDLE_READ_PENDING;
|
|
481
|
-
handle->reqs_pending++;
|
|
482
346
|
}
|
|
483
347
|
|
|
484
348
|
|
|
485
349
|
int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
|
|
350
|
+
uv_loop_t* loop = handle->loop;
|
|
351
|
+
unsigned int i;
|
|
352
|
+
uv_tcp_accept_t* req;
|
|
353
|
+
|
|
486
354
|
assert(backlog > 0);
|
|
487
355
|
|
|
488
356
|
if (handle->flags & UV_HANDLE_BIND_ERROR) {
|
|
489
|
-
|
|
357
|
+
loop->last_error = handle->bind_error;
|
|
490
358
|
return -1;
|
|
491
359
|
}
|
|
492
360
|
|
|
493
361
|
if (handle->flags & UV_HANDLE_LISTENING ||
|
|
494
362
|
handle->flags & UV_HANDLE_READING) {
|
|
495
363
|
/* Already listening. */
|
|
496
|
-
uv_set_sys_error(WSAEALREADY);
|
|
364
|
+
uv_set_sys_error(loop, WSAEALREADY);
|
|
497
365
|
return -1;
|
|
498
366
|
}
|
|
499
367
|
|
|
@@ -502,60 +370,88 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
|
|
|
502
370
|
return -1;
|
|
503
371
|
|
|
504
372
|
if (listen(handle->socket, backlog) == SOCKET_ERROR) {
|
|
505
|
-
uv_set_sys_error(WSAGetLastError());
|
|
373
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
506
374
|
return -1;
|
|
507
375
|
}
|
|
508
376
|
|
|
509
377
|
handle->flags |= UV_HANDLE_LISTENING;
|
|
510
378
|
handle->connection_cb = cb;
|
|
511
379
|
|
|
512
|
-
|
|
513
|
-
handle->
|
|
514
|
-
|
|
515
|
-
|
|
380
|
+
assert(!handle->accept_reqs);
|
|
381
|
+
handle->accept_reqs = (uv_tcp_accept_t*)
|
|
382
|
+
malloc(uv_simultaneous_server_accepts * sizeof(uv_tcp_accept_t));
|
|
383
|
+
if (!handle->accept_reqs) {
|
|
384
|
+
uv_fatal_error(ERROR_OUTOFMEMORY, "malloc");
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
for (i = 0; i < uv_simultaneous_server_accepts; i++) {
|
|
388
|
+
req = &handle->accept_reqs[i];
|
|
389
|
+
uv_req_init(loop, (uv_req_t*)req);
|
|
390
|
+
req->type = UV_ACCEPT;
|
|
391
|
+
req->accept_socket = INVALID_SOCKET;
|
|
392
|
+
req->data = handle;
|
|
393
|
+
uv_tcp_queue_accept(handle, req);
|
|
394
|
+
}
|
|
516
395
|
|
|
517
396
|
return 0;
|
|
518
397
|
}
|
|
519
398
|
|
|
520
399
|
|
|
521
400
|
int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) {
|
|
401
|
+
uv_loop_t* loop = server->loop;
|
|
522
402
|
int rv = 0;
|
|
523
403
|
|
|
524
|
-
|
|
525
|
-
|
|
404
|
+
uv_tcp_accept_t* req = server->pending_accepts;
|
|
405
|
+
|
|
406
|
+
if (!req) {
|
|
407
|
+
/* No valid connections found, so we error out. */
|
|
408
|
+
uv_set_sys_error(loop, WSAEWOULDBLOCK);
|
|
409
|
+
return -1;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (req->accept_socket == INVALID_SOCKET) {
|
|
413
|
+
uv_set_sys_error(loop, WSAENOTCONN);
|
|
526
414
|
return -1;
|
|
527
415
|
}
|
|
528
416
|
|
|
529
|
-
if (uv_tcp_set_socket(client,
|
|
530
|
-
closesocket(
|
|
417
|
+
if (uv_tcp_set_socket(client->loop, client, req->accept_socket) == -1) {
|
|
418
|
+
closesocket(req->accept_socket);
|
|
531
419
|
rv = -1;
|
|
532
420
|
} else {
|
|
533
|
-
uv_connection_init((uv_stream_t*)client);
|
|
421
|
+
uv_connection_init((uv_stream_t*) client);
|
|
534
422
|
}
|
|
535
423
|
|
|
536
|
-
|
|
424
|
+
/* Prepare the req to pick up a new connection */
|
|
425
|
+
server->pending_accepts = req->next_pending;
|
|
426
|
+
req->next_pending = NULL;
|
|
427
|
+
req->accept_socket = INVALID_SOCKET;
|
|
537
428
|
|
|
538
429
|
if (!(server->flags & UV_HANDLE_CLOSING)) {
|
|
539
|
-
uv_tcp_queue_accept(server);
|
|
430
|
+
uv_tcp_queue_accept(server, req);
|
|
540
431
|
}
|
|
541
432
|
|
|
433
|
+
active_tcp_streams++;
|
|
434
|
+
|
|
542
435
|
return rv;
|
|
543
436
|
}
|
|
544
437
|
|
|
545
438
|
|
|
546
|
-
int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
|
|
439
|
+
int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
|
|
440
|
+
uv_read_cb read_cb) {
|
|
441
|
+
uv_loop_t* loop = handle->loop;
|
|
442
|
+
|
|
547
443
|
if (!(handle->flags & UV_HANDLE_CONNECTION)) {
|
|
548
|
-
uv_set_sys_error(WSAEINVAL);
|
|
444
|
+
uv_set_sys_error(loop, WSAEINVAL);
|
|
549
445
|
return -1;
|
|
550
446
|
}
|
|
551
447
|
|
|
552
448
|
if (handle->flags & UV_HANDLE_READING) {
|
|
553
|
-
uv_set_sys_error(WSAEALREADY);
|
|
449
|
+
uv_set_sys_error(loop, WSAEALREADY);
|
|
554
450
|
return -1;
|
|
555
451
|
}
|
|
556
452
|
|
|
557
453
|
if (handle->flags & UV_HANDLE_EOF) {
|
|
558
|
-
uv_set_sys_error(WSAESHUTDOWN);
|
|
454
|
+
uv_set_sys_error(loop, WSAESHUTDOWN);
|
|
559
455
|
return -1;
|
|
560
456
|
}
|
|
561
457
|
|
|
@@ -566,7 +462,7 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb
|
|
|
566
462
|
/* If reading was stopped and then started again, there could stell be a */
|
|
567
463
|
/* read request pending. */
|
|
568
464
|
if (!(handle->flags & UV_HANDLE_READ_PENDING))
|
|
569
|
-
uv_tcp_queue_read(handle);
|
|
465
|
+
uv_tcp_queue_read(loop, handle);
|
|
570
466
|
|
|
571
467
|
return 0;
|
|
572
468
|
}
|
|
@@ -574,17 +470,18 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb
|
|
|
574
470
|
|
|
575
471
|
int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle,
|
|
576
472
|
struct sockaddr_in address, uv_connect_cb cb) {
|
|
473
|
+
uv_loop_t* loop = handle->loop;
|
|
577
474
|
int addrsize = sizeof(struct sockaddr_in);
|
|
578
475
|
BOOL success;
|
|
579
476
|
DWORD bytes;
|
|
580
477
|
|
|
581
478
|
if (handle->flags & UV_HANDLE_BIND_ERROR) {
|
|
582
|
-
|
|
479
|
+
loop->last_error = handle->bind_error;
|
|
583
480
|
return -1;
|
|
584
481
|
}
|
|
585
482
|
|
|
586
483
|
if (address.sin_family != AF_INET) {
|
|
587
|
-
uv_set_sys_error(WSAEFAULT);
|
|
484
|
+
uv_set_sys_error(loop, WSAEFAULT);
|
|
588
485
|
return -1;
|
|
589
486
|
}
|
|
590
487
|
|
|
@@ -592,7 +489,7 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle,
|
|
|
592
489
|
uv_tcp_bind(handle, uv_addr_ip4_any_) < 0)
|
|
593
490
|
return -1;
|
|
594
491
|
|
|
595
|
-
uv_req_init((uv_req_t*) req);
|
|
492
|
+
uv_req_init(loop, (uv_req_t*) req);
|
|
596
493
|
req->type = UV_CONNECT;
|
|
597
494
|
req->handle = (uv_stream_t*) handle;
|
|
598
495
|
req->cb = cb;
|
|
@@ -606,35 +503,41 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle,
|
|
|
606
503
|
&bytes,
|
|
607
504
|
&req->overlapped);
|
|
608
505
|
|
|
609
|
-
if (
|
|
610
|
-
|
|
506
|
+
if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
|
|
507
|
+
/* Process the req without IOCP. */
|
|
508
|
+
handle->reqs_pending++;
|
|
509
|
+
uv_insert_pending_req(loop, (uv_req_t*)req);
|
|
510
|
+
} else if (UV_SUCCEEDED_WITH_IOCP(success)) {
|
|
511
|
+
/* The req will be processed with IOCP. */
|
|
512
|
+
handle->reqs_pending++;
|
|
513
|
+
} else {
|
|
514
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
611
515
|
return -1;
|
|
612
516
|
}
|
|
613
517
|
|
|
614
|
-
handle->reqs_pending++;
|
|
615
|
-
|
|
616
518
|
return 0;
|
|
617
519
|
}
|
|
618
520
|
|
|
619
521
|
|
|
620
522
|
int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle,
|
|
621
523
|
struct sockaddr_in6 address, uv_connect_cb cb) {
|
|
524
|
+
uv_loop_t* loop = handle->loop;
|
|
622
525
|
int addrsize = sizeof(struct sockaddr_in6);
|
|
623
526
|
BOOL success;
|
|
624
527
|
DWORD bytes;
|
|
625
528
|
|
|
626
529
|
if (!uv_allow_ipv6) {
|
|
627
|
-
uv_new_sys_error(
|
|
530
|
+
uv_new_sys_error(WSAEAFNOSUPPORT);
|
|
628
531
|
return -1;
|
|
629
532
|
}
|
|
630
533
|
|
|
631
534
|
if (handle->flags & UV_HANDLE_BIND_ERROR) {
|
|
632
|
-
|
|
535
|
+
loop->last_error = handle->bind_error;
|
|
633
536
|
return -1;
|
|
634
537
|
}
|
|
635
538
|
|
|
636
539
|
if (address.sin6_family != AF_INET6) {
|
|
637
|
-
uv_set_sys_error(WSAEFAULT);
|
|
540
|
+
uv_set_sys_error(loop, WSAEFAULT);
|
|
638
541
|
return -1;
|
|
639
542
|
}
|
|
640
543
|
|
|
@@ -642,7 +545,7 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle,
|
|
|
642
545
|
uv_tcp_bind6(handle, uv_addr_ip6_any_) < 0)
|
|
643
546
|
return -1;
|
|
644
547
|
|
|
645
|
-
uv_req_init((uv_req_t*) req);
|
|
548
|
+
uv_req_init(loop, (uv_req_t*) req);
|
|
646
549
|
req->type = UV_CONNECT;
|
|
647
550
|
req->handle = (uv_stream_t*) handle;
|
|
648
551
|
req->cb = cb;
|
|
@@ -656,28 +559,32 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle,
|
|
|
656
559
|
&bytes,
|
|
657
560
|
&req->overlapped);
|
|
658
561
|
|
|
659
|
-
if (
|
|
660
|
-
|
|
562
|
+
if (UV_SUCCEEDED_WITHOUT_IOCP(success)) {
|
|
563
|
+
handle->reqs_pending++;
|
|
564
|
+
uv_insert_pending_req(loop, (uv_req_t*)req);
|
|
565
|
+
} else if (UV_SUCCEEDED_WITH_IOCP(success)) {
|
|
566
|
+
handle->reqs_pending++;
|
|
567
|
+
} else {
|
|
568
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
661
569
|
return -1;
|
|
662
570
|
}
|
|
663
571
|
|
|
664
|
-
handle->reqs_pending++;
|
|
665
|
-
|
|
666
572
|
return 0;
|
|
667
573
|
}
|
|
668
574
|
|
|
669
575
|
|
|
670
|
-
int
|
|
576
|
+
int uv_tcp_getsockname(uv_loop_t* loop, uv_tcp_t* handle,
|
|
577
|
+
struct sockaddr* name, int* namelen) {
|
|
671
578
|
int result;
|
|
672
579
|
|
|
673
580
|
if (handle->flags & UV_HANDLE_SHUTTING) {
|
|
674
|
-
uv_set_sys_error(WSAESHUTDOWN);
|
|
581
|
+
uv_set_sys_error(loop, WSAESHUTDOWN);
|
|
675
582
|
return -1;
|
|
676
583
|
}
|
|
677
584
|
|
|
678
585
|
result = getsockname(handle->socket, name, namelen);
|
|
679
586
|
if (result != 0) {
|
|
680
|
-
uv_set_sys_error(WSAGetLastError());
|
|
587
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
681
588
|
return -1;
|
|
682
589
|
}
|
|
683
590
|
|
|
@@ -685,22 +592,22 @@ int uv_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen) {
|
|
|
685
592
|
}
|
|
686
593
|
|
|
687
594
|
|
|
688
|
-
int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle,
|
|
689
|
-
uv_write_cb cb) {
|
|
595
|
+
int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle,
|
|
596
|
+
uv_buf_t bufs[], int bufcnt, uv_write_cb cb) {
|
|
690
597
|
int result;
|
|
691
|
-
DWORD bytes
|
|
598
|
+
DWORD bytes;
|
|
692
599
|
|
|
693
600
|
if (!(handle->flags & UV_HANDLE_CONNECTION)) {
|
|
694
|
-
uv_set_sys_error(WSAEINVAL);
|
|
601
|
+
uv_set_sys_error(loop, WSAEINVAL);
|
|
695
602
|
return -1;
|
|
696
603
|
}
|
|
697
604
|
|
|
698
605
|
if (handle->flags & UV_HANDLE_SHUTTING) {
|
|
699
|
-
uv_set_sys_error(WSAESHUTDOWN);
|
|
606
|
+
uv_set_sys_error(loop, WSAESHUTDOWN);
|
|
700
607
|
return -1;
|
|
701
608
|
}
|
|
702
609
|
|
|
703
|
-
uv_req_init((uv_req_t*) req);
|
|
610
|
+
uv_req_init(loop, (uv_req_t*) req);
|
|
704
611
|
req->type = UV_WRITE;
|
|
705
612
|
req->handle = (uv_stream_t*) handle;
|
|
706
613
|
req->cb = cb;
|
|
@@ -713,32 +620,31 @@ int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[], int bufcnt,
|
|
|
713
620
|
0,
|
|
714
621
|
&req->overlapped,
|
|
715
622
|
NULL);
|
|
716
|
-
if (result != 0) {
|
|
717
|
-
err = WSAGetLastError();
|
|
718
|
-
if (err != WSA_IO_PENDING) {
|
|
719
|
-
/* Send failed due to an error. */
|
|
720
|
-
uv_set_sys_error(WSAGetLastError());
|
|
721
|
-
return -1;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
623
|
|
|
725
|
-
if (result == 0) {
|
|
624
|
+
if (UV_SUCCEEDED_WITHOUT_IOCP(result == 0)) {
|
|
726
625
|
/* Request completed immediately. */
|
|
727
626
|
req->queued_bytes = 0;
|
|
728
|
-
|
|
627
|
+
handle->reqs_pending++;
|
|
628
|
+
handle->write_reqs_pending++;
|
|
629
|
+
uv_insert_pending_req(loop, (uv_req_t*) req);
|
|
630
|
+
} else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) {
|
|
729
631
|
/* Request queued by the kernel. */
|
|
730
632
|
req->queued_bytes = uv_count_bufs(bufs, bufcnt);
|
|
633
|
+
handle->reqs_pending++;
|
|
634
|
+
handle->write_reqs_pending++;
|
|
731
635
|
handle->write_queue_size += req->queued_bytes;
|
|
636
|
+
} else {
|
|
637
|
+
/* Send failed due to an error. */
|
|
638
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
639
|
+
return -1;
|
|
732
640
|
}
|
|
733
641
|
|
|
734
|
-
handle->reqs_pending++;
|
|
735
|
-
handle->write_reqs_pending++;
|
|
736
|
-
|
|
737
642
|
return 0;
|
|
738
643
|
}
|
|
739
644
|
|
|
740
645
|
|
|
741
|
-
void uv_process_tcp_read_req(
|
|
646
|
+
void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
|
|
647
|
+
uv_req_t* req) {
|
|
742
648
|
DWORD bytes, flags, err;
|
|
743
649
|
uv_buf_t buf;
|
|
744
650
|
|
|
@@ -746,19 +652,43 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) {
|
|
|
746
652
|
|
|
747
653
|
handle->flags &= ~UV_HANDLE_READ_PENDING;
|
|
748
654
|
|
|
749
|
-
if (req
|
|
750
|
-
/* An error occurred doing the
|
|
655
|
+
if (!REQ_SUCCESS(req)) {
|
|
656
|
+
/* An error occurred doing the read. */
|
|
751
657
|
if ((handle->flags & UV_HANDLE_READING)) {
|
|
752
658
|
handle->flags &= ~UV_HANDLE_READING;
|
|
753
|
-
|
|
754
|
-
buf
|
|
755
|
-
|
|
659
|
+
loop->last_error = GET_REQ_UV_SOCK_ERROR(req);
|
|
660
|
+
buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
|
|
661
|
+
uv_buf_init(NULL, 0) : handle->read_buffer;
|
|
756
662
|
handle->read_cb((uv_stream_t*)handle, -1, buf);
|
|
757
663
|
}
|
|
758
664
|
} else {
|
|
665
|
+
if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
|
|
666
|
+
/* The read was done with a non-zero buffer length. */
|
|
667
|
+
if (req->overlapped.InternalHigh > 0) {
|
|
668
|
+
/* Successful read */
|
|
669
|
+
handle->read_cb((uv_stream_t*)handle,
|
|
670
|
+
req->overlapped.InternalHigh,
|
|
671
|
+
handle->read_buffer);
|
|
672
|
+
/* Read again only if bytes == buf.len */
|
|
673
|
+
if (req->overlapped.InternalHigh < handle->read_buffer.len) {
|
|
674
|
+
goto done;
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
/* Connection closed */
|
|
678
|
+
handle->flags &= ~UV_HANDLE_READING;
|
|
679
|
+
handle->flags |= UV_HANDLE_EOF;
|
|
680
|
+
loop->last_error.code = UV_EOF;
|
|
681
|
+
loop->last_error.sys_errno_ = ERROR_SUCCESS;
|
|
682
|
+
buf.base = 0;
|
|
683
|
+
buf.len = 0;
|
|
684
|
+
handle->read_cb((uv_stream_t*)handle, -1, handle->read_buffer);
|
|
685
|
+
goto done;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
759
689
|
/* Do nonblocking reads until the buffer is empty */
|
|
760
690
|
while (handle->flags & UV_HANDLE_READING) {
|
|
761
|
-
buf = handle->alloc_cb((
|
|
691
|
+
buf = handle->alloc_cb((uv_handle_t*) handle, 65536);
|
|
762
692
|
assert(buf.len > 0);
|
|
763
693
|
flags = 0;
|
|
764
694
|
if (WSARecv(handle->socket,
|
|
@@ -779,8 +709,8 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) {
|
|
|
779
709
|
/* Connection closed */
|
|
780
710
|
handle->flags &= ~UV_HANDLE_READING;
|
|
781
711
|
handle->flags |= UV_HANDLE_EOF;
|
|
782
|
-
|
|
783
|
-
|
|
712
|
+
loop->last_error.code = UV_EOF;
|
|
713
|
+
loop->last_error.sys_errno_ = ERROR_SUCCESS;
|
|
784
714
|
handle->read_cb((uv_stream_t*)handle, -1, buf);
|
|
785
715
|
break;
|
|
786
716
|
}
|
|
@@ -788,21 +718,23 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) {
|
|
|
788
718
|
err = WSAGetLastError();
|
|
789
719
|
if (err == WSAEWOULDBLOCK) {
|
|
790
720
|
/* Read buffer was completely empty, report a 0-byte read. */
|
|
791
|
-
uv_set_sys_error(WSAEWOULDBLOCK);
|
|
721
|
+
uv_set_sys_error(loop, WSAEWOULDBLOCK);
|
|
792
722
|
handle->read_cb((uv_stream_t*)handle, 0, buf);
|
|
793
723
|
} else {
|
|
794
724
|
/* Ouch! serious error. */
|
|
795
|
-
uv_set_sys_error(err);
|
|
725
|
+
uv_set_sys_error(loop, err);
|
|
726
|
+
handle->flags &= ~UV_HANDLE_READING;
|
|
796
727
|
handle->read_cb((uv_stream_t*)handle, -1, buf);
|
|
797
728
|
}
|
|
798
729
|
break;
|
|
799
730
|
}
|
|
800
731
|
}
|
|
801
732
|
|
|
802
|
-
|
|
733
|
+
done:
|
|
734
|
+
/* Post another read if still reading and not closing. */
|
|
803
735
|
if ((handle->flags & UV_HANDLE_READING) &&
|
|
804
736
|
!(handle->flags & UV_HANDLE_READ_PENDING)) {
|
|
805
|
-
uv_tcp_queue_read(handle);
|
|
737
|
+
uv_tcp_queue_read(loop, handle);
|
|
806
738
|
}
|
|
807
739
|
}
|
|
808
740
|
|
|
@@ -810,47 +742,54 @@ void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req) {
|
|
|
810
742
|
}
|
|
811
743
|
|
|
812
744
|
|
|
813
|
-
void uv_process_tcp_write_req(
|
|
745
|
+
void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
|
|
746
|
+
uv_write_t* req) {
|
|
814
747
|
assert(handle->type == UV_TCP);
|
|
815
748
|
|
|
816
749
|
handle->write_queue_size -= req->queued_bytes;
|
|
817
750
|
|
|
818
751
|
if (req->cb) {
|
|
819
|
-
|
|
820
|
-
((uv_write_cb)req->cb)(req,
|
|
752
|
+
loop->last_error = GET_REQ_UV_SOCK_ERROR(req);
|
|
753
|
+
((uv_write_cb)req->cb)(req, loop->last_error.code == UV_OK ? 0 : -1);
|
|
821
754
|
}
|
|
822
755
|
|
|
823
756
|
handle->write_reqs_pending--;
|
|
824
757
|
if (handle->flags & UV_HANDLE_SHUTTING &&
|
|
825
758
|
handle->write_reqs_pending == 0) {
|
|
826
|
-
uv_want_endgame((uv_handle_t*)handle);
|
|
759
|
+
uv_want_endgame(loop, (uv_handle_t*)handle);
|
|
827
760
|
}
|
|
828
761
|
|
|
829
762
|
DECREASE_PENDING_REQ_COUNT(handle);
|
|
830
763
|
}
|
|
831
764
|
|
|
832
765
|
|
|
833
|
-
void uv_process_tcp_accept_req(
|
|
766
|
+
void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
|
|
767
|
+
uv_req_t* raw_req) {
|
|
768
|
+
uv_tcp_accept_t* req = (uv_tcp_accept_t*) raw_req;
|
|
769
|
+
|
|
834
770
|
assert(handle->type == UV_TCP);
|
|
835
771
|
|
|
836
772
|
/* If handle->accepted_socket is not a valid socket, then */
|
|
837
773
|
/* uv_queue_accept must have failed. This is a serious error. We stop */
|
|
838
774
|
/* accepting connections and report this error to the connection */
|
|
839
775
|
/* callback. */
|
|
840
|
-
if (
|
|
776
|
+
if (req->accept_socket == INVALID_SOCKET) {
|
|
841
777
|
if (handle->flags & UV_HANDLE_LISTENING) {
|
|
842
778
|
handle->flags &= ~UV_HANDLE_LISTENING;
|
|
843
779
|
if (handle->connection_cb) {
|
|
844
|
-
|
|
780
|
+
loop->last_error = GET_REQ_UV_SOCK_ERROR(req);
|
|
845
781
|
handle->connection_cb((uv_stream_t*)handle, -1);
|
|
846
782
|
}
|
|
847
783
|
}
|
|
848
|
-
} else if (req
|
|
849
|
-
setsockopt(
|
|
784
|
+
} else if (REQ_SUCCESS(req) &&
|
|
785
|
+
setsockopt(req->accept_socket,
|
|
850
786
|
SOL_SOCKET,
|
|
851
787
|
SO_UPDATE_ACCEPT_CONTEXT,
|
|
852
788
|
(char*)&handle->socket,
|
|
853
789
|
sizeof(handle->socket)) == 0) {
|
|
790
|
+
req->next_pending = handle->pending_accepts;
|
|
791
|
+
handle->pending_accepts = req;
|
|
792
|
+
|
|
854
793
|
/* Accept and SO_UPDATE_ACCEPT_CONTEXT were successful. */
|
|
855
794
|
if (handle->connection_cb) {
|
|
856
795
|
handle->connection_cb((uv_stream_t*)handle, 0);
|
|
@@ -859,9 +798,10 @@ void uv_process_tcp_accept_req(uv_tcp_t* handle, uv_req_t* req) {
|
|
|
859
798
|
/* Error related to accepted socket is ignored because the server */
|
|
860
799
|
/* socket may still be healthy. If the server socket is broken
|
|
861
800
|
/* uv_queue_accept will detect it. */
|
|
862
|
-
closesocket(
|
|
801
|
+
closesocket(req->accept_socket);
|
|
802
|
+
req->accept_socket = INVALID_SOCKET;
|
|
863
803
|
if (handle->flags & UV_HANDLE_LISTENING) {
|
|
864
|
-
uv_tcp_queue_accept(handle);
|
|
804
|
+
uv_tcp_queue_accept(handle, req);
|
|
865
805
|
}
|
|
866
806
|
}
|
|
867
807
|
|
|
@@ -869,24 +809,26 @@ void uv_process_tcp_accept_req(uv_tcp_t* handle, uv_req_t* req) {
|
|
|
869
809
|
}
|
|
870
810
|
|
|
871
811
|
|
|
872
|
-
void uv_process_tcp_connect_req(
|
|
812
|
+
void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
|
|
813
|
+
uv_connect_t* req) {
|
|
873
814
|
assert(handle->type == UV_TCP);
|
|
874
815
|
|
|
875
816
|
if (req->cb) {
|
|
876
|
-
if (req
|
|
817
|
+
if (REQ_SUCCESS(req)) {
|
|
877
818
|
if (setsockopt(handle->socket,
|
|
878
819
|
SOL_SOCKET,
|
|
879
820
|
SO_UPDATE_CONNECT_CONTEXT,
|
|
880
821
|
NULL,
|
|
881
822
|
0) == 0) {
|
|
882
823
|
uv_connection_init((uv_stream_t*)handle);
|
|
824
|
+
active_tcp_streams++;
|
|
883
825
|
((uv_connect_cb)req->cb)(req, 0);
|
|
884
826
|
} else {
|
|
885
|
-
uv_set_sys_error(WSAGetLastError());
|
|
827
|
+
uv_set_sys_error(loop, WSAGetLastError());
|
|
886
828
|
((uv_connect_cb)req->cb)(req, -1);
|
|
887
829
|
}
|
|
888
830
|
} else {
|
|
889
|
-
|
|
831
|
+
loop->last_error = GET_REQ_UV_SOCK_ERROR(req);
|
|
890
832
|
((uv_connect_cb)req->cb)(req, -1);
|
|
891
833
|
}
|
|
892
834
|
}
|