Navigation Menu

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

Commit

Permalink
Igor's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Oct 20, 2011
1 parent 36903d3 commit ea9ee39
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 39 deletions.
25 changes: 24 additions & 1 deletion include/uv-private/uv-win.h
Expand Up @@ -104,6 +104,27 @@
DWORD dwFlags);
#endif

typedef int (WSAAPI* LPFN_WSARECV)
(SOCKET socket,
LPWSABUF buffers,
DWORD buffer_count,
LPDWORD bytes,
LPDWORD flags,
LPWSAOVERLAPPED overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE
completion_routine);

typedef int (WSAAPI* LPFN_WSARECVFROM)
(SOCKET socket,
LPWSABUF buffers,
DWORD buffer_count,
LPDWORD bytes,
LPDWORD flags,
struct sockaddr* addr,
LPINT addr_len,
LPWSAOVERLAPPED overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);


/**
* It should be possible to cast uv_buf_t[] to WSABUF[]
Expand Down Expand Up @@ -236,7 +257,9 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
struct sockaddr_storage recv_from; \
int recv_from_len; \
uv_udp_recv_cb recv_cb; \
uv_alloc_cb alloc_cb;
uv_alloc_cb alloc_cb; \
LPFN_WSARECV func_wsarecv; \
LPFN_WSARECVFROM func_wsarecvfrom;

#define uv_pipe_server_fields \
uv_pipe_accept_t accept_reqs[4]; \
Expand Down
2 changes: 1 addition & 1 deletion include/uv.h
Expand Up @@ -1061,7 +1061,7 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb);
int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
const char* new_path, uv_fs_cb cb);

/*
/*
* This flag can be used with uv_fs_symlink on Windows
* to specify whether path argument points to a directory.
*/
Expand Down
53 changes: 20 additions & 33 deletions src/win/udp.c
Expand Up @@ -109,6 +109,8 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle,
FILE_SKIP_SET_EVENT_ON_HANDLE |
FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) {
handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP;
handle->func_wsarecv = uv_wsarecv_workaround;
handle->func_wsarecvfrom = uv_wsarecvfrom_workaround;
} else if (GetLastError() != ERROR_INVALID_FUNCTION) {
uv__set_sys_error(loop, GetLastError());
return -1;
Expand All @@ -128,6 +130,8 @@ int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) {
handle->reqs_pending = 0;
handle->loop = loop;
handle->flags = 0;
handle->func_wsarecv = WSARecv;
handle->func_wsarecvfrom = WSARecvFrom;

uv_req_init(loop, (uv_req_t*) &(handle->recv_req));
handle->recv_req.type = UV_UDP_RECV;
Expand Down Expand Up @@ -254,11 +258,6 @@ static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) {
uv_buf_t buf;
DWORD bytes, flags;
int result;
int (WSAAPI *recvfrom)(SOCKET, WSABUF*, DWORD, DWORD*, DWORD*,
struct sockaddr*, int*, WSAOVERLAPPED*,
LPWSAOVERLAPPED_COMPLETION_ROUTINE);
int (WSAAPI *recv)(SOCKET, WSABUF*, DWORD, DWORD*, DWORD*,
WSAOVERLAPPED*, LPWSAOVERLAPPED_COMPLETION_ROUTINE);

assert(handle->flags & UV_HANDLE_READING);
assert(!(handle->flags & UV_HANDLE_READ_PENDING));
Expand All @@ -281,21 +280,15 @@ static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) {
handle->recv_from_len = sizeof handle->recv_from;
flags = 0;

if (handle->flags & UV_HANDLE_SYNC_BYPASS_IOCP) {
recvfrom = uv_wsarecvfrom_workaround;
} else {
recvfrom = WSARecvFrom;
}

result = recvfrom(handle->socket,
(WSABUF*) &buf,
1,
&bytes,
&flags,
(struct sockaddr*) &handle->recv_from,
&handle->recv_from_len,
&req->overlapped,
NULL);
result = handle->func_wsarecvfrom(handle->socket,
(WSABUF*) &buf,
1,
&bytes,
&flags,
(struct sockaddr*) &handle->recv_from,
&handle->recv_from_len,
&req->overlapped,
NULL);

if (UV_SUCCEEDED_WITHOUT_IOCP(result == 0)) {
/* Process the req without IOCP. */
Expand All @@ -321,19 +314,13 @@ static void uv_udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) {
buf.len = 0;
flags = MSG_PEEK;

if (handle->flags & UV_HANDLE_SYNC_BYPASS_IOCP) {
recv = uv_wsarecv_workaround;
} else {
recv = WSARecv;
}

result = recv(handle->socket,
(WSABUF*) &buf,
1,
&bytes,
&flags,
&req->overlapped,
NULL);
result = handle->func_wsarecv(handle->socket,
(WSABUF*) &buf,
1,
&bytes,
&flags,
&req->overlapped,
NULL);

if (UV_SUCCEEDED_WITHOUT_IOCP(result == 0)) {
/* Process the req without IOCP. */
Expand Down
2 changes: 1 addition & 1 deletion src/win/winapi.c
Expand Up @@ -62,7 +62,7 @@ void uv_winapi_init() {
ntdll_module,
"NtDeviceIoControlFile");
if (pNtDeviceIoControlFile == NULL) {
uv_fatal_error(GetLastError(), "NtDeviceIoControlFile");
uv_fatal_error(GetLastError(), "GetProcAddress");
}

pNtSetInformationFile = (sNtSetInformationFile) GetProcAddress(
Expand Down
1 change: 0 additions & 1 deletion src/win/winapi.h
Expand Up @@ -4343,7 +4343,6 @@ typedef BOOLEAN (WINAPI* sCreateSymbolicLinkW)
/* Ntapi function pointers */
extern sRtlNtStatusToDosError pRtlNtStatusToDosError;
extern sNtDeviceIoControlFile pNtDeviceIoControlFile;
extern sNtDeviceIoControlFile pNtDeviceIoControlFile;
extern sNtQueryInformationFile pNtQueryInformationFile;
extern sNtSetInformationFile pNtSetInformationFile;

Expand Down
2 changes: 0 additions & 2 deletions src/win/winsock.h
Expand Up @@ -84,8 +84,6 @@ typedef struct _AFD_RECV_INFO {
ULONG BufferCount;
ULONG AfdFlags;
ULONG TdiFlags;
struct sockaddr* Address;
int* AddressLength;
} AFD_RECV_INFO, *PAFD_RECV_INFO;


Expand Down

0 comments on commit ea9ee39

Please sign in to comment.