Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
win: udp support
  • Loading branch information
piscisaureus authored and bnoordhuis committed Aug 24, 2011
1 parent 36ce74f commit 5c9d749
Show file tree
Hide file tree
Showing 8 changed files with 611 additions and 2 deletions.
16 changes: 14 additions & 2 deletions include/uv-win.h
Expand Up @@ -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 { \
Expand All @@ -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 \
Expand Down Expand Up @@ -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]; \
Expand Down
1 change: 1 addition & 0 deletions include/uv.h
Expand Up @@ -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
};

Expand Down
1 change: 1 addition & 0 deletions src/win/error.c
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/win/handle.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/win/internal.h
Expand Up @@ -177,6 +177,15 @@ void uv_process_tcp_connect_req(uv_tcp_t* handle, uv_connect_t* req);
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
*/
Expand Down
9 changes: 9 additions & 0 deletions src/win/req.c
Expand Up @@ -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;
Expand Down

0 comments on commit 5c9d749

Please sign in to comment.