| 1 |
#ifndef AWS_IO_SOCKET_IMPL_H |
| 2 |
#define AWS_IO_SOCKET_IMPL_H |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <aws/io/io.h> |
| 10 |
#include <aws/io/socket.h> |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifdef _WIN32 |
| 16 |
typedef void (*aws_ms_fn_ptr)(void); |
| 17 |
|
| 18 |
void aws_check_and_init_winsock(void); |
| 19 |
aws_ms_fn_ptr aws_winsock_get_connectex_fn(void); |
| 20 |
aws_ms_fn_ptr aws_winsock_get_acceptex_fn(void); |
| 21 |
#else |
| 22 |
struct socket_address { |
| 23 |
union sock_addr_types { |
| 24 |
struct sockaddr_in addr_in; |
| 25 |
struct sockaddr_in6 addr_in6; |
| 26 |
struct sockaddr_un un_addr; |
| 27 |
# ifdef __APPLE__ |
| 28 |
struct sockaddr addr_base; |
| 29 |
# endif |
| 30 |
# ifdef USE_VSOCK |
| 31 |
struct sockaddr_vm vm_addr; |
| 32 |
# endif |
| 33 |
} sock_addr_types; |
| 34 |
}; |
| 35 |
#endif |
| 36 |
|
| 37 |
int aws_socket_init_posix( |
| 38 |
struct aws_socket *socket, |
| 39 |
struct aws_allocator *alloc, |
| 40 |
const struct aws_socket_options *options); |
| 41 |
|
| 42 |
int aws_socket_init_winsock( |
| 43 |
struct aws_socket *socket, |
| 44 |
struct aws_allocator *alloc, |
| 45 |
const struct aws_socket_options *options); |
| 46 |
|
| 47 |
int aws_socket_init_apple_nw_socket( |
| 48 |
struct aws_socket *socket, |
| 49 |
struct aws_allocator *alloc, |
| 50 |
const struct aws_socket_options *options); |
| 51 |
|
| 52 |
struct aws_socket_vtable { |
| 53 |
void (*socket_cleanup_fn)(struct aws_socket *socket); |
| 54 |
int (*socket_connect_fn)(struct aws_socket *socket, struct aws_socket_connect_options *socket_connect_options); |
| 55 |
int (*socket_bind_fn)(struct aws_socket *socket, struct aws_socket_bind_options *socket_bind_options); |
| 56 |
int (*socket_listen_fn)(struct aws_socket *socket, int backlog_size); |
| 57 |
int (*socket_start_accept_fn)( |
| 58 |
struct aws_socket *socket, |
| 59 |
struct aws_event_loop *accept_loop, |
| 60 |
struct aws_socket_listener_options options); |
| 61 |
int (*socket_stop_accept_fn)(struct aws_socket *socket); |
| 62 |
int (*socket_close_fn)(struct aws_socket *socket); |
| 63 |
int (*socket_shutdown_dir_fn)(struct aws_socket *socket, enum aws_channel_direction dir); |
| 64 |
int (*socket_set_options_fn)(struct aws_socket *socket, const struct aws_socket_options *options); |
| 65 |
int (*socket_assign_to_event_loop_fn)(struct aws_socket *socket, struct aws_event_loop *event_loop); |
| 66 |
int (*socket_subscribe_to_readable_events_fn)( |
| 67 |
struct aws_socket *socket, |
| 68 |
aws_socket_on_readable_fn *on_readable, |
| 69 |
void *user_data); |
| 70 |
int (*socket_read_fn)(struct aws_socket *socket, struct aws_byte_buf *buffer, size_t *amount_read); |
| 71 |
int (*socket_write_fn)( |
| 72 |
struct aws_socket *socket, |
| 73 |
const struct aws_byte_cursor *cursor, |
| 74 |
aws_socket_on_write_completed_fn *written_fn, |
| 75 |
void *user_data); |
| 76 |
int (*socket_get_error_fn)(struct aws_socket *socket); |
| 77 |
bool (*socket_is_open_fn)(struct aws_socket *socket); |
| 78 |
int (*socket_set_close_callback)(struct aws_socket *socket, aws_socket_on_shutdown_complete_fn fn, void *user_data); |
| 79 |
int (*socket_set_cleanup_callback)( |
| 80 |
struct aws_socket *socket, |
| 81 |
aws_socket_on_shutdown_complete_fn fn, |
| 82 |
void *user_data); |
| 83 |
struct aws_byte_buf (*socket_get_protocol_fn)(const struct aws_socket *socket); |
| 84 |
struct aws_string *(*socket_get_server_name_fn)(const struct aws_socket *socket); |
| 85 |
}; |
| 86 |
|
| 87 |
struct on_start_accept_result_args { |
| 88 |
struct aws_task task; |
| 89 |
int error; |
| 90 |
struct aws_allocator *allocator; |
| 91 |
struct aws_socket *socket; |
| 92 |
aws_socket_on_accept_started_fn *on_accept_start; |
| 93 |
void *on_accept_start_user_data; |
| 94 |
}; |
| 95 |
|
| 96 |
#endif |