Permalink
Browse files

uv: upgrade to 80e5491

  • Loading branch information...
1 parent 7003d6e commit 28998a8cfe92043b27ff573b54258e21123616a4 @bnoordhuis bnoordhuis committed Aug 23, 2011
Showing with 6,505 additions and 109 deletions.
  1. +6 −4 deps/uv/README
  2. +20 −0 deps/uv/include/uv-unix.h
  3. +17 −4 deps/uv/include/uv-win.h
  4. +157 −3 deps/uv/include/uv.h
  5. +547 −10 deps/uv/src/uv-unix.c
  6. +0 −1 deps/uv/src/win/async.c
  7. +0 −8 deps/uv/src/win/core.c
  8. +1 −0 deps/uv/src/win/error.c
  9. +31 −9 deps/uv/src/win/handle.c
  10. +40 −1 deps/uv/src/win/internal.h
  11. +0 −1 deps/uv/src/win/loop-watcher.c
  12. +20 −23 deps/uv/src/win/pipe.c
  13. +0 −1 deps/uv/src/win/process.c
  14. +10 −1 deps/uv/src/win/req.c
  15. +0 −1 deps/uv/src/win/stream.c
  16. +22 −19 deps/uv/src/win/tcp.c
  17. +0 −1 deps/uv/src/win/timer.c
  18. +576 −0 deps/uv/src/win/udp.c
  19. +4,040 −2 deps/uv/src/win/winapi.h
  20. +115 −0 deps/uv/src/win/winsock.c
  21. +6 −2 deps/uv/src/win/winsock.h
  22. +21 −0 deps/uv/test/benchmark-list.h
  23. +1 −1 deps/uv/test/benchmark-ping-pongs.c
  24. +2 −2 deps/uv/test/benchmark-pound.c
  25. +2 −2 deps/uv/test/benchmark-pump.c
  26. +1 −1 deps/uv/test/benchmark-spawn.c
  27. +247 −0 deps/uv/test/benchmark-udp-packet-storm.c
  28. +1 −1 deps/uv/test/dns-server.c
  29. +1 −1 deps/uv/test/echo-server.c
  30. +1 −1 deps/uv/test/test-callback-stack.c
  31. +1 −1 deps/uv/test/test-delayed-accept.c
  32. +4 −4 deps/uv/test/test-getsockname.c
  33. +9 −0 deps/uv/test/test-list.h
  34. +1 −1 deps/uv/test/test-ping-pong.c
  35. +1 −1 deps/uv/test/test-shutdown-eof.c
  36. +1 −1 deps/uv/test/test-spawn.c
  37. +1 −1 deps/uv/test/test-tcp-writealot.c
  38. +88 −0 deps/uv/test/test-udp-dgram-too-big.c
  39. +141 −0 deps/uv/test/test-udp-ipv6-only.c
  40. +158 −0 deps/uv/test/test-udp-ipv6.c
  41. +210 −0 deps/uv/test/test-udp-send-and-recv.c
  42. +5 −0 deps/uv/uv.gyp
