1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/*
|
|
17 |
* Vio Lite.
|
|
18 |
* Purpose: include file for Vio that will work with C and C++
|
|
19 |
*/
|
|
20 |
||
21 |
#ifndef vio_violite_h_
|
|
22 |
#define vio_violite_h_
|
|
23 |
||
24 |
#include "my_net.h" /* needed because of struct in_addr */ |
|
25 |
||
26 |
||
27 |
/* Simple vio interface in C; The functions are implemented in violite.c */
|
|
28 |
||
29 |
#ifdef __cplusplus
|
|
30 |
extern "C" { |
|
31 |
#endif /* __cplusplus */ |
|
32 |
||
33 |
enum enum_vio_type |
|
34 |
{
|
|
35 |
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE, |
|
36 |
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY |
|
37 |
};
|
|
38 |
||
39 |
||
40 |
#define VIO_LOCALHOST 1 /* a localhost connection */ |
|
41 |
#define VIO_BUFFERED_READ 2 /* use buffered read */ |
|
42 |
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */ |
|
43 |
||
44 |
Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags); |
|
45 |
||
46 |
void vio_delete(Vio* vio); |
|
47 |
int vio_close(Vio* vio); |
|
172
by Brian Aker
First pass of cleanup |
48 |
void vio_reset(Vio* vio, enum enum_vio_type type, my_socket sd, uint32_t flags); |
1
by brian
clean slate |
49 |
size_t vio_read(Vio *vio, uchar * buf, size_t size); |
50 |
size_t vio_read_buff(Vio *vio, uchar * buf, size_t size); |
|
51 |
size_t vio_write(Vio *vio, const uchar * buf, size_t size); |
|
172
by Brian Aker
First pass of cleanup |
52 |
int vio_blocking(Vio *vio, bool onoff, bool *old_mode); |
53 |
bool vio_is_blocking(Vio *vio); |
|
1
by brian
clean slate |
54 |
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
|
55 |
int vio_fastsend(Vio *vio); |
|
56 |
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
|
|
172
by Brian Aker
First pass of cleanup |
57 |
int32_t vio_keepalive(Vio *vio, bool onoff); |
1
by brian
clean slate |
58 |
/* Whenever we should retry the last read/write operation. */
|
172
by Brian Aker
First pass of cleanup |
59 |
bool vio_should_retry(Vio *vio); |
1
by brian
clean slate |
60 |
/* Check that operation was timed out */
|
172
by Brian Aker
First pass of cleanup |
61 |
bool vio_was_interrupted(Vio *vio); |
1
by brian
clean slate |
62 |
/* Short text description of the socket for those, who are curious.. */
|
63 |
const char* vio_description(Vio *vio); |
|
64 |
/* Return the type of the connection */
|
|
65 |
enum enum_vio_type vio_type(Vio* vio); |
|
66 |
/* Return last error number */
|
|
67 |
int vio_errno(Vio*vio); |
|
68 |
/* Get socket number */
|
|
69 |
my_socket vio_fd(Vio*vio); |
|
70 |
/* Remote peer's address and name in text form */
|
|
172
by Brian Aker
First pass of cleanup |
71 |
bool vio_peer_addr(Vio *vio, char *buf, uint16 *port, size_t buflen); |
72 |
bool vio_poll_read(Vio *vio,uint timeout); |
|
73 |
bool vio_peek_read(Vio *vio, uint *bytes); |
|
1
by brian
clean slate |
74 |
|
75 |
void vio_end(void); |
|
76 |
||
77 |
#ifdef __cplusplus
|
|
78 |
}
|
|
79 |
#endif
|
|
80 |
||
81 |
#if !defined(DONT_MAP_VIO)
|
|
82 |
#define vio_delete(vio) (vio)->viodelete(vio)
|
|
83 |
#define vio_errno(vio) (vio)->vioerrno(vio)
|
|
84 |
#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
|
|
85 |
#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
|
|
86 |
#define vio_blocking(vio, set_blocking_mode, old_mode)\
|
|
87 |
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
|
|
88 |
#define vio_is_blocking(vio) (vio)->is_blocking(vio)
|
|
89 |
#define vio_fastsend(vio) (vio)->fastsend(vio)
|
|
90 |
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
|
|
91 |
#define vio_should_retry(vio) (vio)->should_retry(vio)
|
|
92 |
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
|
|
93 |
#define vio_close(vio) ((vio)->vioclose)(vio)
|
|
94 |
#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
|
|
95 |
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
|
|
96 |
#endif /* !defined(DONT_MAP_VIO) */ |
|
97 |
||
98 |
/* This enumerator is used in parser - should be always visible */
|
|
99 |
enum SSL_type |
|
100 |
{
|
|
101 |
SSL_TYPE_NOT_SPECIFIED= -1, |
|
102 |
SSL_TYPE_NONE, |
|
103 |
SSL_TYPE_ANY, |
|
104 |
SSL_TYPE_X509, |
|
105 |
SSL_TYPE_SPECIFIED
|
|
106 |
};
|
|
107 |
||
108 |
||
109 |
/* HFTODO - hide this if we don't want client in embedded server */
|
|
110 |
/* This structure is for every connection on both sides */
|
|
111 |
struct st_vio |
|
112 |
{
|
|
113 |
my_socket sd; /* my_socket - real or imaginary */ |
|
114 |
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
|
115 |
struct sockaddr_storage local; /* Local internet address */ |
|
116 |
struct sockaddr_storage remote; /* Remote internet address */ |
|
117 |
int addrLen; /* Length of remote address */ |
|
118 |
enum enum_vio_type type; /* Type of connection */ |
|
119 |
char desc[30]; /* String description */ |
|
120 |
char *read_pos; /* start of unfetched data in the |
|
121 |
read buffer */
|
|
122 |
char *read_end; /* end of unfetched data */ |
|
172
by Brian Aker
First pass of cleanup |
123 |
|
1
by brian
clean slate |
124 |
/* function pointers. They are similar for socket/SSL/whatever */
|
125 |
void (*viodelete)(Vio*); |
|
172
by Brian Aker
First pass of cleanup |
126 |
int32_t (*vioerrno)(Vio*); |
1
by brian
clean slate |
127 |
size_t (*read)(Vio*, uchar *, size_t); |
128 |
size_t (*write)(Vio*, const uchar *, size_t); |
|
172
by Brian Aker
First pass of cleanup |
129 |
int32_t (*vioblocking)(Vio*, bool, bool *); |
130 |
bool (*is_blocking)(Vio*); |
|
131 |
int32_t (*viokeepalive)(Vio*, bool); |
|
132 |
int32_t (*fastsend)(Vio*); |
|
133 |
bool (*peer_addr)(Vio*, char *, uint16_t *, size_t); |
|
1
by brian
clean slate |
134 |
void (*in_addr)(Vio*, struct sockaddr_storage*); |
172
by Brian Aker
First pass of cleanup |
135 |
bool (*should_retry)(Vio*); |
136 |
bool (*was_interrupted)(Vio*); |
|
137 |
int32_t (*vioclose)(Vio*); |
|
138 |
void (*timeout)(Vio*, uint32_t which, uint32_t timeout); |
|
139 |
char *read_buffer; /* buffer for vio_read_buff */ |
|
1
by brian
clean slate |
140 |
};
|
141 |
#endif /* vio_violite_h_ */ |