1 | #ifndef _ma_pvio_h_ |
2 | #define _ma_pvio_h_ |
3 | #define cio_defined |
4 | |
5 | #ifdef HAVE_TLS |
6 | #include <ma_tls.h> |
7 | #else |
8 | #define MARIADB_TLS void |
9 | #endif |
10 | |
11 | #define PVIO_SET_ERROR if (pvio->set_error) \ |
12 | pvio->set_error |
13 | |
14 | #define PVIO_READ_AHEAD_CACHE_SIZE 16384 |
15 | #define PVIO_READ_AHEAD_CACHE_MIN_SIZE 2048 |
16 | #define PVIO_EINTR_TRIES 2 |
17 | |
18 | struct st_ma_pvio_methods; |
19 | typedef struct st_ma_pvio_methods PVIO_METHODS; |
20 | |
21 | #define IS_PVIO_ASYNC(a) \ |
22 | ((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context) |
23 | |
24 | #define IS_PVIO_ASYNC_ACTIVE(a) \ |
25 | (IS_PVIO_ASYNC(a)&& (a)->mysql->options.extension->async_context->active) |
26 | |
27 | #define IS_MYSQL_ASYNC(a) \ |
28 | ((a)->options.extension && (a)->options.extension->async_context) |
29 | |
30 | #define IS_MYSQL_ASYNC_ACTIVE(a) \ |
31 | (IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active) |
32 | |
33 | enum enum_pvio_timeout { |
34 | PVIO_CONNECT_TIMEOUT= 0, |
35 | PVIO_READ_TIMEOUT, |
36 | PVIO_WRITE_TIMEOUT |
37 | }; |
38 | |
39 | enum enum_pvio_io_event |
40 | { |
41 | VIO_IO_EVENT_READ, |
42 | VIO_IO_EVENT_WRITE, |
43 | VIO_IO_EVENT_CONNECT |
44 | }; |
45 | |
46 | enum enum_pvio_type { |
47 | PVIO_TYPE_UNIXSOCKET= 0, |
48 | PVIO_TYPE_SOCKET, |
49 | PVIO_TYPE_NAMEDPIPE, |
50 | PVIO_TYPE_SHAREDMEM, |
51 | }; |
52 | |
53 | enum enum_pvio_operation { |
54 | PVIO_READ= 0, |
55 | PVIO_WRITE=1 |
56 | }; |
57 | |
58 | #define SHM_DEFAULT_NAME "MYSQL" |
59 | |
60 | struct st_pvio_callback; |
61 | |
62 | typedef struct st_pvio_callback { |
63 | void (*callback)(MYSQL *mysql, uchar *buffer, size_t size); |
64 | struct st_pvio_callback *next; |
65 | } PVIO_CALLBACK; |
66 | |
67 | struct st_ma_pvio { |
68 | void *data; |
69 | /* read ahead cache */ |
70 | uchar *cache; |
71 | uchar *cache_pos; |
72 | size_t cache_size; |
73 | enum enum_pvio_type type; |
74 | int timeout[3]; |
75 | int ssl_type; /* todo: change to enum (ssl plugins) */ |
76 | MARIADB_TLS *ctls; |
77 | MYSQL *mysql; |
78 | PVIO_METHODS *methods; |
79 | void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...); |
80 | void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const uchar *buffer, size_t length); |
81 | }; |
82 | |
83 | typedef struct st_ma_pvio_cinfo |
84 | { |
85 | const char *host; |
86 | const char *unix_socket; |
87 | int port; |
88 | enum enum_pvio_type type; |
89 | MYSQL *mysql; |
90 | } MA_PVIO_CINFO; |
91 | |
92 | struct st_ma_pvio_methods |
93 | { |
94 | my_bool (*set_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); |
95 | int (*get_timeout)(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); |
96 | ssize_t (*read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length); |
97 | ssize_t (*async_read)(MARIADB_PVIO *pvio, uchar *buffer, size_t length); |
98 | ssize_t (*write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); |
99 | ssize_t (*async_write)(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); |
100 | int (*wait_io_or_timeout)(MARIADB_PVIO *pvio, my_bool is_read, int timeout); |
101 | int (*blocking)(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); |
102 | my_bool (*connect)(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); |
103 | my_bool (*close)(MARIADB_PVIO *pvio); |
104 | int (*fast_send)(MARIADB_PVIO *pvio); |
105 | int (*keepalive)(MARIADB_PVIO *pvio); |
106 | my_bool (*get_handle)(MARIADB_PVIO *pvio, void *handle); |
107 | my_bool (*is_blocking)(MARIADB_PVIO *pvio); |
108 | my_bool (*is_alive)(MARIADB_PVIO *pvio); |
109 | my_bool (*has_data)(MARIADB_PVIO *pvio, ssize_t *data_len); |
110 | int(*shutdown)(MARIADB_PVIO *pvio); |
111 | }; |
112 | |
113 | /* Function prototypes */ |
114 | MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo); |
115 | void ma_pvio_close(MARIADB_PVIO *pvio); |
116 | ssize_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); |
117 | ssize_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); |
118 | ssize_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); |
119 | int ma_pvio_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); |
120 | my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); |
121 | int ma_pvio_fast_send(MARIADB_PVIO *pvio); |
122 | int ma_pvio_keepalive(MARIADB_PVIO *pvio); |
123 | my_socket ma_pvio_get_socket(MARIADB_PVIO *pvio); |
124 | my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio); |
125 | my_bool ma_pvio_blocking(MARIADB_PVIO *pvio, my_bool block, my_bool *previous_mode); |
126 | my_bool ma_pvio_is_blocking(MARIADB_PVIO *pvio); |
127 | int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); |
128 | my_bool ma_pvio_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); |
129 | my_bool ma_pvio_is_alive(MARIADB_PVIO *pvio); |
130 | my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle); |
131 | my_bool ma_pvio_has_data(MARIADB_PVIO *pvio, ssize_t *length); |
132 | |
133 | #endif /* _ma_pvio_h_ */ |
134 | |