View
@@ -24,13 +24,15 @@ checkout GYP into the project tree manually:
svn co http://gyp.googlecode.com/svn/trunk build/gyp
-And then run
+Unix users run
- ./build/gyp_uv -f make
+ ./gyp_uv -f make
+ make
-or
+Macintosh users run
- ./build/gyp_uv -f xcode
+ ./gyp_uv -f xcode
+ xcodebuild -project uv.xcodeproj -configuration Release -target All
= Supported Platforms
View
@@ -55,6 +55,16 @@ typedef struct {
#define UV_CONNECT_PRIVATE_FIELDS \
ngx_queue_t queue;
+#define UV_UDP_SEND_PRIVATE_FIELDS \
+ ngx_queue_t queue; \
+ struct sockaddr_storage addr; \
+ socklen_t addrlen; \
+ uv_buf_t* bufs; \
+ int bufcnt; \
+ ssize_t status; \
+ uv_udp_send_cb send_cb; \
+ uv_buf_t bufsml[UV_REQ_BUFSML_SIZE]; \
+
#define UV_PRIVATE_REQ_TYPES /* empty */
@@ -83,6 +93,16 @@ typedef struct {
#define UV_TCP_PRIVATE_FIELDS
+/* UV_UDP */
+#define UV_UDP_PRIVATE_FIELDS \
+ uv_alloc_cb alloc_cb; \
+ uv_udp_recv_cb recv_cb; \
+ ev_io read_watcher; \
+ ev_io write_watcher; \
+ ngx_queue_t write_queue; \
+ ngx_queue_t write_completed_queue; \
+
+
/* UV_NAMED_PIPE */
#define UV_PIPE_PRIVATE_TYPEDEF
#define UV_PIPE_PRIVATE_FIELDS \
View
@@ -48,7 +48,8 @@ typedef struct uv_buf_t {
UV_ARES_CLEANUP_REQ, \
UV_GETADDRINFO_REQ, \
UV_PROCESS_EXIT, \
- UV_PROCESS_CLOSE
+ UV_PROCESS_CLOSE, \
+ UV_UDP_RECV
#define UV_REQ_PRIVATE_FIELDS \
union { \
@@ -58,7 +59,6 @@ typedef struct uv_buf_t {
size_t queued_bytes; \
}; \
}; \
- uv_err_t error; \
struct uv_req_s* next_req;
#define UV_WRITE_PRIVATE_FIELDS \
@@ -70,6 +70,9 @@ typedef struct uv_buf_t {
#define UV_SHUTDOWN_PRIVATE_FIELDS \
/* empty */
+#define UV_UDP_SEND_PRIVATE_FIELDS \
+ /* empty */
+
#define UV_PRIVATE_REQ_TYPES \
typedef struct uv_pipe_accept_s { \
UV_REQ_FIELDS \
@@ -109,11 +112,22 @@ typedef struct uv_buf_t {
#define UV_TCP_PRIVATE_FIELDS \
SOCKET socket; \
+ uv_err_t bind_error; \
union { \
struct { uv_tcp_server_fields }; \
struct { uv_tcp_connection_fields }; \
};
+#define UV_UDP_PRIVATE_FIELDS \
+ SOCKET socket; \
+ unsigned int reqs_pending; \
+ uv_req_t recv_req; \
+ uv_buf_t recv_buffer; \
+ struct sockaddr_storage recv_from; \
+ int recv_from_len; \
+ uv_udp_recv_cb recv_cb; \
+ uv_alloc_cb alloc_cb;
+
#define uv_pipe_server_fields \
uv_pipe_accept_t accept_reqs[4]; \
uv_pipe_accept_t* pending_accepts;
@@ -157,8 +171,7 @@ typedef struct uv_buf_t {
#define UV_HANDLE_PRIVATE_FIELDS \
uv_handle_t* endgame_next; \
- unsigned int flags; \
- uv_err_t error;
+ unsigned int flags;
#define UV_ARES_TASK_PRIVATE_FIELDS \
struct uv_req_s ares_req; \
View
@@ -45,6 +45,7 @@ typedef struct uv_err_s uv_err_t;
typedef struct uv_handle_s uv_handle_t;
typedef struct uv_stream_s uv_stream_t;
typedef struct uv_tcp_s uv_tcp_t;
+typedef struct uv_udp_s uv_udp_t;
typedef struct uv_pipe_s uv_pipe_t;
typedef struct uv_timer_s uv_timer_t;
typedef struct uv_prepare_s uv_prepare_t;
@@ -58,6 +59,7 @@ typedef struct uv_req_s uv_req_t;
typedef struct uv_shutdown_s uv_shutdown_t;
typedef struct uv_write_s uv_write_t;
typedef struct uv_connect_s uv_connect_t;
+typedef struct uv_udp_send_s uv_udp_send_t;
#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
# include "uv-unix.h"
@@ -106,8 +108,8 @@ int64_t uv_now();
* In the case of uv_read_cb the uv_buf_t returned should be freed by the
* user.
*/
-typedef uv_buf_t (*uv_alloc_cb)(uv_stream_t* tcp, size_t suggested_size);
-typedef void (*uv_read_cb)(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf);
+typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size);
+typedef void (*uv_read_cb)(uv_stream_t* stream, ssize_t nread, uv_buf_t buf);
typedef void (*uv_write_cb)(uv_write_t* req, int status);
typedef void (*uv_connect_cb)(uv_connect_t* req, int status);
typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status);
@@ -146,6 +148,7 @@ typedef enum {
UV_EINVAL,
UV_EISCONN,
UV_EMFILE,
+ UV_EMSGSIZE,
UV_ENETDOWN,
UV_ENETUNREACH,
UV_ENFILE,
@@ -172,6 +175,7 @@ typedef enum {
typedef enum {
UV_UNKNOWN_HANDLE = 0,
UV_TCP,
+ UV_UDP,
UV_NAMED_PIPE,
UV_TTY,
UV_FILE,
@@ -194,6 +198,7 @@ typedef enum {
UV_WRITE,
UV_SHUTDOWN,
UV_WAKEUP,
+ UV_UDP_SEND,
UV_REQ_TYPE_PRIVATE
} uv_req_type;
@@ -415,7 +420,155 @@ struct uv_connect_s {
};
-int uv_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen);
+int uv_getsockname(uv_handle_t* handle, struct sockaddr* name, int* namelen);
+
+
+/*
+ * UDP support.
+ */
+
+enum uv_udp_flags {
+ /* Disables dual stack mode. Used with uv_udp_bind6(). */
+ 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
+};
+
+/*
+ * Called after a uv_udp_send() or uv_udp_send6(). status 0 indicates
+ * success otherwise error.
+ */
+typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
+
+/*
+ * Callback that is invoked when a new UDP datagram is received.
+ *
+ * handle UDP handle.
+ * nread Number of bytes that have been received.
+ * 0 if there is no more data to read. You may
+ * discard or repurpose the read buffer.
+ * -1 if a transmission error was detected.
+ * buf uv_buf_t with the received data.
+ * addr struct sockaddr_in or struct sockaddr_in6.
+ * Valid for the duration of the callback only.
+ * flags One or more OR'ed UV_UDP_* constants.
+ * Right now only UV_UDP_PARTIAL is used.
+ */
+typedef void (*uv_udp_recv_cb)(uv_udp_t* handle, ssize_t nread, uv_buf_t buf,
+ struct sockaddr* addr, unsigned flags);
+
+/* uv_udp_t is a subclass of uv_handle_t */
+struct uv_udp_s {
+ UV_HANDLE_FIELDS
+ UV_UDP_PRIVATE_FIELDS
+};
+
+/* uv_udp_send_t is a subclass of uv_req_t */
+struct uv_udp_send_s {
+ UV_REQ_FIELDS
+ uv_udp_t* handle;
+ uv_udp_send_cb cb;
+ UV_UDP_SEND_PRIVATE_FIELDS
+};
+
+/*
+ * Initialize a new UDP handle. The actual socket is created lazily.
+ * Returns 0 on success.
+ */
+int uv_udp_init(uv_udp_t* handle);
+
+/*
+ * Bind to a IPv4 address and port.
+ *
+ * Arguments:
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
+ * addr struct sockaddr_in with the address and port to bind to.
+ * flags Unused.
+ *
+ * Returns:
+ * 0 on success, -1 on error.
+ */
+int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags);
+
+/*
+ * Bind to a IPv6 address and port.
+ *
+ * Arguments:
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
+ * addr struct sockaddr_in with the address and port to bind to.
+ * flags Should be 0 or UV_UDP_IPV6ONLY.
+ *
+ * Returns:
+ * 0 on success, -1 on error.
+ */
+int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags);
+
+/*
+ * Send data. If the socket has not previously been bound with `uv_udp_bind`
+ * or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
+ * and a random port number.
+ *
+ * Arguments:
+ * req UDP request handle. Need not be initialized.
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
+ * bufs List of buffers to send.
+ * bufcnt Number of buffers in `bufs`.
+ * addr Address of the remote peer. See `uv_ip4_addr`.
+ * send_cb Callback to invoke when the data has been sent out.
+ *
+ * Returns:
+ * 0 on success, -1 on error.
+ */
+int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
+ int bufcnt, struct sockaddr_in addr, uv_udp_send_cb send_cb);
+
+/*
+ * Send data. If the socket has not previously been bound with `uv_udp_bind6`,
+ * it is bound to ::0 (the "all interfaces" address) and a random port number.
+ *
+ * Arguments:
+ * req UDP request handle. Need not be initialized.
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
+ * bufs List of buffers to send.
+ * bufcnt Number of buffers in `bufs`.
+ * addr Address of the remote peer. See `uv_ip6_addr`.
+ * send_cb Callback to invoke when the data has been sent out.
+ *
+ * Returns:
+ * 0 on success, -1 on error.
+ */
+int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
+ int bufcnt, struct sockaddr_in6 addr, uv_udp_send_cb send_cb);
+
+/*
+ * Send data. If the socket has not previously been bound with `uv_udp_bind`
+ * or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
+ * and a random port number.
+ *
+ * Arguments:
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
+ * alloc_cb Callback to invoke when temporary storage is needed.
+ * recv_cb Callback to invoke with received data.
+ *
+ * Returns:
+ * 0 on success, -1 on error.
+ */
+int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
+ uv_udp_recv_cb recv_cb);
+
+/*
+ * Stop listening for incoming datagrams.
+ *
+ * Arguments:
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
+ *
+ * Returns:
+ * 0 on success, -1 on error.
+ */
+int uv_udp_recv_stop(uv_udp_t* handle);
/*
@@ -699,6 +852,7 @@ typedef struct {
uint64_t handle_init;
uint64_t stream_init;
uint64_t tcp_init;
+ uint64_t udp_init;
uint64_t pipe_init;
uint64_t prepare_init;
uint64_t check_init;
Oops, something went wrong.

0 comments on commit 28998a8

Please sign in to comment.