ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro-Mysql/violite.h
Revision: 1.9
Committed: Mon Mar 4 05:34:52 2019 UTC (5 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.8: +4 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.4 /* adapted from violite.h from mysql 5.0.51 and many others */
2 root 1.1 /* all modifications public domain */
3     /* Copyright (C) 2000 MySQL AB
4    
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; version 2 of the License.
8    
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17    
18     /*
19     * Vio Lite.
20     * Purpose: include file for Vio that will work with C and C++
21     */
22    
23     #ifndef vio_violite_h_
24     #define vio_violite_h_
25    
26     /* Simple vio interface in C; The functions are implemented in violite.c */
27    
28     #ifdef __cplusplus
29     extern "C" {
30     #endif /* __cplusplus */
31    
32 root 1.3 #if MYSQL_VERSION_ID < 50100
33     typedef I8 *xgptr;
34     typedef I8 *const cxgptr;
35 root 1.9 typedef int xsize_t;
36     typedef int xssize_t;
37 root 1.3 #else
38     typedef U8 *xgptr;
39     typedef const U8 *cxgptr;
40 root 1.9 typedef size_t xsize_t;
41     typedef size_t xssize_t;
42 root 1.3 #endif
43 root 1.2
44 root 1.1 enum enum_vio_type
45     {
46     VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
47     VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
48     };
49    
50    
51     #define VIO_LOCALHOST 1 /* a localhost connection */
52     #define VIO_BUFFERED_READ 2 /* use buffered read */
53     #define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
54    
55     Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
56     #ifdef __WIN__
57     Vio* vio_new_win32pipe(HANDLE hPipe);
58     Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map,
59     HANDLE handle_map,
60     HANDLE event_server_wrote,
61     HANDLE event_server_read,
62     HANDLE event_client_wrote,
63     HANDLE event_client_read,
64     HANDLE event_conn_closed);
65 root 1.3 xlen vio_read_pipe(Vio *vio, xgptr buf, xlen size);
66     xlen vio_write_pipe(Vio *vio, xcgptr buf, xlen size);
67     xlen vio_close_pipe(Vio * vio);
68 root 1.1 #else
69     #define HANDLE void *
70     #endif /* __WIN__ */
71    
72     void vio_delete(Vio* vio);
73     int vio_close(Vio* vio);
74     void vio_reset(Vio* vio, enum enum_vio_type type,
75     my_socket sd, HANDLE hPipe, uint flags);
76 root 1.3 xlen vio_read(Vio *vio, xgptr buf, xlen size);
77     xlen vio_read_buff(Vio *vio, xgptr buf, xlen size);
78     xlen vio_write(Vio *vio, cxgptr buf, xlen size);
79 root 1.1 int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
80     my_bool vio_is_blocking(Vio *vio);
81     /* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
82     int vio_fastsend(Vio *vio);
83     /* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
84     int vio_keepalive(Vio *vio, my_bool onoff);
85     /* Whenever we should retry the last read/write operation. */
86     my_bool vio_should_retry(Vio *vio);
87     /* Check that operation was timed out */
88     my_bool vio_was_interrupted(Vio *vio);
89     /* Short text description of the socket for those, who are curious.. */
90     const char* vio_description(Vio *vio);
91     /* Return the type of the connection */
92     enum enum_vio_type vio_type(Vio* vio);
93     /* Return last error number */
94     int vio_errno(Vio*vio);
95     /* Get socket number */
96     my_socket vio_fd(Vio*vio);
97     /* Remote peer's address and name in text form */
98     my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port);
99     /* Remotes in_addr */
100     void vio_in_addr(Vio *vio, struct in_addr *in);
101     my_bool vio_poll_read(Vio *vio,uint timeout);
102    
103     void vio_end(void);
104    
105     #ifdef __cplusplus
106     }
107     #endif
108    
109     #if !defined(DONT_MAP_VIO)
110     #define vio_delete(vio) (vio)->viodelete(vio)
111     #define vio_errno(vio) (vio)->vioerrno(vio)
112     #define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
113     #define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
114     #define vio_blocking(vio, set_blocking_mode, old_mode)\
115     (vio)->vioblocking(vio, set_blocking_mode, old_mode)
116     #define vio_is_blocking(vio) (vio)->is_blocking(vio)
117     #define vio_fastsend(vio) (vio)->fastsend(vio)
118     #define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
119     #define vio_should_retry(vio) (vio)->should_retry(vio)
120     #define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
121     #define vio_close(vio) ((vio)->vioclose)(vio)
122     #define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt)
123     #define vio_in_addr(vio, in) (vio)->in_addr(vio, in)
124     #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
125     #endif /* !defined(DONT_MAP_VIO) */
126    
127     /* This enumerator is used in parser - should be always visible */
128     enum SSL_type
129     {
130     SSL_TYPE_NOT_SPECIFIED= -1,
131     SSL_TYPE_NONE,
132     SSL_TYPE_ANY,
133     SSL_TYPE_X509,
134     SSL_TYPE_SPECIFIED
135     };
136    
137 root 1.5 typedef unsigned char uchar;
138 root 1.1
139     /* HFTODO - hide this if we don't want client in embedded server */
140     /* This structure is for every connection on both sides */
141 root 1.7 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100010
142 root 1.4
143     #define DESC_IS_PTR 1
144     struct st_vio
145     {
146     my_socket sd; /* my_socket - real or imaginary */
147     void *m_psi;
148     my_bool localhost; /* Are we from localhost? */
149     int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
150     struct sockaddr_storage local; /* Local internet address */
151     struct sockaddr_storage remote; /* Remote internet address */
152     int addrLen; /* Length of remote address */
153     enum enum_vio_type type; /* Type of connection */
154     const char *desc; /* String description */
155     char *read_buffer; /* buffer for vio_read_buff */
156     char *read_pos; /* start of unfetched data in the
157     read buffer */
158     char *read_end; /* end of unfetched data */
159     struct mysql_async_context *async_context; /* For non-blocking API */
160     int read_timeout; /* Timeout value (ms) for read ops. */
161     int write_timeout; /* Timeout value (ms) for write ops. */
162     /* function pointers. They are similar for socket/SSL/whatever */
163     void (*viodelete)(Vio*);
164     int (*vioerrno)(Vio*);
165     size_t (*read)(Vio*, uchar *, size_t);
166     size_t (*write)(Vio*, const uchar *, size_t);
167     int (*timeout)(Vio*, uint, my_bool);
168     int (*vioblocking)(Vio*, my_bool, my_bool *);
169     my_bool (*is_blocking)(Vio*);
170     int (*viokeepalive)(Vio*, my_bool);
171     int (*fastsend)(Vio*);
172     my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
173     void (*in_addr)(Vio*, struct sockaddr_storage*);
174     my_bool (*should_retry)(Vio*);
175     my_bool (*was_timeout)(Vio*);
176     int (*vioclose)(Vio*);
177     my_bool (*is_connected)(Vio*);
178     int (*shutdown)(Vio *, int);
179     my_bool (*has_data) (Vio*);
180     };
181    
182     #elif MYSQL_VERSION_ID < 50500
183 root 1.3
184 root 1.1 struct st_vio
185     {
186     my_socket sd; /* my_socket - real or imaginary */
187     HANDLE hPipe;
188     my_bool localhost; /* Are we from localhost? */
189     int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
190     struct sockaddr_in local; /* Local internet address */
191     struct sockaddr_in remote; /* Remote internet address */
192     enum enum_vio_type type; /* Type of connection */
193     char desc[30]; /* String description */
194     char *read_buffer; /* buffer for vio_read_buff */
195     char *read_pos; /* start of unfetched data in the
196     read buffer */
197     char *read_end; /* end of unfetched data */
198     /* function pointers. They are similar for socket/SSL/whatever */
199     void (*viodelete)(Vio*);
200     int (*vioerrno)(Vio*);
201 root 1.3 xlen (*read)(Vio*, xgptr, xlen);
202     xlen (*write)(Vio*, cxgptr, xlen);
203 root 1.1 int (*vioblocking)(Vio*, my_bool, my_bool *);
204     my_bool (*is_blocking)(Vio*);
205     int (*viokeepalive)(Vio*, my_bool);
206     int (*fastsend)(Vio*);
207     my_bool (*peer_addr)(Vio*, char *, uint16*);
208     void (*in_addr)(Vio*, struct in_addr*);
209     my_bool (*should_retry)(Vio*);
210     my_bool (*was_interrupted)(Vio*);
211     int (*vioclose)(Vio*);
212     void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
213 root 1.3 };
214    
215 root 1.5 #elif MYSQL_VERSION_ID < 50600
216 root 1.3
217     struct st_vio
218     {
219     my_socket sd; /* my_socket - real or imaginary */
220     HANDLE hPipe;
221     my_bool localhost; /* Are we from localhost? */
222     int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
223     struct sockaddr_storage local; /* Local internet address */
224     struct sockaddr_storage remote; /* Remote internet address */
225     int addrLen; /* Length of remote address */
226     enum enum_vio_type type; /* Type of connection */
227     char desc[30]; /* String description */
228     char *read_buffer; /* buffer for vio_read_buff */
229     char *read_pos; /* start of unfetched data in the
230     read buffer */
231     char *read_end; /* end of unfetched data */
232 root 1.8 #if defined(MARIADB_BASE_VERSION)
233     struct mysql_async_context *async_context; /* For non-blocking API */
234     uint read_timeout, write_timeout;
235     #endif
236 root 1.3 /* function pointers. They are similar for socket/SSL/whatever */
237     void (*viodelete)(Vio*);
238     int (*vioerrno)(Vio*);
239     size_t (*read)(Vio*, unsigned char *, size_t);
240     size_t (*write)(Vio*, const unsigned char *, size_t);
241     int (*vioblocking)(Vio*, my_bool, my_bool *);
242     my_bool (*is_blocking)(Vio*);
243     int (*viokeepalive)(Vio*, my_bool);
244     int (*fastsend)(Vio*);
245     my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
246     void (*in_addr)(Vio*, struct sockaddr_storage*);
247     my_bool (*should_retry)(Vio*);
248     my_bool (*was_interrupted)(Vio*);
249     int (*vioclose)(Vio*);
250     void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
251     my_bool (*poll_read)(Vio *vio, uint timeout);
252     my_bool (*is_connected)(Vio*);
253     my_bool (*has_data) (Vio*);
254     };
255    
256 root 1.5 #else
257    
258     /* this is not supposed to work, but it's a start
259     * one needs to look into MYSQL_SOCKET, missing
260     * vioblocking and this io_wait stuff, at the least. */
261    
262     /**
263     VIO I/O events.
264     */
265     enum enum_vio_io_event
266     {
267     VIO_IO_EVENT_READ,
268     VIO_IO_EVENT_WRITE,
269     VIO_IO_EVENT_CONNECT
270     };
271    
272     struct st_vio
273     {
274     MYSQL_SOCKET mysql_socket; /* Instrumented socket */
275     my_bool localhost; /* Are we from localhost? */
276     struct sockaddr_storage local; /* Local internet address */
277     struct sockaddr_storage remote; /* Remote internet address */
278     int addrLen; /* Length of remote address */
279     enum enum_vio_type type; /* Type of connection */
280     my_bool inactive; /* Connection inactive (has been shutdown) */
281     char desc[30]; /* Description string. This
282     member MUST NOT be
283     used directly, but only
284     via function
285     "vio_description" */
286     char *read_buffer; /* buffer for vio_read_buff */
287     char *read_pos; /* start of unfetched data in the
288     read buffer */
289     char *read_end; /* end of unfetched data */
290     int read_timeout; /* Timeout value (ms) for read ops. */
291     int write_timeout; /* Timeout value (ms) for write ops. */
292    
293     /*
294     VIO vtable interface to be implemented by VIO's like SSL, Socket,
295     Named Pipe, etc.
296     */
297    
298     /*
299     viodelete is responsible for cleaning up the VIO object by freeing
300     internal buffers, closing descriptors, handles.
301     */
302     void (*viodelete)(Vio*);
303     int (*vioerrno)(Vio*);
304     size_t (*read)(Vio*, uchar *, size_t);
305     size_t (*write)(Vio*, const uchar *, size_t);
306     int (*timeout)(Vio*, uint, my_bool);
307     int (*viokeepalive)(Vio*, my_bool);
308     int (*fastsend)(Vio*);
309     my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
310     void (*in_addr)(Vio*, struct sockaddr_storage*);
311     my_bool (*should_retry)(Vio*);
312     my_bool (*was_timeout)(Vio*);
313     /*
314     vioshutdown is resposnible to shutdown/close the channel, so that no
315     further communications can take place, however any related buffers,
316     descriptors, handles can remain valid after a shutdown.
317     */
318     int (*vioshutdown)(Vio*);
319     my_bool (*is_connected)(Vio*);
320     my_bool (*has_data) (Vio*);
321     int (*io_wait)(Vio*, enum enum_vio_io_event, int);
322     my_bool (*connect)(Vio*, struct sockaddr *, socklen_t, int);
323     };
324    
325 root 1.1 #endif
326 root 1.3
327 root 1.1 #endif /* vio_violite_h_ */