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

Commit

Permalink
ipc on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Zinkovsky committed Oct 5, 2011
1 parent 29881be commit 6f3e89b
Show file tree
Hide file tree
Showing 14 changed files with 762 additions and 290 deletions.
23 changes: 18 additions & 5 deletions include/uv-private/uv-win.h
Expand Up @@ -43,6 +43,11 @@ typedef struct uv_buf_t {
char* base;
} uv_buf_t;

typedef struct uv_duplicate_socket_info_s {
WSAPROTOCOL_INFOW socket_info;
struct uv_duplicate_socket_info_s* next;
} uv_duplicate_socket_info_t;

typedef int uv_file;

RB_HEAD(uv_timer_tree_s, uv_timer_s);
Expand Down Expand Up @@ -120,6 +125,8 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
UV_REQ_FIELDS \
SOCKET accept_socket; \
char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \
HANDLE event_handle; \

This comment has been minimized.

Copy link
@piscisaureus

piscisaureus Oct 5, 2011

For now, this seems right; eventually it may be better to add these handles to uv_req_s. Maybe we can also unify the life cycles of these handles then.

HANDLE wait_handle; \
struct uv_tcp_accept_s* next_pending; \
} uv_tcp_accept_t;

Expand All @@ -140,10 +147,12 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);

#define uv_tcp_server_fields \
uv_tcp_accept_t* accept_reqs; \
uv_tcp_accept_t* pending_accepts;
uv_tcp_accept_t* pending_accepts; \
LPFN_ACCEPTEX func_acceptex;

#define uv_tcp_connection_fields \
uv_buf_t read_buffer;
uv_buf_t read_buffer; \
LPFN_CONNECTEX func_connectex;

#define UV_TCP_PRIVATE_FIELDS \
SOCKET socket; \
Expand All @@ -164,11 +173,15 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
uv_alloc_cb alloc_cb;

#define uv_pipe_server_fields \
uv_pipe_accept_t accept_reqs[4]; \
uv_pipe_accept_t* pending_accepts;
uv_pipe_accept_t accept_reqs[4]; \
uv_pipe_accept_t* pending_accepts;

#define uv_pipe_connection_fields \
uv_timer_t* eof_timer;
uv_timer_t* eof_timer; \
uv_write_t ipc_header_write_req; \

This comment has been minimized.

Copy link
@piscisaureus

piscisaureus Oct 5, 2011

Will this work if the user calls uv_write2 twice? It seems to me that the second write2 would clobber it.

This comment has been minimized.

Copy link
@igorzi

igorzi Oct 5, 2011

good point.. will fix.

int ipc_pid; \
uint64_t remaining_ipc_rawdata_bytes; \
uv_duplicate_socket_info_t* pending_ipc_sockets;

This comment has been minimized.

Copy link
@piscisaureus

piscisaureus Oct 5, 2011

I am tempted to think that we should just keep 1 socket queued; if the user doesn't pick it up we don't queue another read. I'll bring it up tonight.


