Permalink
Browse files

win: udp support

  • Loading branch information...
1 parent 36ce74f commit 5c9d749a574cc09af598c6d4e8bfcc4cb91720b2 @piscisaureus piscisaureus committed with bnoordhuis Aug 24, 2011
Showing with 611 additions and 2 deletions.
  1. +14 −2 include/uv-win.h
  2. +1 −0 include/uv.h
  3. +1 −0 src/win/error.c
  4. +14 −0 src/win/handle.c
  5. +9 −0 src/win/internal.h
  6. +9 −0 src/win/req.c
  7. +558 −0 src/win/udp.c
  8. +5 −0 uv.gyp
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 { \
@@ -69,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 \
@@ -114,7 +118,15 @@ typedef struct uv_buf_t {
struct { uv_tcp_connection_fields }; \
};
-#define UV_UDP_PRIVATE_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]; \
View
@@ -491,6 +491,7 @@ struct uv_udp_s {
struct uv_udp_send_s {
UV_REQ_FIELDS
uv_udp_t* handle;
+ uv_udp_send_cb cb;
UV_UDP_SEND_PRIVATE_FIELDS
};
View
@@ -109,6 +109,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case WSAEINVAL: return UV_EINVAL;
case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE;
case WSAEMFILE: return UV_EMFILE;
+ case WSAEMSGSIZE: return UV_EMSGSIZE;
case ERROR_NETWORK_UNREACHABLE: return UV_ENETUNREACH;
case WSAENETUNREACH: return UV_ENETUNREACH;
case ERROR_OUTOFMEMORY: return UV_ENOMEM;
View
@@ -42,6 +42,7 @@ int uv_is_active(uv_handle_t* handle) {
void uv_close(uv_handle_t* handle, uv_close_cb cb) {
uv_tcp_t* tcp;
uv_pipe_t* pipe;
+ uv_udp_t* udp;
uv_process_t* process;
if (handle->flags & UV_HANDLE_CLOSING) {
@@ -77,6 +78,15 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
}
return;
+ case UV_UDP:
+ udp = (uv_udp_t*) handle;
+ uv_udp_recv_stop(udp);
+ closesocket(udp->socket);
+ if (udp->reqs_pending == 0) {
+ uv_want_endgame(handle);
+ }
+ return;
+
case UV_TIMER:
uv_timer_stop((uv_timer_t*)handle);
uv_want_endgame(handle);
@@ -143,6 +153,10 @@ void uv_process_endgames() {
uv_pipe_endgame((uv_pipe_t*)handle);
break;
+ case UV_UDP:
+ uv_udp_endgame((uv_udp_t*) handle);
+ break;
+
case UV_TIMER:
uv_timer_endgame((uv_timer_t*)handle);
break;
View
@@ -178,6 +178,15 @@ void uv_tcp_endgame(uv_tcp_t* handle);
/*
+ * UDP
+ */
+void uv_udp_endgame(uv_udp_t* handle);
+
+void uv_process_udp_recv_req(uv_udp_t* handle, uv_req_t* req);
+void uv_process_udp_send_req(uv_udp_t* handle, uv_udp_send_t* req);
+
+
+/*
* Pipes
*/
int uv_pipe_init_with_handle(uv_pipe_t* handle, HANDLE pipeHandle);
View
@@ -117,6 +117,15 @@ void uv_process_reqs() {
(uv_pipe_t*) ((uv_shutdown_t*) req)->handle, (uv_shutdown_t*) req);
break;
+ case UV_UDP_RECV:
+ uv_process_udp_recv_req((uv_udp_t*) req->data, req);
+ break;
+
+ case UV_UDP_SEND:
+ uv_process_udp_send_req(((uv_udp_send_t*) req)->handle,
+ (uv_udp_send_t*) req);
+ break;
+
case UV_WAKEUP:
uv_process_async_wakeup_req((uv_async_t*) req->data, req);
break;
Oops, something went wrong.

0 comments on commit 5c9d749

Please sign in to comment.