Windows: make room for oio_handle polymorphism
This commit is contained in:
parent
816eb1fa9e
commit
bba0f79b32
10
oio-win.c
10
oio-win.c
@ -393,8 +393,6 @@ static int oio_tcp_init_socket(oio_handle* handle, oio_close_cb close_cb,
|
|||||||
handle->error = oio_ok_;
|
handle->error = oio_ok_;
|
||||||
handle->accept_socket = INVALID_SOCKET;
|
handle->accept_socket = INVALID_SOCKET;
|
||||||
|
|
||||||
oio_req_init(&(handle->read_accept_req), handle, NULL);
|
|
||||||
|
|
||||||
/* Set the socket to nonblocking mode */
|
/* Set the socket to nonblocking mode */
|
||||||
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
|
if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) {
|
||||||
oio_set_sys_error(WSAGetLastError());
|
oio_set_sys_error(WSAGetLastError());
|
||||||
@ -426,6 +424,7 @@ static int oio_tcp_init_socket(oio_handle* handle, oio_close_cb close_cb,
|
|||||||
static void oio_tcp_init_connection(oio_handle* handle) {
|
static void oio_tcp_init_connection(oio_handle* handle) {
|
||||||
handle->flags |= OIO_HANDLE_CONNECTION;
|
handle->flags |= OIO_HANDLE_CONNECTION;
|
||||||
handle->write_reqs_pending = 0;
|
handle->write_reqs_pending = 0;
|
||||||
|
oio_req_init(&(handle->read_req), handle, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -614,7 +613,7 @@ static void oio_queue_accept(oio_handle* handle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare the oio_req and OVERLAPPED structures. */
|
/* Prepare the oio_req and OVERLAPPED structures. */
|
||||||
req = &handle->read_accept_req;
|
req = &handle->accept_req;
|
||||||
assert(!(req->flags & OIO_REQ_PENDING));
|
assert(!(req->flags & OIO_REQ_PENDING));
|
||||||
req->type = OIO_ACCEPT;
|
req->type = OIO_ACCEPT;
|
||||||
req->flags |= OIO_REQ_PENDING;
|
req->flags |= OIO_REQ_PENDING;
|
||||||
@ -653,7 +652,7 @@ void oio_queue_read(oio_handle* handle) {
|
|||||||
|
|
||||||
assert(handle->flags & OIO_HANDLE_READING);
|
assert(handle->flags & OIO_HANDLE_READING);
|
||||||
|
|
||||||
req = &handle->read_accept_req;
|
req = &handle->read_req;
|
||||||
assert(!(req->flags & OIO_REQ_PENDING));
|
assert(!(req->flags & OIO_REQ_PENDING));
|
||||||
memset(&req->overlapped, 0, sizeof(req->overlapped));
|
memset(&req->overlapped, 0, sizeof(req->overlapped));
|
||||||
req->type = OIO_READ;
|
req->type = OIO_READ;
|
||||||
@ -703,6 +702,7 @@ int oio_listen(oio_handle* handle, int backlog, oio_accept_cb cb) {
|
|||||||
handle->flags |= OIO_HANDLE_LISTENING;
|
handle->flags |= OIO_HANDLE_LISTENING;
|
||||||
handle->accept_cb = cb;
|
handle->accept_cb = cb;
|
||||||
|
|
||||||
|
oio_req_init(&(handle->accept_req), handle, NULL);
|
||||||
oio_queue_accept(handle);
|
oio_queue_accept(handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -757,7 +757,7 @@ int oio_read_start(oio_handle* handle, oio_read_cb cb) {
|
|||||||
|
|
||||||
/* If reading was stopped and then started again, there could stell be a */
|
/* If reading was stopped and then started again, there could stell be a */
|
||||||
/* read request pending. */
|
/* read request pending. */
|
||||||
if (!(handle->read_accept_req.flags & OIO_REQ_PENDING))
|
if (!(handle->read_req.flags & OIO_REQ_PENDING))
|
||||||
oio_queue_read(handle);
|
oio_queue_read(handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
40
oio-win.h
40
oio-win.h
@ -53,25 +53,33 @@ typedef struct oio_buf {
|
|||||||
}; \
|
}; \
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
#define oio_handle_private_fields \
|
#define oio_tcp_connection_fields \
|
||||||
oio_handle* endgame_next; \
|
void* read_cb; \
|
||||||
|
struct oio_req_s read_req; \
|
||||||
|
unsigned int write_reqs_pending; \
|
||||||
|
oio_req* shutdown_req;
|
||||||
|
|
||||||
|
#define oio_tcp_server_fields \
|
||||||
|
void *accept_cb; \
|
||||||
|
SOCKET accept_socket; \
|
||||||
|
struct oio_req_s accept_req; \
|
||||||
|
char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32];
|
||||||
|
|
||||||
|
#define oio_tcp_fields \
|
||||||
|
unsigned int reqs_pending; \
|
||||||
union { \
|
union { \
|
||||||
SOCKET socket; \
|
SOCKET socket; \
|
||||||
HANDLE handle; \
|
HANDLE handle; \
|
||||||
}; \
|
}; \
|
||||||
struct oio_req_s read_accept_req; \
|
|
||||||
union { \
|
union { \
|
||||||
struct { \
|
struct { oio_tcp_connection_fields }; \
|
||||||
char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \
|
struct { oio_tcp_server_fields }; \
|
||||||
void *accept_cb; \
|
};
|
||||||
SOCKET accept_socket; \
|
|
||||||
}; \
|
#define oio_handle_private_fields \
|
||||||
struct { \
|
oio_handle* endgame_next; \
|
||||||
unsigned int write_reqs_pending; \
|
|
||||||
void* read_cb; \
|
|
||||||
oio_req* shutdown_req; \
|
|
||||||
}; \
|
|
||||||
}; \
|
|
||||||
unsigned int flags; \
|
unsigned int flags; \
|
||||||
unsigned int reqs_pending; \
|
oio_err error; \
|
||||||
oio_err error;
|
union { \
|
||||||
|
struct { oio_tcp_fields }; \
|
||||||
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user