commit 133b4e3999221ba654744262cb065c3aafce3312 Author: Ryan Dahl Date: Wed Mar 23 01:39:59 2011 -0700 start! diff --git a/iocp-links.html b/iocp-links.html new file mode 100644 index 00000000..1d62a453 --- /dev/null +++ b/iocp-links.html @@ -0,0 +1,68 @@ + +

Asynchronous I/O in Windows for UNIX Programmers

+ +

Windows has very different notions for how asynchronous and non-blocking I/O +are done. While Windows does have select(), it is severely +limited: it supports only 64 file descriptors. (Does select() +work on named pipes in windows?) Windows has the possibility of serving +20,000 TCP connections using a different API called overlapped + I/O using I/O + completion ports. Unfortunately I/O completion ports + + + + + + +tips +

+ +IOCP: + + +APC: + + + +Pipes: + diff --git a/ol.h b/ol.h new file mode 100644 index 00000000..b35747ff --- /dev/null +++ b/ol.h @@ -0,0 +1,74 @@ +#ifdef windows +# include "ol_win.h" +#else +# include "ol_unix.h" +#endif + + +typedef ol_read_cb void(*)(ol_buf *bufs, int bufcnt); +typedef ol_close_cb void(*)(int read, int write); +typedef ol_connect_cb void(*)(); +typedef ol_connect_cb void(*)(); + + +typedef enum { + OL_NAMED_PIPE, + OL_TCP, + OL_TCP6 +} ol_socket_type; + + +typedef struct { + size_t len; + char* buf; +} ol_buf; + + +typedef struct { + size_t len; + void* name; +} ol_addr; + + +/** + * Creates a new socket of given type. If bind_addr is NULL a random + * port will be bound in the case of OL_TCP and OL_TCP6. In the case + * of NAMED_PIPE, bind_addr specifies a string describing the location + * to bind to. + */ +ol_socket* ol_socket_create(ol_socket_type type, ol_buf* bind_addr, + ol_read_cb cb, ol_close_cb cb); + + +int ol_socket_connect(ol_socket* socket, ol_addr addr, + ol_buf* buf, size_t* bytes_sent, ol_connect_cb ol); + + +int ol_socket_pause(ol_socket* socket); + + +int ol_socket_resume(ol_socket* socket); + + +int ol_socket_address(ol_socket* socket, ol_addr* addr); + + +/** + * Send data to socket. User responsible for bufs until callback is made. + * Multiple ol_socket_write() calls may be issued before the previous ones + * complete - data will sent in the correct order. + */ +int ol_socket_write(ol_socket* socket, ol_buf* bufs, int bufcnt, + size_t* bytes_sent, ol_write_cb cb); + + +int ol_socket_listen(ol_socket* server, int backlog, ol_accept_cb cb); + + +int ol_socket_shutdown_write(ol_socket* socket); + + +int ol_socket_close(ol_socket* socket); + + +int ol_socket_free(ol_socket* socket); diff --git a/ol_win.c b/ol_win.c new file mode 100644 index 00000000..41fd9f86 --- /dev/null +++ b/ol_win.c @@ -0,0 +1,3 @@ +#include "ol.h" + +void ol_init