1 |
/* adapted from violite.h from mysql 5.0.51 */ |
2 |
/* 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 |
#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 |
|
42 |
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 |
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 |
#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 |
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 |
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 |
#if MYSQL_VERSION_ID < 50500 |
139 |
|
140 |
struct st_vio |
141 |
{ |
142 |
my_socket sd; /* my_socket - real or imaginary */ |
143 |
HANDLE hPipe; |
144 |
my_bool localhost; /* Are we from localhost? */ |
145 |
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
146 |
struct sockaddr_in local; /* Local internet address */ |
147 |
struct sockaddr_in remote; /* Remote internet address */ |
148 |
enum enum_vio_type type; /* Type of connection */ |
149 |
char desc[30]; /* String description */ |
150 |
char *read_buffer; /* buffer for vio_read_buff */ |
151 |
char *read_pos; /* start of unfetched data in the |
152 |
read buffer */ |
153 |
char *read_end; /* end of unfetched data */ |
154 |
/* function pointers. They are similar for socket/SSL/whatever */ |
155 |
void (*viodelete)(Vio*); |
156 |
int (*vioerrno)(Vio*); |
157 |
xlen (*read)(Vio*, xgptr, xlen); |
158 |
xlen (*write)(Vio*, cxgptr, xlen); |
159 |
int (*vioblocking)(Vio*, my_bool, my_bool *); |
160 |
my_bool (*is_blocking)(Vio*); |
161 |
int (*viokeepalive)(Vio*, my_bool); |
162 |
int (*fastsend)(Vio*); |
163 |
my_bool (*peer_addr)(Vio*, char *, uint16*); |
164 |
void (*in_addr)(Vio*, struct in_addr*); |
165 |
my_bool (*should_retry)(Vio*); |
166 |
my_bool (*was_interrupted)(Vio*); |
167 |
int (*vioclose)(Vio*); |
168 |
void (*timeout)(Vio*, unsigned int which, unsigned int timeout); |
169 |
}; |
170 |
|
171 |
#else |
172 |
|
173 |
struct st_vio |
174 |
{ |
175 |
my_socket sd; /* my_socket - real or imaginary */ |
176 |
HANDLE hPipe; |
177 |
my_bool localhost; /* Are we from localhost? */ |
178 |
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
179 |
struct sockaddr_storage local; /* Local internet address */ |
180 |
struct sockaddr_storage remote; /* Remote internet address */ |
181 |
int addrLen; /* Length of remote address */ |
182 |
enum enum_vio_type type; /* Type of connection */ |
183 |
char desc[30]; /* String description */ |
184 |
char *read_buffer; /* buffer for vio_read_buff */ |
185 |
char *read_pos; /* start of unfetched data in the |
186 |
read buffer */ |
187 |
char *read_end; /* end of unfetched data */ |
188 |
/* function pointers. They are similar for socket/SSL/whatever */ |
189 |
void (*viodelete)(Vio*); |
190 |
int (*vioerrno)(Vio*); |
191 |
size_t (*read)(Vio*, unsigned char *, size_t); |
192 |
size_t (*write)(Vio*, const unsigned char *, size_t); |
193 |
int (*vioblocking)(Vio*, my_bool, my_bool *); |
194 |
my_bool (*is_blocking)(Vio*); |
195 |
int (*viokeepalive)(Vio*, my_bool); |
196 |
int (*fastsend)(Vio*); |
197 |
my_bool (*peer_addr)(Vio*, char *, uint16*, size_t); |
198 |
void (*in_addr)(Vio*, struct sockaddr_storage*); |
199 |
my_bool (*should_retry)(Vio*); |
200 |
my_bool (*was_interrupted)(Vio*); |
201 |
int (*vioclose)(Vio*); |
202 |
void (*timeout)(Vio*, unsigned int which, unsigned int timeout); |
203 |
my_bool (*poll_read)(Vio *vio, uint timeout); |
204 |
my_bool (*is_connected)(Vio*); |
205 |
my_bool (*has_data) (Vio*); |
206 |
}; |
207 |
|
208 |
#endif |
209 |
|
210 |
#endif /* vio_violite_h_ */ |