ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro-Mysql/violite.h
Revision: 1.4
Committed: Fri Aug 2 04:08:56 2013 UTC (10 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-1_22
Changes since 1.3: +45 -2 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     typedef int xlen;
36     #else
37     typedef U8 *xgptr;
38     typedef const U8 *cxgptr;
39     typedef size_t xlen;
40     #endif
41 root 1.2
42 root 1.1 enum enum_vio_type
43     {
44     VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
45     VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
46     };
47    
48    
49     #define VIO_LOCALHOST 1 /* a localhost connection */
50     #define VIO_BUFFERED_READ 2 /* use buffered read */
51     #define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
52    
53     Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
54     #ifdef __WIN__
55     Vio* vio_new_win32pipe(HANDLE hPipe);
56     Vio* vio_new_win32shared_memory(NET *net,HANDLE handle_file_map,
57     HANDLE handle_map,
58     HANDLE event_server_wrote,
59     HANDLE event_server_read,
60     HANDLE event_client_wrote,
61     HANDLE event_client_read,
62     HANDLE event_conn_closed);
63 root 1.3 xlen vio_read_pipe(Vio *vio, xgptr buf, xlen size);
64     xlen vio_write_pipe(Vio *vio, xcgptr buf, xlen size);
65     xlen vio_close_pipe(Vio * vio);
66 root 1.1 #else
67     #define HANDLE void *
68     #endif /* __WIN__ */
69    
70     void vio_delete(Vio* vio);
71     int vio_close(Vio* vio);
72     void vio_reset(Vio* vio, enum enum_vio_type type,
73     my_socket sd, HANDLE hPipe, uint flags);
74 root 1.3 xlen vio_read(Vio *vio, xgptr buf, xlen size);
75     xlen vio_read_buff(Vio *vio, xgptr buf, xlen size);
76     xlen vio_write(Vio *vio, cxgptr buf, xlen size);
77 root 1.1 int vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
78     my_bool vio_is_blocking(Vio *vio);
79     /* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
80     int vio_fastsend(Vio *vio);
81     /* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
82     int vio_keepalive(Vio *vio, my_bool onoff);
83     /* Whenever we should retry the last read/write operation. */
84     my_bool vio_should_retry(Vio *vio);
85     /* Check that operation was timed out */
86     my_bool vio_was_interrupted(Vio *vio);
87     /* Short text description of the socket for those, who are curious.. */
88     const char* vio_description(Vio *vio);
89     /* Return the type of the connection */
90     enum enum_vio_type vio_type(Vio* vio);
91     /* Return last error number */
92     int vio_errno(Vio*vio);
93     /* Get socket number */
94     my_socket vio_fd(Vio*vio);
95     /* Remote peer's address and name in text form */
96     my_bool vio_peer_addr(Vio* vio, char *buf, uint16 *port);
97     /* Remotes in_addr */
98     void vio_in_addr(Vio *vio, struct in_addr *in);
99     my_bool vio_poll_read(Vio *vio,uint timeout);
100    
101     void vio_end(void);
102    
103     #ifdef __cplusplus
104     }
105     #endif
106    
107     #if !defined(DONT_MAP_VIO)
108     #define vio_delete(vio) (vio)->viodelete(vio)
109     #define vio_errno(vio) (vio)->vioerrno(vio)
110     #define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
111     #define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
112     #define vio_blocking(vio, set_blocking_mode, old_mode)\
113     (vio)->vioblocking(vio, set_blocking_mode, old_mode)
114     #define vio_is_blocking(vio) (vio)->is_blocking(vio)
115     #define vio_fastsend(vio) (vio)->fastsend(vio)
116     #define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
117     #define vio_should_retry(vio) (vio)->should_retry(vio)
118     #define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
119     #define vio_close(vio) ((vio)->vioclose)(vio)
120     #define vio_peer_addr(vio, buf, prt) (vio)->peer_addr(vio, buf, prt)
121     #define vio_in_addr(vio, in) (vio)->in_addr(vio, in)
122     #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
123     #endif /* !defined(DONT_MAP_VIO) */
124    
125     /* This enumerator is used in parser - should be always visible */
126     enum SSL_type
127     {
128     SSL_TYPE_NOT_SPECIFIED= -1,
129     SSL_TYPE_NONE,
130     SSL_TYPE_ANY,
131     SSL_TYPE_X509,
132     SSL_TYPE_SPECIFIED
133     };
134    
135    
136     /* HFTODO - hide this if we don't want client in embedded server */
137     /* This structure is for every connection on both sides */
138 root 1.4 #if defined(MARIADB_BASE_VERSION)
139    
140     #define DESC_IS_PTR 1
141     typedef unsigned char uchar;
142    
143     struct st_vio
144     {
145     my_socket sd; /* my_socket - real or imaginary */
146     void *m_psi;
147     my_bool localhost; /* Are we from localhost? */
148     int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
149     struct sockaddr_storage local; /* Local internet address */
150     struct sockaddr_storage remote; /* Remote internet address */
151     int addrLen; /* Length of remote address */
152     enum enum_vio_type type; /* Type of connection */
153     const char *desc; /* String description */
154     char *read_buffer; /* buffer for vio_read_buff */
155     char *read_pos; /* start of unfetched data in the
156     read buffer */
157     char *read_end; /* end of unfetched data */
158     struct mysql_async_context *async_context; /* For non-blocking API */
159     int read_timeout; /* Timeout value (ms) for read ops. */
160     int write_timeout; /* Timeout value (ms) for write ops. */
161     /* function pointers. They are similar for socket/SSL/whatever */
162     void (*viodelete)(Vio*);
163     int (*vioerrno)(Vio*);
164     size_t (*read)(Vio*, uchar *, size_t);
165     size_t (*write)(Vio*, const uchar *, size_t);
166     int (*timeout)(Vio*, uint, my_bool);
167     int (*vioblocking)(Vio*, my_bool, my_bool *);
168     my_bool (*is_blocking)(Vio*);
169     int (*viokeepalive)(Vio*, my_bool);
170     int (*fastsend)(Vio*);
171     my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
172     void (*in_addr)(Vio*, struct sockaddr_storage*);
173     my_bool (*should_retry)(Vio*);
174     my_bool (*was_timeout)(Vio*);
175     int (*vioclose)(Vio*);
176     my_bool (*is_connected)(Vio*);
177     int (*shutdown)(Vio *, int);
178     my_bool (*has_data) (Vio*);
179     };
180    
181     #elif MYSQL_VERSION_ID < 50500
182 root 1.3
183 root 1.1 struct st_vio
184     {
185     my_socket sd; /* my_socket - real or imaginary */
186     HANDLE hPipe;
187     my_bool localhost; /* Are we from localhost? */
188     int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
189     struct sockaddr_in local; /* Local internet address */
190     struct sockaddr_in remote; /* Remote internet address */
191     enum enum_vio_type type; /* Type of connection */
192     char desc[30]; /* String description */
193     char *read_buffer; /* buffer for vio_read_buff */
194     char *read_pos; /* start of unfetched data in the
195     read buffer */
196     char *read_end; /* end of unfetched data */
197     /* function pointers. They are similar for socket/SSL/whatever */
198     void (*viodelete)(Vio*);
199     int (*vioerrno)(Vio*);
200 root 1.3 xlen (*read)(Vio*, xgptr, xlen);
201     xlen (*write)(Vio*, cxgptr, xlen);
202 root 1.1 int (*vioblocking)(Vio*, my_bool, my_bool *);
203     my_bool (*is_blocking)(Vio*);
204     int (*viokeepalive)(Vio*, my_bool);
205     int (*fastsend)(Vio*);
206     my_bool (*peer_addr)(Vio*, char *, uint16*);
207     void (*in_addr)(Vio*, struct in_addr*);
208     my_bool (*should_retry)(Vio*);
209     my_bool (*was_interrupted)(Vio*);
210     int (*vioclose)(Vio*);
211     void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
212 root 1.3 };
213    
214     #else
215    
216     struct st_vio
217     {
218     my_socket sd; /* my_socket - real or imaginary */
219     HANDLE hPipe;
220     my_bool localhost; /* Are we from localhost? */
221     int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
222     struct sockaddr_storage local; /* Local internet address */
223     struct sockaddr_storage remote; /* Remote internet address */
224     int addrLen; /* Length of remote address */
225     enum enum_vio_type type; /* Type of connection */
226     char desc[30]; /* String description */
227     char *read_buffer; /* buffer for vio_read_buff */
228     char *read_pos; /* start of unfetched data in the
229     read buffer */
230     char *read_end; /* end of unfetched data */
231     /* function pointers. They are similar for socket/SSL/whatever */
232     void (*viodelete)(Vio*);
233     int (*vioerrno)(Vio*);
234     size_t (*read)(Vio*, unsigned char *, size_t);
235     size_t (*write)(Vio*, const unsigned char *, size_t);
236     int (*vioblocking)(Vio*, my_bool, my_bool *);
237     my_bool (*is_blocking)(Vio*);
238     int (*viokeepalive)(Vio*, my_bool);
239     int (*fastsend)(Vio*);
240     my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
241     void (*in_addr)(Vio*, struct sockaddr_storage*);
242     my_bool (*should_retry)(Vio*);
243     my_bool (*was_interrupted)(Vio*);
244     int (*vioclose)(Vio*);
245     void (*timeout)(Vio*, unsigned int which, unsigned int timeout);
246     my_bool (*poll_read)(Vio *vio, uint timeout);
247     my_bool (*is_connected)(Vio*);
248     my_bool (*has_data) (Vio*);
249     };
250    
251 root 1.1 #endif
252 root 1.3
253 root 1.1 #endif /* vio_violite_h_ */