view release on metacpan or search on metacpan
libuv/test/test-loop-close.c
libuv/test/test-loop-configure.c
libuv/test/test-loop-handles.c
libuv/test/test-loop-stop.c
libuv/test/test-loop-time.c
libuv/test/test-multiple-listen.c
libuv/test/test-mutexes.c
libuv/test/test-osx-select.c
libuv/test/test-pass-always.c
libuv/test/test-ping-pong.c
libuv/test/test-pipe-bind-error.c
libuv/test/test-pipe-close-stdout-read-stdin.c
libuv/test/test-pipe-connect-error.c
libuv/test/test-pipe-connect-multiple.c
libuv/test/test-pipe-connect-prepare.c
libuv/test/test-pipe-getsockname.c
libuv/test/test-pipe-pending-instances.c
libuv/test/test-pipe-sendmsg.c
libuv/test/test-pipe-server-close.c
libuv/test/test-pipe-set-fchmod.c
libuv/test/test-pipe-set-non-blocking.c
libuv/test/test-shutdown-close.c
libuv/test/test-shutdown-eof.c
libuv/test/test-shutdown-twice.c
libuv/test/test-signal-multiple-loops.c
libuv/test/test-signal.c
libuv/test/test-socket-buffer-size.c
libuv/test/test-spawn.c
libuv/test/test-stdio-over-pipes.c
libuv/test/test-strscpy.c
libuv/test/test-tcp-alloc-cb-fail.c
libuv/test/test-tcp-bind-error.c
libuv/test/test-tcp-bind6-error.c
libuv/test/test-tcp-close-accept.c
libuv/test/test-tcp-close-while-connecting.c
libuv/test/test-tcp-close.c
libuv/test/test-tcp-connect-error-after-write.c
libuv/test/test-tcp-connect-error.c
libuv/test/test-tcp-connect-timeout.c
libuv/test/test-tcp-connect6-error.c
libuv/test/test-tcp-create-socket-early.c
libuv/test/test-tcp-flags.c
libuv/test/test-tcp-oob.c
libuv/test/test-thread.c
libuv/test/test-threadpool-cancel.c
libuv/test/test-threadpool.c
libuv/test/test-timer-again.c
libuv/test/test-timer-from-check.c
libuv/test/test-timer.c
libuv/test/test-tmpdir.c
libuv/test/test-tty-duplicate-key.c
libuv/test/test-tty.c
libuv/test/test-udp-alloc-cb-fail.c
libuv/test/test-udp-bind.c
libuv/test/test-udp-connect.c
libuv/test/test-udp-create-socket-early.c
libuv/test/test-udp-dgram-too-big.c
libuv/test/test-udp-ipv6.c
libuv/test/test-udp-multicast-interface.c
libuv/test/test-udp-multicast-interface6.c
libuv/test/test-udp-multicast-join.c
libuv/test/test-udp-multicast-join6.c
libuv/test/test-udp-multicast-ttl.c
libuv/test/test-udp-open.c
libuv/CMakeLists.txt view on Meta::CPAN
test/test-loop-close.c
test/test-loop-configure.c
test/test-loop-handles.c
test/test-loop-stop.c
test/test-loop-time.c
test/test-multiple-listen.c
test/test-mutexes.c
test/test-osx-select.c
test/test-pass-always.c
test/test-ping-pong.c
test/test-pipe-bind-error.c
test/test-pipe-close-stdout-read-stdin.c
test/test-pipe-connect-error.c
test/test-pipe-connect-multiple.c
test/test-pipe-connect-prepare.c
test/test-pipe-getsockname.c
test/test-pipe-pending-instances.c
test/test-pipe-sendmsg.c
test/test-pipe-server-close.c
test/test-pipe-set-fchmod.c
test/test-pipe-set-non-blocking.c
libuv/CMakeLists.txt view on Meta::CPAN
test/test-shutdown-close.c
test/test-shutdown-eof.c
test/test-shutdown-twice.c
test/test-signal-multiple-loops.c
test/test-signal.c
test/test-socket-buffer-size.c
test/test-spawn.c
test/test-stdio-over-pipes.c
test/test-strscpy.c
test/test-tcp-alloc-cb-fail.c
test/test-tcp-bind-error.c
test/test-tcp-bind6-error.c
test/test-tcp-close-accept.c
test/test-tcp-close-while-connecting.c
test/test-tcp-close.c
test/test-tcp-connect-error-after-write.c
test/test-tcp-connect-error.c
test/test-tcp-connect-timeout.c
test/test-tcp-connect6-error.c
test/test-tcp-create-socket-early.c
test/test-tcp-flags.c
test/test-tcp-oob.c
libuv/CMakeLists.txt view on Meta::CPAN
test/test-thread.c
test/test-threadpool-cancel.c
test/test-threadpool.c
test/test-timer-again.c
test/test-timer-from-check.c
test/test-timer.c
test/test-tmpdir.c
test/test-tty-duplicate-key.c
test/test-tty.c
test/test-udp-alloc-cb-fail.c
test/test-udp-bind.c
test/test-udp-connect.c
test/test-udp-create-socket-early.c
test/test-udp-dgram-too-big.c
test/test-udp-ipv6.c
test/test-udp-multicast-interface.c
test/test-udp-multicast-interface6.c
test/test-udp-multicast-join.c
test/test-udp-multicast-join6.c
test/test-udp-multicast-ttl.c
test/test-udp-open.c
libuv/ChangeLog view on Meta::CPAN
* test: use custom timeout for getaddrinfo_fail_sync (Ben Noordhuis)
* Revert "win: add Windows XP support to uv_if_indextoname()" (Bert Belder)
* win,thread: remove fallback uv_cond implementation (Bert Belder)
* src,test: s/olny/only (cjihrig)
* unix: close signal pipe fds on unload (Ben Noordhuis)
* win: allow setting udp socket options before bind (cjihrig)
* unix: return UV_ENOTSUP on FICLONE_FORCE failure (cjihrig)
* win,pipe: remove unreferenced local variable (Bert Belder)
* win,code: remove GetQueuedCompletionStatus-based poller (Bert Belder)
* win: remove the remaining dynamic kernel32 imports (Bert Belder)
* test: speedup process-title-threadsafe on macOS (cjihrig)
libuv/ChangeLog view on Meta::CPAN
* unix,windows: refactor request init logic (Ben Noordhuis)
* win: fix memory leak inside uv__pipe_getname (A. Hauptmann)
* fsevent: support for files without short name (Bartosz Sosnowski)
* doc: fix multiple doc typos (Jamie Davis)
* test,osx: fix flaky kill test (Santiago Gimeno)
* unix: inline uv_pipe_bind() err_bind goto target (cjihrig)
* unix,test: deadstore fixes (Rasmus Christian Pedersen)
* win: fix memory leak inside uv_fs_access() (A. Hauptmann)
* doc: fix docs/src/fs.rst build warning (Daniel Bevenius)
* doc: minor grammar fix in Installation section (Daniel Bevenius)
* doc: suggestions for design page (Daniel Bevenius)
libuv/ChangeLog view on Meta::CPAN
* win,test: support stdout output larger than 1kb (Bartosz Sosnowski)
* win: remove __declspec(inline) from atomic op (Keane)
* test: fix VC++ compilation warning (Rasmus Christian Pedersen)
* build: add -Wstrict-prototypes (Jameson Nash)
* zos: implement uv__io_fork, skip fs event tests (jBarz)
* unix: do not close udp sockets on bind error (Marc Schlaich)
* unix: remove FSEventStreamFlushSync() call (cjihrig)
* build,openbsd: remove kvm-related code (James McCoy)
* test: fix flaky tcp-write-queue-order (Santiago Gimeno)
* unix,win: add uv_os_gethostname() (cjihrig)
* zos: increase timeout for tcp_writealot (jBarz)
libuv/ChangeLog view on Meta::CPAN
* build: GNU/kFreeBSD support (Jeffrey Clark)
* zos: use PLO instruction for atomic operations (John Barboza)
* zos: use pthread helper functions (John Barboza)
* zos: implement uv__fs_futime (John Barboza)
* unix: expand range of values for usleep (John Barboza)
* zos: track unbound handles and bind before listen (John Barboza)
* test: improve tap output on test failures (Santiago Gimeno)
* test: refactor fs_event_close_in_callback (Julien Gilli)
* zos: implement uv__io_check_fd (John Barboza)
* unix: unneccessary use const qualifier in container_of (John Barboza)
* win,tty: add support for ANSI codes in win10 v1511 (Imran Iqbal)
libuv/ChangeLog view on Meta::CPAN
2016.05.17, Version 1.9.1 (Stable), d989902ac658b4323a4f4020446e6f4dc449e25c
Changes since version 1.9.0:
* test: handle root home directories (cjihrig)
* unix: implement uv__fs_futime for AIX 7.1 (Imran Iqbal)
* test: skip early bind tests if no IPv6 is supported (Saúl Ibarra Corretgé)
* win: fix var declaration to be C89 compliant (Michael Fero)
* unix: use POLL{IN,OUT,etc} constants directly (Ben Noordhuis)
* doc: add ability to live reload and regenerate HTML (Saúl Ibarra Corretgé)
* Revert "win,build: remove unused build defines" (cjihrig)
* linux: fix fd leaks in uv_cpu_info() error paths (Ben Noordhuis)
libuv/ChangeLog view on Meta::CPAN
2015.08.25, Version 1.7.2 (Stable), 4d13a013fcfa72311f0102751fdc7951873f466c
Changes since version 1.7.1:
* unix, win: make uv_loop_init return on error (Willem Thiart)
* win: reset pipe handle for pipe servers (Saúl Ibarra Corretgé)
* win: fix replacing pipe handle for pipe servers (Saúl Ibarra Corretgé)
* win: fix setting pipe pending instances after bind (Saúl Ibarra Corretgé)
2015.08.20, Version 1.7.1 (Stable), 44f4b6bd82d8ae4583ccc4768a83af778ef69f85
Changes since version 1.7.0:
* doc: document the procedure for verifying releases (Saúl Ibarra Corretgé)
* doc: add note about Windows binaries to the README (Saúl Ibarra Corretgé)
libuv/ChangeLog view on Meta::CPAN
* unix, win: prevent replacing fd in uv_{udp,tcp,pipe}_t (Saúl Ibarra Corretgé)
* win: move logic to set socket non-inheritable to uv_tcp_set_socket (Saúl
Ibarra Corretgé)
* unix, win: add ability to create tcp/udp sockets early (Saúl Ibarra Corretgé)
* test: retry select() on EINTR, honor milliseconds (Ben Noordhuis)
* unix: consolidate tcp and udp bind error (Saúl Ibarra Corretgé)
* test: conditionally skip udp_ipv6_multicast_join6 (heshamsafi)
* core: add UV_VERSION_HEX macro (Saúl Ibarra Corretgé)
* doc: add section with version-checking macros and functions (Saúl Ibarra
Corretgé)
* tty: cleanup handle if uv_tty_init fails (Saúl Ibarra Corretgé)
libuv/ChangeLog view on Meta::CPAN
* sunos: preemptively fix uv_exepath(size=1) (Ben Noordhuis)
* win: fix and clarify comments in winapi.h (Bert Belder)
* win: make available NtQueryDirectoryFile (Bert Belder)
* win: add definitions for directory information types (Bert Belder)
* win: use NtQueryDirectoryFile to implement uv_fs_scandir (Bert Belder)
* unix: don't unlink unix socket on bind error (Ben Noordhuis)
* build: fix bad comment in autogen.sh (Ben Noordhuis)
* build: add AC_PROG_LIBTOOL to configure.ac (Ben Noordhuis)
* test: skip udp_options6 if there no IPv6 support (Saúl Ibarra Corretgé)
* win: add definitions for MUI errors mingw lacks (Bert Belder)
* build: enable warnings in autotools build (Ben Noordhuis)
libuv/ChangeLog view on Meta::CPAN
* unix: remove incorrect assert (Saúl Ibarra Corretgé)
* openbsd: avoid requiring privileges for uv_resident_set_memory (Aaron Bieber)
* unix: guarantee write queue cb execution order in streams (Andrius Bentkus)
* img: add logo files (Saúl Ibarra Corretgé)
* aix: improve AIX compatibility (Andrew Low)
* windows: return bind error immediately when implicitly binding (Saúl Ibarra
Corretgé)
* windows: don't use atexit for cleaning up the threadpool (Saúl Ibarra
Corretgé)
* windows: destroy work queue elements when colsing a loop (Saúl Ibarra
Corretgé)
* unix, windows: add uv_fs_mkdtemp (Pavel Platto)
* build: handle platforms without multiprocessing.synchronize (Saúl Ibarra
Corretgé)
* windows: change GENERIC_ALL to GENERIC_WRITE in fs__create_junction (Tony
Kelman)
* windows: relay TCP bind errors via ipc (Alexis Campailla)
2014.07.32, Version 0.10.28 (Stable), 9c14b616f5fb84bfd7d45707bab4bbb85894443e
Changes since version 0.10.27:
* windows: fix handling closed socket while poll handle is closing (Saúl Ibarra
Corretgé)
* unix: return system error on EAI_SYSTEM (Saúl Ibarra Corretgé)
libuv/ChangeLog view on Meta::CPAN
Changes since version 0.11.24:
* osx: pass const handle pointer to uv___stream_fd (Chernyshev Viacheslav)
* unix, windows: pass const handle ptr to uv_tcp_get*name (Chernyshev
Viacheslav)
* common: pass const sockaddr ptr to uv_ip*_name (Chernyshev Viacheslav)
* unix, windows: validate flags on uv_udp|tcp_bind (Saúl Ibarra Corretgé)
* unix: handle case when addr is not initialized after recvmsg (Saúl Ibarra
Corretgé)
* unix, windows: uv_now constness (Rasmus Pedersen)
2014.04.15, Version 0.11.24 (Unstable), ed948c29f6e8c290f79325a6f0bc9ef35bcde644
Changes since version 0.11.23:
libuv/ChangeLog view on Meta::CPAN
2014.01.23, Version 0.11.18 (Unstable), d47962e9d93d4a55a9984623feaf546406c9cdbb
Changes since version 0.11.17:
* osx: Fix a possible segfault in uv__io_poll (Alex Crichton)
* windows: improved handling of invalid FDs (Alexis Campailla)
* doc: adding ARCHS flag to OS X build command (Nathan Sweet)
* tcp: reveal bind-time errors before listen (Alexis Campailla)
* tcp: uv_tcp_dualstack() (Fedor Indutny)
* linux: relax assumption on /proc/stat parsing (Luca Bruno)
* openbsd: fix obvious bug in uv_cpu_info (Fedor Indutny)
* process: close stdio after dup2'ing it (Fedor Indutny)
* linux: move sscanf() out of the assert() (Trevor Norris)
libuv/ChangeLog view on Meta::CPAN
* windows/fs: handle _open_osfhandle() failure correctly (Bert Belder)
* build: clarify instructions for Windows (Brian Kaisner)
* build: remove GCC_WARN_ABOUT_MISSING_NEWLINE (Ben Noordhuis)
* darwin: fix 10.6 build error in fsevents.c (Ben Noordhuis)
* windows: run close callbacks after polling for i/o (Saúl Ibarra Corretgé)
* include: clarify uv_tcp_bind() behavior (Ben Noordhuis)
* include: clean up includes in uv.h (Ben Noordhuis)
* include: remove UV_IO_PRIVATE_FIELDS macro (Ben Noordhuis)
* include: fix typo in comment in uv.h (Ben Noordhuis)
* include: update uv_is_active() documentation (Ben Noordhuis)
* include: make uv_process_options_t.cwd const (Ben Noordhuis)
libuv/ChangeLog view on Meta::CPAN
2013.09.05, Version 0.11.13 (Unstable), f5b6db6c1d7f93d28281207fd47c3841c9a9792e
Changes since version 0.11.12:
* unix: define _GNU_SOURCE, exposes glibc-isms (Ben Noordhuis)
* windows: check for nonconforming swprintf arguments (Brent Cook)
* build: include internal headers in source list (Brent Cook)
* include: merge uv_tcp_bind and uv_tcp_bind6 (Ben Noordhuis)
* include: merge uv_tcp_connect and uv_tcp_connect6 (Ben Noordhuis)
* include: merge uv_udp_bind and uv_udp_bind6 (Ben Noordhuis)
* include: merge uv_udp_send and uv_udp_send6 (Ben Noordhuis)
2013.09.03, Version 0.11.12 (Unstable), 82d01d5f6780d178f5176a01425ec297583c0811
Changes since version 0.11.11:
* test: fix epoll_wait() usage in test-embed.c (Ben Noordhuis)
* include: uv_alloc_cb now takes uv_buf_t* (Ben Noordhuis)
* include: uv_read{2}_cb now takes const uv_buf_t* (Ben Noordhuis)
* include: uv_ip[46]_addr now takes sockaddr_in* (Ben Noordhuis)
* include: uv_tcp_bind{6} now takes sockaddr_in* (Ben Noordhuis)
* include: uv_tcp_connect{6} now takes sockaddr_in* (Ben Noordhuis)
* include: uv_udp_recv_cb now takes const uv_buf_t* (Ben Noordhuis)
* include: uv_udp_bind{6} now takes sockaddr_in* (Ben Noordhuis)
* include: uv_udp_send{6} now takes sockaddr_in* (Ben Noordhuis)
* include: uv_spawn takes const uv_process_options_t* (Ben Noordhuis)
* include: make uv_write{2} const correct (Ben Noordhuis)
* windows: fix flags assignment in uv_fs_readdir() (Ben Noordhuis)
* windows: fix stray comments (Ben Noordhuis)
libuv/ChangeLog view on Meta::CPAN
Changes since version 0.11.10:
* unix, windows: add thread-local storage API (Ben Noordhuis)
* linux: don't turn on SO_REUSEPORT socket option (Ben Noordhuis)
* darwin: fix 10.6 build error in fsevents.c (Ben Noordhuis)
* windows: make uv_shutdown() for write-only pipes work (Bert Belder)
* include: update uv_udp_open() / uv_udp_bind() docs (Ben Noordhuis)
* unix: req queue must be empty when destroying loop (Ben Noordhuis)
* unix: move loop functions from core.c to loop.c (Ben Noordhuis)
* darwin: remove CoreFoundation dependency (Ben Noordhuis)
* windows: make autotools build system work with mingw (Keno Fischer)
* windows: fix mingw build (Alex Crichton)
libuv/Makefile.am view on Meta::CPAN
test/test-loop-alive.c \
test/test-loop-close.c \
test/test-loop-stop.c \
test/test-loop-time.c \
test/test-loop-configure.c \
test/test-multiple-listen.c \
test/test-mutexes.c \
test/test-osx-select.c \
test/test-pass-always.c \
test/test-ping-pong.c \
test/test-pipe-bind-error.c \
test/test-pipe-connect-error.c \
test/test-pipe-connect-multiple.c \
test/test-pipe-connect-prepare.c \
test/test-pipe-getsockname.c \
test/test-pipe-pending-instances.c \
test/test-pipe-sendmsg.c \
test/test-pipe-server-close.c \
test/test-pipe-close-stdout-read-stdin.c \
test/test-pipe-set-non-blocking.c \
test/test-pipe-set-fchmod.c \
libuv/Makefile.am view on Meta::CPAN
test/test-shutdown-close.c \
test/test-shutdown-eof.c \
test/test-shutdown-twice.c \
test/test-signal-multiple-loops.c \
test/test-signal.c \
test/test-socket-buffer-size.c \
test/test-spawn.c \
test/test-stdio-over-pipes.c \
test/test-strscpy.c \
test/test-tcp-alloc-cb-fail.c \
test/test-tcp-bind-error.c \
test/test-tcp-bind6-error.c \
test/test-tcp-close-accept.c \
test/test-tcp-close-while-connecting.c \
test/test-tcp-close.c \
test/test-tcp-create-socket-early.c \
test/test-tcp-connect-error-after-write.c \
test/test-tcp-connect-error.c \
test/test-tcp-connect-timeout.c \
test/test-tcp-connect6-error.c \
test/test-tcp-flags.c \
test/test-tcp-open.c \
libuv/Makefile.am view on Meta::CPAN
test/test-thread.c \
test/test-threadpool-cancel.c \
test/test-threadpool.c \
test/test-timer-again.c \
test/test-timer-from-check.c \
test/test-timer.c \
test/test-tmpdir.c \
test/test-tty-duplicate-key.c \
test/test-tty.c \
test/test-udp-alloc-cb-fail.c \
test/test-udp-bind.c \
test/test-udp-connect.c \
test/test-udp-create-socket-early.c \
test/test-udp-dgram-too-big.c \
test/test-udp-ipv6.c \
test/test-udp-multicast-interface.c \
test/test-udp-multicast-interface6.c \
test/test-udp-multicast-join.c \
test/test-udp-multicast-join6.c \
test/test-udp-multicast-ttl.c \
test/test-udp-open.c \
libuv/common.gypi view on Meta::CPAN
['OS=="mac"', {
'xcode_settings': {
'ALWAYS_SEARCH_USER_PATHS': 'NO',
'GCC_CW_ASM_SYNTAX': 'NO', # No -fasm-blocks
'GCC_DYNAMIC_NO_PIC': 'NO', # No -mdynamic-no-pic
# (Equivalent to -fPIC)
'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', # -fno-exceptions
'GCC_ENABLE_CPP_RTTI': 'NO', # -fno-rtti
'GCC_ENABLE_PASCAL_STRINGS': 'NO', # No -mpascal-strings
'GCC_THREADSAFE_STATICS': 'NO', # -fno-threadsafe-statics
'PREBINDING': 'NO', # No -Wl,-prebind
'USE_HEADERMAP': 'NO',
'WARNING_CFLAGS': [
'-Wall',
'-Wendif-labels',
'-W',
'-Wno-unused-parameter',
'-Wstrict-prototypes',
],
},
'conditions': [
libuv/docs/code/cgi/main.c view on Meta::CPAN
uv_close((uv_handle_t*) client, NULL);
}
}
int main() {
loop = uv_default_loop();
uv_tcp_t server;
uv_tcp_init(loop, &server);
struct sockaddr_in bind_addr;
uv_ip4_addr("0.0.0.0", 7000, &bind_addr);
uv_tcp_bind(&server, (const struct sockaddr *)&bind_addr, 0);
int r = uv_listen((uv_stream_t*) &server, 128, on_new_connection);
if (r) {
fprintf(stderr, "Listen error %s\n", uv_err_name(r));
return 1;
}
return uv_run(loop, UV_RUN_DEFAULT);
}
libuv/docs/code/multi-echo-server/main.c view on Meta::CPAN
}
int main() {
loop = uv_default_loop();
setup_workers();
uv_tcp_t server;
uv_tcp_init(loop, &server);
struct sockaddr_in bind_addr;
uv_ip4_addr("0.0.0.0", 7000, &bind_addr);
uv_tcp_bind(&server, (const struct sockaddr *)&bind_addr, 0);
int r;
if ((r = uv_listen((uv_stream_t*) &server, 128, on_new_connection))) {
fprintf(stderr, "Listen error %s\n", uv_err_name(r));
return 2;
}
return uv_run(loop, UV_RUN_DEFAULT);
}
libuv/docs/code/pipe-echo-server/main.c view on Meta::CPAN
int main() {
loop = uv_default_loop();
uv_pipe_t server;
uv_pipe_init(loop, &server, 0);
signal(SIGINT, remove_sock);
int r;
if ((r = uv_pipe_bind(&server, PIPENAME))) {
fprintf(stderr, "Bind error %s\n", uv_err_name(r));
return 1;
}
if ((r = uv_listen((uv_stream_t*) &server, 128, on_new_connection))) {
fprintf(stderr, "Listen error %s\n", uv_err_name(r));
return 2;
}
return uv_run(loop, UV_RUN_DEFAULT);
}
libuv/docs/code/tcp-echo-server/main.c view on Meta::CPAN
}
int main() {
loop = uv_default_loop();
uv_tcp_t server;
uv_tcp_init(loop, &server);
uv_ip4_addr("0.0.0.0", DEFAULT_PORT, &addr);
uv_tcp_bind(&server, (const struct sockaddr*)&addr, 0);
int r = uv_listen((uv_stream_t*) &server, DEFAULT_BACKLOG, on_new_connection);
if (r) {
fprintf(stderr, "Listen error %s\n", uv_strerror(r));
return 1;
}
return uv_run(loop, UV_RUN_DEFAULT);
}
libuv/docs/code/udp-dhcp/main.c view on Meta::CPAN
return;
}
}
int main() {
loop = uv_default_loop();
uv_udp_init(loop, &recv_socket);
struct sockaddr_in recv_addr;
uv_ip4_addr("0.0.0.0", 68, &recv_addr);
uv_udp_bind(&recv_socket, (const struct sockaddr *)&recv_addr, UV_UDP_REUSEADDR);
uv_udp_recv_start(&recv_socket, alloc_buffer, on_read);
uv_udp_init(loop, &send_socket);
struct sockaddr_in broadcast_addr;
uv_ip4_addr("0.0.0.0", 0, &broadcast_addr);
uv_udp_bind(&send_socket, (const struct sockaddr *)&broadcast_addr, 0);
uv_udp_set_broadcast(&send_socket, 1);
uv_udp_send_t send_req;
uv_buf_t discover_msg = make_discover_msg();
struct sockaddr_in send_addr;
uv_ip4_addr("255.255.255.255", 67, &send_addr);
uv_udp_send(&send_req, &send_socket, &discover_msg, 1, (const struct sockaddr *)&send_addr, on_send);
return uv_run(loop, UV_RUN_DEFAULT);
libuv/docs/src/guide/basics.rst view on Meta::CPAN
Default loop
++++++++++++
A default loop is provided by libuv and can be accessed using
``uv_default_loop()``. You should use this loop if you only want a single
loop.
.. note::
node.js uses the default loop as its main loop. If you are writing bindings
you should be aware of this.
.. _libuv-error-handling:
Error handling
--------------
Initialization functions or synchronous functions which may fail return a negative number on error. Async functions that may fail will pass a status parameter to their callbacks. The error messages are defined as ``UV_E*`` `constants`_.
.. _constants: http://docs.libuv.org/en/v1.x/errors.html#error-constants
libuv/docs/src/guide/introduction.rst view on Meta::CPAN
combined a model of I/O -- evented -- with a language that was well suited to
the style of programming; due to the way it had been shaped by browsers. As
node.js grew in popularity, it was important to make it work on Windows, but
libev ran only on Unix. The Windows equivalent of kernel event notification
mechanisms like kqueue or (e)poll is IOCP. libuv was an abstraction around libev
or IOCP depending on the platform, providing users an API based on libev.
In the node-v0.9.0 version of libuv `libev was removed`_.
Since then libuv has continued to mature and become a high quality standalone
library for system programming. Users outside of node.js include Mozilla's
Rust_ programming language, and a variety_ of language bindings.
This book and the code is based on libuv version `v1.3.0`_.
Code
----
All the code from this book is included as part of the source of the book on
Github. `Clone`_/`Download`_ the book, then build libuv::
cd libuv
libuv/docs/src/guide/networking.rst view on Meta::CPAN
TCP is a connection oriented, stream protocol and is therefore based on the
libuv streams infrastructure.
Server
++++++
Server sockets proceed by:
1. ``uv_tcp_init`` the TCP handle.
2. ``uv_tcp_bind`` it.
3. Call ``uv_listen`` on the handle to have a callback invoked whenever a new
connection is established by a client.
4. Use ``uv_accept`` to accept the connection.
5. Use :ref:`stream operations <buffers-and-streams>` to communicate with the
client.
Here is a simple echo server
.. rubric:: tcp-echo-server/main.c - The listen socket
.. literalinclude:: ../../code/tcp-echo-server/main.c
libuv/docs/src/guide/networking.rst view on Meta::CPAN
:emphasize-lines: 9-10
The remaining set of functions is very similar to the streams example and can
be found in the code. Just remember to call ``uv_close`` when the socket isn't
required. This can be done even in the ``uv_listen`` callback if you are not
interested in accepting the connection.
Client
++++++
Where you do bind/listen/accept on the server, on the client side it's simply
a matter of calling ``uv_tcp_connect``. The same ``uv_connect_cb`` style
callback of ``uv_listen`` is used by ``uv_tcp_connect``. Try::
uv_tcp_t* socket = (uv_tcp_t*)malloc(sizeof(uv_tcp_t));
uv_tcp_init(loop, socket);
uv_connect_t* connect = (uv_connect_t*)malloc(sizeof(uv_connect_t));
struct sockaddr_in dest;
uv_ip4_addr("127.0.0.1", 80, &dest);
libuv/docs/src/guide/networking.rst view on Meta::CPAN
numbers below 1024.
.. rubric:: udp-dhcp/main.c - Setup and send UDP packets
.. literalinclude:: ../../code/udp-dhcp/main.c
:linenos:
:lines: 7-11,104-
:emphasize-lines: 8,10-11,17-18,21
.. note::
The IP address ``0.0.0.0`` is used to bind to all interfaces. The IP
address ``255.255.255.255`` is a broadcast address meaning that packets
will be sent to all interfaces on the subnet. port ``0`` means that the OS
randomly assigns a port.
First we setup the receiving socket to bind on all interfaces on port 68 (DHCP
client) and start a read on it. This will read back responses from any DHCP
server that replies. We use the UV_UDP_REUSEADDR flag to play nice with any
other system DHCP clients that are running on this computer on the same port.
Then we setup a similar send socket and use ``uv_udp_send`` to send
a *broadcast message* on port 67 (DHCP server).
It is **necessary** to set the broadcast flag, otherwise you will get an
``EACCES`` error [#]_. The exact message being sent is not relevant to this
book and you can study the code if you are interested. As usual the read and
write callbacks will receive a status code of < 0 if something went wrong.
libuv/docs/src/guide/networking.rst view on Meta::CPAN
Time-to-live
~~~~~~~~~~~~
The TTL of packets sent on the socket can be changed using ``uv_udp_set_ttl``.
IPv6 stack only
~~~~~~~~~~~~~~~
IPv6 sockets can be used for both IPv4 and IPv6 communication. If you want to
restrict the socket to IPv6 only, pass the ``UV_UDP_IPV6ONLY`` flag to
``uv_udp_bind`` [#]_.
Multicast
~~~~~~~~~
A socket can (un)subscribe to a multicast group using:
.. literalinclude:: ../../../include/uv.h
:lines: 594-597
where ``membership`` is ``UV_JOIN_GROUP`` or ``UV_LEAVE_GROUP``.
libuv/docs/src/guide/networking.rst view on Meta::CPAN
libuv also provides the inverse `uv_getnameinfo`_.
.. _uv_getnameinfo: http://docs.libuv.org/en/v1.x/dns.html#c.uv_getnameinfo
Network interfaces
------------------
Information about the system's network interfaces can be obtained through libuv
using ``uv_interface_addresses``. This simple program just prints out all the
interface details so you get an idea of the fields that are available. This is
useful to allow your service to bind to IP addresses when it starts.
.. rubric:: interfaces/main.c
.. literalinclude:: ../../code/interfaces/main.c
:linenos:
:emphasize-lines: 9,17
``is_internal`` is true for loopback interfaces. Note that if a physical
interface has multiple IPv4/IPv6 addresses, the name will be reported multiple
times, with each address being reported once.
libuv/docs/src/guide/threads.rst view on Meta::CPAN
.. note::
mutexes and rwlocks **DO NOT** work inside a signal handler, whereas
``uv_async_send`` does.
One use case where ``uv_async_send`` is required is when interoperating with
libraries that require thread affinity for their functionality. For example in
node.js, a v8 engine instance, contexts and its objects are bound to the thread
that the v8 instance was started in. Interacting with v8 data structures from
another thread can lead to undefined results. Now consider some node.js module
which binds a third party library. It may go something like this:
1. In node, the third party library is set up with a JavaScript callback to be
invoked for more information::
var lib = require('lib');
lib.on_progress(function() {
console.log("Progress");
});
lib.do();
// do other stuff
2. ``lib.do`` is supposed to be non-blocking but the third party lib is
blocking, so the binding uses ``uv_queue_work``.
3. The actual work being done in a separate thread wants to invoke the progress
callback, but cannot directly call into v8 to interact with JavaScript. So
it uses ``uv_async_send``.
4. The async callback, invoked in the main loop thread, which is the v8 thread,
then interacts with v8 to invoke the JavaScript callback.
.. _pthreads: http://man7.org/linux/man-pages/man7/pthreads.7.html
libuv/docs/src/guide/utilities.rst view on Meta::CPAN
Check & Prepare watchers
------------------------
TODO
Loading libraries
-----------------
libuv provides a cross platform API to dynamically load `shared libraries`_.
This can be used to implement your own plugin/extension/module system and is
used by node.js to implement ``require()`` support for bindings. The usage is
quite simple as long as your library exports the right symbols. Be careful with
sanity and security checks when loading third party code, otherwise your
program will behave unpredictably. This example implements a very simple
plugin system which does nothing except print the name of the plugin.
Let us first look at the interface provided to plugin authors.
.. rubric:: plugin/plugin.h
.. literalinclude:: ../../code/plugin/plugin.h
:linenos:
libuv/docs/src/guide/utilities.rst view on Meta::CPAN
can try `ncurses`_.
.. _ncurses: http://www.gnu.org/software/ncurses/ncurses.html
.. versionchanged:: 1.23.1: the `readable` parameter is now unused and ignored.
The appropriate value will now be auto-detected from the kernel.
----
.. [#] I was first introduced to the term baton in this context, in Konstantin
Käfer's excellent slides on writing node.js bindings --
http://kkaefer.github.com/node-cpp-modules/#baton
.. [#] mfp is My Fancy Plugin
.. _libev man page: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#COMMON_OR_USEFUL_IDIOMS_OR_BOTH
libuv/docs/src/handle.rst view on Meta::CPAN
See :ref:`refcount`.
.. c:function:: int uv_has_ref(const uv_handle_t* handle)
Returns non-zero if the handle referenced, zero otherwise.
See :ref:`refcount`.
.. c:function:: size_t uv_handle_size(uv_handle_type type)
Returns the size of the given handle type. Useful for FFI binding writers
who don't want to know the structure layout.
Miscellaneous API functions
---------------------------
The following API functions take a :c:type:`uv_handle_t` argument but they work
just for some handle types.
.. c:function:: int uv_send_buffer_size(uv_handle_t* handle, int* value)
libuv/docs/src/loop.rst view on Meta::CPAN
.. c:function:: void uv_stop(uv_loop_t* loop)
Stop the event loop, causing :c:func:`uv_run` to end as soon as
possible. This will happen not sooner than the next loop iteration.
If this function was called before blocking for i/o, the loop won't block
for i/o on this iteration.
.. c:function:: size_t uv_loop_size(void)
Returns the size of the `uv_loop_t` structure. Useful for FFI binding
writers who don't want to know the structure layout.
.. c:function:: int uv_backend_fd(const uv_loop_t* loop)
Get backend file descriptor. Only kqueue, epoll and event ports are
supported.
This can be used in conjunction with `uv_run(loop, UV_RUN_NOWAIT)` to
poll in one thread and run the event loop's callbacks in another see
test/test-embed.c for an example.
libuv/docs/src/migration_010_100.rst view on Meta::CPAN
void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
buf->base = malloc(size);
buf->len = size;
}
Unification of IPv4 / IPv6 APIs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libuv 1.0 unified the IPv4 and IPv6 APIS. There is no longer a `uv_tcp_bind` and `uv_tcp_bind6`
duality, there is only :c:func:`uv_tcp_bind` now.
IPv4 functions took ``struct sockaddr_in`` structures by value, and IPv6 functions took
``struct sockaddr_in6``. Now functions take a ``struct sockaddr*`` (note it's a pointer).
It can be stack allocated.
libuv 0.10
::
struct sockaddr_in addr = uv_ip4_addr("0.0.0.0", 1234);
...
uv_tcp_bind(&server, addr)
libuv 1.0
::
struct sockaddr_in addr;
uv_ip4_addr("0.0.0.0", 1234, &addr)
...
uv_tcp_bind(&server, (const struct sockaddr*) &addr, 0);
The IPv4 and IPv6 struct creating functions (:c:func:`uv_ip4_addr` and :c:func:`uv_ip6_addr`)
have also changed, make sure you check the documentation.
..note::
This change applies to all functions that made a distinction between IPv4 and IPv6
addresses.
Streams / UDP data receive callback API change
libuv/docs/src/pipe.rst view on Meta::CPAN
.. c:function:: int uv_pipe_open(uv_pipe_t* handle, uv_file file)
Open an existing file descriptor or HANDLE as a pipe.
.. versionchanged:: 1.2.1 the file descriptor is set to non-blocking mode.
.. note::
The passed file descriptor or HANDLE is not checked for its type, but
it's required that it represents a valid pipe.
.. c:function:: int uv_pipe_bind(uv_pipe_t* handle, const char* name)
Bind the pipe to a file path (Unix) or a name (Windows).
.. note::
Paths on Unix get truncated to ``sizeof(sockaddr_un.sun_path)`` bytes, typically between
92 and 108 bytes.
.. c:function:: void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, const char* name, uv_connect_cb cb)
Connect to the Unix domain socket or the named pipe.
libuv/docs/src/request.rst view on Meta::CPAN
Here is how cancellation is reported to the callback:
* A :c:type:`uv_fs_t` request has its req->result field set to `UV_ECANCELED`.
* A :c:type:`uv_work_t`, :c:type:`uv_getaddrinfo_t` or c:type:`uv_getnameinfo_t`
request has its callback invoked with status == `UV_ECANCELED`.
.. c:function:: size_t uv_req_size(uv_req_type type)
Returns the size of the given request type. Useful for FFI binding writers
who don't want to know the structure layout.
.. c:function:: void* uv_req_get_data(const uv_req_t* req)
Returns `req->data`.
.. versionadded:: 1.19.0
.. c:function:: void* uv_req_set_data(uv_req_t* req, void* data)
libuv/docs/src/tcp.rst view on Meta::CPAN
.. c:function:: int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable)
Enable / disable simultaneous asynchronous accept requests that are
queued by the operating system when listening for new TCP connections.
This setting is used to tune a TCP server for the desired performance.
Having simultaneous accepts can significantly improve the rate of accepting
connections (which is why it is enabled by default) but may lead to uneven
load distribution in multi-process setups.
.. c:function:: int uv_tcp_bind(uv_tcp_t* handle, const struct sockaddr* addr, unsigned int flags)
Bind the handle to an address and port. `addr` should point to an
initialized ``struct sockaddr_in`` or ``struct sockaddr_in6``.
When the port is already taken, you can expect to see an ``UV_EADDRINUSE``
error from either :c:func:`uv_tcp_bind`, :c:func:`uv_listen` or
:c:func:`uv_tcp_connect`. That is, a successful call to this function does
not guarantee that the call to :c:func:`uv_listen` or :c:func:`uv_tcp_connect`
will succeed as well.
`flags` can contain ``UV_TCP_IPV6ONLY``, in which case dual-stack support
is disabled and only IPv6 is used.
.. c:function:: int uv_tcp_getsockname(const uv_tcp_t* handle, struct sockaddr* name, int* namelen)
Get the current address to which the handle is bound. `name` must point to
libuv/docs/src/udp.rst view on Meta::CPAN
.. c:type:: uv_udp_t
UDP handle type.
.. c:type:: uv_udp_send_t
UDP send request type.
.. c:type:: uv_udp_flags
Flags used in :c:func:`uv_udp_bind` and :c:type:`uv_udp_recv_cb`..
::
enum uv_udp_flags {
/* Disables dual stack mode. */
UV_UDP_IPV6ONLY = 1,
/*
* Indicates message was truncated because read buffer was too small. The
* remainder was discarded by the OS. Used in uv_udp_recv_cb.
*/
UV_UDP_PARTIAL = 2,
/*
* Indicates if SO_REUSEADDR will be set when binding the handle in
* uv_udp_bind.
* This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
* Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
* multiple threads or processes can bind to the same address without error
* (provided they all set the flag) but only the last one to bind will receive
* any traffic, in effect "stealing" the port from the previous listener.
*/
UV_UDP_REUSEADDR = 4
};
.. c:type:: void (*uv_udp_send_cb)(uv_udp_send_t* req, int status)
Type definition for callback passed to :c:func:`uv_udp_send`, which is
called after the data was sent.
libuv/docs/src/udp.rst view on Meta::CPAN
contract (works in unconnected mode, supports sendmsg()/recvmsg(), etc).
In other words, other datagram-type sockets like raw sockets or netlink
sockets can also be passed to this function.
.. versionchanged:: 1.2.1 the file descriptor is set to non-blocking mode.
.. note::
The passed file descriptor or SOCKET is not checked for its type, but
it's required that it represents a valid datagram socket.
.. c:function:: int uv_udp_bind(uv_udp_t* handle, const struct sockaddr* addr, unsigned int flags)
Bind the UDP handle to an IP address and port.
:param handle: UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:param addr: `struct sockaddr_in` or `struct sockaddr_in6`
with the address and port to bind to.
:param flags: Indicate how the socket will be bound,
``UV_UDP_IPV6ONLY`` and ``UV_UDP_REUSEADDR`` are supported.
:returns: 0 on success, or an error code < 0 on failure.
.. c:function:: int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr)
Associate the UDP handle to a remote address and port, so every
message sent by this handle is automatically sent to that destination.
libuv/docs/src/udp.rst view on Meta::CPAN
:param handle: UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:param ttl: 1 through 255.
:returns: 0 on success, or an error code < 0 on failure.
.. c:function:: int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr* addr, uv_udp_send_cb send_cb)
Send data over the UDP socket. If the socket has not previously been bound
with :c:func:`uv_udp_bind` it will be bound to 0.0.0.0
(the "all interfaces" IPv4 address) and a random port number.
On Windows if the `addr` is initialized to point to an unspecified address
(``0.0.0.0`` or ``::``) it will be changed to point to ``localhost``.
This is done to match the behavior of Linux systems.
For connected UDP handles, `addr` must be set to `NULL`, otherwise it will
return `UV_EISCONN` error.
For connectionless UDP handles, `addr` cannot be `NULL`, otherwise it will
libuv/docs/src/udp.rst view on Meta::CPAN
:returns: >= 0: number of bytes sent (it matches the given buffer size).
< 0: negative error code (``UV_EAGAIN`` is returned when the message
can't be sent immediately).
.. versionchanged:: 1.27.0 added support for connected sockets
.. c:function:: int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
Prepare for receiving data. If the socket has not previously been bound
with :c:func:`uv_udp_bind` it is bound to 0.0.0.0 (the "all interfaces"
IPv4 address) and a random port number.
:param handle: UDP handle. Should have been initialized with
:c:func:`uv_udp_init`.
:param alloc_cb: Callback to invoke when temporary storage is needed.
:param recv_cb: Callback to invoke with received data.
:returns: 0 on success, or an error code < 0 on failure.
libuv/include/uv.h view on Meta::CPAN
UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
UV_EXTERN int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags);
UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle,
int enable,
unsigned int delay);
UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
enum uv_tcp_flags {
/* Used with uv_tcp_bind, when an IPv6 address is used. */
UV_TCP_IPV6ONLY = 1
};
UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
const struct sockaddr* addr,
unsigned int flags);
UV_EXTERN int uv_tcp_getsockname(const uv_tcp_t* handle,
struct sockaddr* name,
int* namelen);
UV_EXTERN int uv_tcp_getpeername(const uv_tcp_t* handle,
struct sockaddr* name,
int* namelen);
UV_EXTERN int uv_tcp_connect(uv_connect_t* req,
uv_tcp_t* handle,
libuv/include/uv.h view on Meta::CPAN
enum uv_udp_flags {
/* Disables dual stack mode. */
UV_UDP_IPV6ONLY = 1,
/*
* Indicates message was truncated because read buffer was too small. The
* remainder was discarded by the OS. Used in uv_udp_recv_cb.
*/
UV_UDP_PARTIAL = 2,
/*
* Indicates if SO_REUSEADDR will be set when binding the handle.
* This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
* Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
* multiple threads or processes can bind to the same address without error
* (provided they all set the flag) but only the last one to bind will receive
* any traffic, in effect "stealing" the port from the previous listener.
*/
UV_UDP_REUSEADDR = 4
};
typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
ssize_t nread,
const uv_buf_t* buf,
const struct sockaddr* addr,
libuv/include/uv.h view on Meta::CPAN
struct uv_udp_send_s {
UV_REQ_FIELDS
uv_udp_t* handle;
uv_udp_send_cb cb;
UV_UDP_SEND_PRIVATE_FIELDS
};
UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
UV_EXTERN int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags);
UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
const struct sockaddr* addr,
unsigned int flags);
UV_EXTERN int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr);
UV_EXTERN int uv_udp_getpeername(const uv_udp_t* handle,
struct sockaddr* name,
int* namelen);
UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle,
struct sockaddr* name,
int* namelen);
libuv/include/uv.h view on Meta::CPAN
*/
struct uv_pipe_s {
UV_HANDLE_FIELDS
UV_STREAM_FIELDS
int ipc; /* non-zero if this pipe is used for passing handles */
UV_PIPE_PRIVATE_FIELDS
};
UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);
UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
UV_EXTERN void uv_pipe_connect(uv_connect_t* req,
uv_pipe_t* handle,
const char* name,
uv_connect_cb cb);
UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle,
char* buffer,
size_t* size);
UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle,
char* buffer,
size_t* size);
libuv/samples/socks5-proxy/client.c view on Meta::CPAN
if (size != 0) {
pr_err("junk in request %u", (unsigned) size);
return do_kill(cx);
}
if (err != s5_exec_cmd) {
pr_err("request error: %s", s5_strerror(err));
return do_kill(cx);
}
if (parser->cmd == s5_cmd_tcp_bind) {
/* Not supported but relatively straightforward to implement. */
pr_warn("BIND requests are not supported.");
return do_kill(cx);
}
if (parser->cmd == s5_cmd_udp_assoc) {
/* Not supported. Might be hard to implement because libuv has no
* functionality for detecting the MTU size which the RFC mandates.
*/
pr_warn("UDP ASSOC requests are not supported.");
libuv/samples/socks5-proxy/defs.h view on Meta::CPAN
#include <assert.h>
#include <netinet/in.h> /* sockaddr_in, sockaddr_in6 */
#include <stddef.h> /* size_t, ssize_t */
#include <stdint.h>
#include <sys/socket.h> /* sockaddr */
struct client_ctx;
typedef struct {
const char *bind_host;
unsigned short bind_port;
unsigned int idle_timeout;
} server_config;
typedef struct {
unsigned int idle_timeout; /* Connection idle timeout in ms. */
uv_tcp_t tcp_handle;
uv_loop_t *loop;
} server_ctx;
typedef struct {
libuv/samples/socks5-proxy/main.c view on Meta::CPAN
static void usage(void);
static const char *progname = __FILE__; /* Reset in main(). */
int main(int argc, char **argv) {
server_config config;
int err;
progname = argv[0];
memset(&config, 0, sizeof(config));
config.bind_host = DEFAULT_BIND_HOST;
config.bind_port = DEFAULT_BIND_PORT;
config.idle_timeout = DEFAULT_IDLE_TIMEOUT;
parse_opts(&config, argc, argv);
err = server_run(&config, uv_default_loop());
if (err) {
exit(1);
}
return 0;
}
libuv/samples/socks5-proxy/main.c view on Meta::CPAN
const char *_getprogname(void) {
return progname;
}
static void parse_opts(server_config *cf, int argc, char **argv) {
int opt;
while (-1 != (opt = getopt(argc, argv, "b:hp:"))) {
switch (opt) {
case 'b':
cf->bind_host = optarg;
break;
case 'p':
if (1 != sscanf(optarg, "%hu", &cf->bind_port)) {
pr_err("bad port number: %s", optarg);
usage();
}
break;
default:
usage();
}
}
}
libuv/samples/socks5-proxy/s5.h view on Meta::CPAN
} s5_auth_result;
typedef enum {
s5_atyp_ipv4,
s5_atyp_ipv6,
s5_atyp_host
} s5_atyp;
typedef enum {
s5_cmd_tcp_connect,
s5_cmd_tcp_bind,
s5_cmd_udp_assoc
} s5_cmd;
typedef struct {
uint32_t arg0; /* Scratch space for the state machine. */
uint32_t arg1; /* Scratch space for the state machine. */
uint8_t state;
uint8_t methods;
uint8_t cmd;
uint8_t atyp;
libuv/samples/socks5-proxy/server.c view on Meta::CPAN
# define INET6_ADDRSTRLEN 63
#endif
typedef struct {
uv_getaddrinfo_t getaddrinfo_req;
server_config config;
server_ctx *servers;
uv_loop_t *loop;
} server_state;
static void do_bind(uv_getaddrinfo_t *req, int status, struct addrinfo *ai);
static void on_connection(uv_stream_t *server, int status);
int server_run(const server_config *cf, uv_loop_t *loop) {
struct addrinfo hints;
server_state state;
int err;
memset(&state, 0, sizeof(state));
state.servers = NULL;
state.config = *cf;
state.loop = loop;
/* Resolve the address of the interface that we should bind to.
* The getaddrinfo callback starts the server and everything else.
*/
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
err = uv_getaddrinfo(loop,
&state.getaddrinfo_req,
do_bind,
cf->bind_host,
NULL,
&hints);
if (err != 0) {
pr_err("getaddrinfo: %s", uv_strerror(err));
return err;
}
/* Start the event loop. Control continues in do_bind(). */
if (uv_run(loop, UV_RUN_DEFAULT)) {
abort();
}
/* Please Valgrind. */
uv_loop_delete(loop);
free(state.servers);
return 0;
}
/* Bind a server to each address that getaddrinfo() reported. */
static void do_bind(uv_getaddrinfo_t *req, int status, struct addrinfo *addrs) {
char addrbuf[INET6_ADDRSTRLEN + 1];
unsigned int ipv4_naddrs;
unsigned int ipv6_naddrs;
server_state *state;
server_config *cf;
struct addrinfo *ai;
const void *addrv;
const char *what;
uv_loop_t *loop;
server_ctx *sx;
libuv/samples/socks5-proxy/server.c view on Meta::CPAN
struct sockaddr addr;
struct sockaddr_in addr4;
struct sockaddr_in6 addr6;
} s;
state = CONTAINER_OF(req, server_state, getaddrinfo_req);
loop = state->loop;
cf = &state->config;
if (status < 0) {
pr_err("getaddrinfo(\"%s\"): %s", cf->bind_host, uv_strerror(status));
uv_freeaddrinfo(addrs);
return;
}
ipv4_naddrs = 0;
ipv6_naddrs = 0;
for (ai = addrs; ai != NULL; ai = ai->ai_next) {
if (ai->ai_family == AF_INET) {
ipv4_naddrs += 1;
} else if (ai->ai_family == AF_INET6) {
ipv6_naddrs += 1;
}
}
if (ipv4_naddrs == 0 && ipv6_naddrs == 0) {
pr_err("%s has no IPv4/6 addresses", cf->bind_host);
uv_freeaddrinfo(addrs);
return;
}
state->servers =
xmalloc((ipv4_naddrs + ipv6_naddrs) * sizeof(state->servers[0]));
n = 0;
for (ai = addrs; ai != NULL; ai = ai->ai_next) {
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) {
continue;
}
if (ai->ai_family == AF_INET) {
s.addr4 = *(const struct sockaddr_in *) ai->ai_addr;
s.addr4.sin_port = htons(cf->bind_port);
addrv = &s.addr4.sin_addr;
} else if (ai->ai_family == AF_INET6) {
s.addr6 = *(const struct sockaddr_in6 *) ai->ai_addr;
s.addr6.sin6_port = htons(cf->bind_port);
addrv = &s.addr6.sin6_addr;
} else {
UNREACHABLE();
}
if (uv_inet_ntop(s.addr.sa_family, addrv, addrbuf, sizeof(addrbuf))) {
UNREACHABLE();
}
sx = state->servers + n;
sx->loop = loop;
sx->idle_timeout = state->config.idle_timeout;
CHECK(0 == uv_tcp_init(loop, &sx->tcp_handle));
what = "uv_tcp_bind";
err = uv_tcp_bind(&sx->tcp_handle, &s.addr, 0);
if (err == 0) {
what = "uv_listen";
err = uv_listen((uv_stream_t *) &sx->tcp_handle, 128, on_connection);
}
if (err != 0) {
pr_err("%s(\"%s:%hu\"): %s",
what,
addrbuf,
cf->bind_port,
uv_strerror(err));
while (n > 0) {
n -= 1;
uv_close((uv_handle_t *) (state->servers + n), NULL);
}
break;
}
pr_info("listening on %s:%hu", addrbuf, cf->bind_port);
n += 1;
}
uv_freeaddrinfo(addrs);
}
static void on_connection(uv_stream_t *server, int status) {
server_ctx *sx;
client_ctx *cx;
libuv/src/unix/android-ifaddrs.c view on Meta::CPAN
socklen_t l_len;
int l_socket = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if(l_socket < 0)
{
return -1;
}
memset(&l_addr, 0, sizeof(l_addr));
l_addr.nl_family = AF_NETLINK;
if(bind(l_socket, (struct sockaddr *)&l_addr, sizeof(l_addr)) < 0)
{
close(l_socket);
return -1;
}
l_len = sizeof(l_addr);
if(getsockname(l_socket, (struct sockaddr *)&l_addr, &l_len) < 0)
{
close(l_socket);
return -1;
libuv/src/unix/pipe.c view on Meta::CPAN
int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
uv__stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE);
handle->shutdown_req = NULL;
handle->connect_req = NULL;
handle->pipe_fname = NULL;
handle->ipc = ipc;
return 0;
}
int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
struct sockaddr_un saddr;
const char* pipe_fname;
int sockfd;
int err;
pipe_fname = NULL;
/* Already bound? */
if (uv__stream_fd(handle) >= 0)
return UV_EINVAL;
libuv/src/unix/pipe.c view on Meta::CPAN
err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
if (err < 0)
goto err_socket;
sockfd = err;
memset(&saddr, 0, sizeof saddr);
uv__strscpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
err = UV__ERR(errno);
/* Convert ENOENT to EACCES for compatibility with Windows. */
if (err == UV_ENOENT)
err = UV_EACCES;
uv__close(sockfd);
goto err_socket;
}
/* Success. */