#define UV_PIPE_PRIVATE_FIELDS \
HANDLE handle; \
Expand Down
19 changes: 6 additions & 13 deletions include/uv.h
Expand Up @@ -41,6 +41,12 @@ extern "C" {
typedef intptr_t ssize_t;
#endif

#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
# include "uv-private/uv-unix.h"
#else
# include "uv-private/uv-win.h"
#endif

/* Expand this list if necessary. */
typedef enum {
UV_UNKNOWN = -1,
Expand Down Expand Up @@ -153,12 +159,6 @@ typedef struct uv_fs_s uv_fs_t;
typedef struct uv_fs_event_s uv_fs_event_t;
typedef struct uv_work_s uv_work_t;

#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
# include "uv-private/uv-unix.h"
#else
# include "uv-private/uv-win.h"
#endif


/*
* This function must be called before any other functions in libuv.
Expand Down Expand Up @@ -392,13 +392,6 @@ int uv_read_stop(uv_stream_t*);
*/
int uv_read2_start(uv_stream_t*, uv_alloc_cb alloc_cb, uv_read2_cb read_cb);

typedef enum {
UV_STDIN = 0,
UV_STDOUT,
UV_STDERR
} uv_std_type;

uv_stream_t* uv_std_handle(uv_loop_t*, uv_std_type type);

/*
* Write data to stream. Buffers are written in order. Example:
Expand Down
7 changes: 0 additions & 7 deletions src/unix/core.c
Expand Up @@ -790,10 +790,3 @@ size_t uv__strlcpy(char* dst, const char* src, size_t size) {

return src - org;
}


uv_stream_t* uv_std_handle(uv_loop_t* loop, uv_std_type type) {
assert(0 && "implement me");
return NULL;
}

63 changes: 37 additions & 26 deletions src/win/internal.h
Expand Up @@ -44,27 +44,30 @@ void uv_process_timers(uv_loop_t* loop);
*/

/* Private uv_handle flags */
#define UV_HANDLE_CLOSING 0x0001
#define UV_HANDLE_CLOSED 0x0002
#define UV_HANDLE_BOUND 0x0004
#define UV_HANDLE_LISTENING 0x0008
#define UV_HANDLE_CONNECTION 0x0010
#define UV_HANDLE_CONNECTED 0x0020
#define UV_HANDLE_READING 0x0040
#define UV_HANDLE_ACTIVE 0x0040
#define UV_HANDLE_EOF 0x0080
#define UV_HANDLE_SHUTTING 0x0100
#define UV_HANDLE_SHUT 0x0200
#define UV_HANDLE_ENDGAME_QUEUED 0x0400
#define UV_HANDLE_BIND_ERROR 0x1000
#define UV_HANDLE_IPV6 0x2000
#define UV_HANDLE_PIPESERVER 0x4000
#define UV_HANDLE_READ_PENDING 0x8000
#define UV_HANDLE_GIVEN_OS_HANDLE 0x10000
#define UV_HANDLE_UV_ALLOCED 0x20000
#define UV_HANDLE_SYNC_BYPASS_IOCP 0x40000
#define UV_HANDLE_ZERO_READ 0x80000
#define UV_HANDLE_TTY_RAW 0x100000
#define UV_HANDLE_CLOSING 0x0001
#define UV_HANDLE_CLOSED 0x0002
#define UV_HANDLE_BOUND 0x0004
#define UV_HANDLE_LISTENING 0x0008
#define UV_HANDLE_CONNECTION 0x0010
#define UV_HANDLE_CONNECTED 0x0020
#define UV_HANDLE_READING 0x0040
#define UV_HANDLE_ACTIVE 0x0040
#define UV_HANDLE_EOF 0x0080
#define UV_HANDLE_SHUTTING 0x0100
#define UV_HANDLE_SHUT 0x0200
#define UV_HANDLE_ENDGAME_QUEUED 0x0400
#define UV_HANDLE_BIND_ERROR 0x1000
#define UV_HANDLE_IPV6 0x2000
#define UV_HANDLE_PIPESERVER 0x4000
#define UV_HANDLE_READ_PENDING 0x8000
#define UV_HANDLE_UV_ALLOCED 0x10000
#define UV_HANDLE_SYNC_BYPASS_IOCP 0x20000
#define UV_HANDLE_ZERO_READ 0x40000
#define UV_HANDLE_TTY_RAW 0x80000
#define UV_HANDLE_USE_IPC_PROTOCOL 0x100000
#define UV_HANDLE_EMULATE_IOCP 0x200000
#define UV_HANDLE_DUPLICATED_SOCKET 0x400000
#define UV_HANDLE_WINSOCK_EXT_INIT 0x800000

void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle);
void uv_process_endgames(uv_loop_t* loop);
Expand Down Expand Up @@ -97,8 +100,8 @@ uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped);
void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req);
void uv_process_reqs(uv_loop_t* loop);

#define POST_COMPLETION_FOR_REQ(loop, req) \
if (!PostQueuedCompletionStatus((loop)->iocp, \
#define POST_COMPLETION_FOR_REQ(loop, req) \
if (!PostQueuedCompletionStatus((loop)->iocp, \
0, \
0, \
&((req)->overlapped))) { \
Expand Down Expand Up @@ -135,6 +138,8 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,

void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle);

int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info);


/*
* UDP
Expand All @@ -149,19 +154,21 @@ void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle);
/*
* Pipes
*/
int uv_pipe_init_with_handle(uv_loop_t* loop, uv_pipe_t* handle,
HANDLE pipeHandle);
int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
char* name, size_t nameSize);
void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err);
void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle);

int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client);
int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client);
int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb,
uv_read_cb read_cb);
int uv_pipe_read2_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb,
uv_read2_cb read_cb);
int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
uv_buf_t bufs[], int bufcnt, uv_write_cb cb);
int uv_pipe_write2(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle,
uv_buf_t bufs[], int bufcnt, uv_stream_t* send_handle, uv_write_cb cb);

void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
uv_req_t* req);
Expand Down Expand Up @@ -267,6 +274,10 @@ void uv_fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle);
void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);


/* Utils */
int uv_parent_pid();


/*
* Error handling
*/
Expand Down

0 comments on commit 6f3e89b

Please sign in to comment.