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

Commit

Permalink
win: change uv_getsockname signature to support udp
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and bnoordhuis committed Aug 24, 2011
1 parent 5c9d749 commit 1870c18
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/win/handle.c
Expand Up @@ -39,6 +39,21 @@ int uv_is_active(uv_handle_t* handle) {
}


int uv_getsockname(uv_handle_t* handle, struct sockaddr* name, int* namelen) {
switch (handle->type) {
case UV_TCP:
return uv_tcp_getsockname((uv_tcp_t*) handle, name, namelen);

case UV_UDP:
return uv_tcp_getsockname((uv_tcp_t*) handle, name, namelen);

default:
uv_set_sys_error(WSAENOTSOCK);
return -1;
}
}


void uv_close(uv_handle_t* handle, uv_close_cb cb) {
uv_tcp_t* tcp;
uv_pipe_t* pipe;
Expand Down
5 changes: 4 additions & 1 deletion src/win/internal.h
Expand Up @@ -168,6 +168,7 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
uv_read_cb read_cb);
int uv_tcp_write(uv_write_t* req, uv_tcp_t* handle, uv_buf_t bufs[],
int bufcnt, uv_write_cb cb);
int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen);

void uv_process_tcp_read_req(uv_tcp_t* handle, uv_req_t* req);
void uv_process_tcp_write_req(uv_tcp_t* handle, uv_write_t* req);
Expand All @@ -180,11 +181,13 @@ void uv_tcp_endgame(uv_tcp_t* handle);
/*
* UDP
*/
void uv_udp_endgame(uv_udp_t* handle);
int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen);

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);

void uv_udp_endgame(uv_udp_t* handle);


/*
* Pipes
Expand Down
2 changes: 1 addition & 1 deletion src/win/tcp.c
Expand Up @@ -548,7 +548,7 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle,
}


int uv_getsockname(uv_handle_t* handle, struct sockaddr* name, int* namelen) {
int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int* namelen) {
int result;

if (handle->flags & UV_HANDLE_SHUTTING) {
Expand Down
18 changes: 18 additions & 0 deletions src/win/udp.c
Expand Up @@ -200,6 +200,24 @@ int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned int flags)
}


int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen) {
int result;

if (handle->flags & UV_HANDLE_SHUTTING) {
uv_set_sys_error(WSAESHUTDOWN);
return -1;
}

result = getsockname(handle->socket, name, namelen);
if (result != 0) {
uv_set_sys_error(WSAGetLastError());
return -1;
}

return 0;
}


static void uv_udp_queue_recv(uv_udp_t* handle) {
uv_req_t* req;
uv_buf_t buf;
Expand Down

0 comments on commit 1870c18

Please sign in to comment.