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 |
||
575.2.2
by Monty Taylor
Moved vio stuff into libdrizzle. |
21 |
#ifndef LIBDRIZZLE_VIO_H
|
22 |
#define LIBDRIZZLE_VIO_H
|
|
1
by brian
clean slate |
23 |
|
390.1.5
by Monty Taylor
Moved more functions into drizzle.c as part of the split of code. |
24 |
#include <sys/socket.h> |
25 |
#include <errno.h> |
|
26 |
||
1
by brian
clean slate |
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 |
||
520.6.1
by Monty Taylor
Removed common.h from common_includes.h. |
39 |
typedef struct st_vio Vio; |
40 |
||
1
by brian
clean slate |
41 |
#define VIO_LOCALHOST 1 /* a localhost connection */ |
42 |
#define VIO_BUFFERED_READ 2 /* use buffered read */ |
|
43 |
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */ |
|
44 |
||
395
by Brian Aker
Fixed uint/ushort issue in libdrizzle |
45 |
Vio* vio_new(int sd, enum enum_vio_type type, unsigned int flags); |
1
by brian
clean slate |
46 |
|
47 |
void vio_delete(Vio* vio); |
|
48 |
int vio_close(Vio* vio); |
|
268
by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef |
49 |
void vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags); |
390.1.5
by Monty Taylor
Moved more functions into drizzle.c as part of the split of code. |
50 |
size_t vio_read(Vio *vio, unsigned char * buf, size_t size); |
51 |
size_t vio_read_buff(Vio *vio, unsigned char * buf, size_t size); |
|
52 |
size_t vio_write(Vio *vio, const unsigned char * buf, size_t size); |
|
172
by Brian Aker
First pass of cleanup |
53 |
int vio_blocking(Vio *vio, bool onoff, bool *old_mode); |
54 |
bool vio_is_blocking(Vio *vio); |
|
1
by brian
clean slate |
55 |
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
|
56 |
int vio_fastsend(Vio *vio); |
|
57 |
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
|
|
172
by Brian Aker
First pass of cleanup |
58 |
int32_t vio_keepalive(Vio *vio, bool onoff); |
1
by brian
clean slate |
59 |
/* Whenever we should retry the last read/write operation. */
|
172
by Brian Aker
First pass of cleanup |
60 |
bool vio_should_retry(Vio *vio); |
1
by brian
clean slate |
61 |
/* Check that operation was timed out */
|
172
by Brian Aker
First pass of cleanup |
62 |
bool vio_was_interrupted(Vio *vio); |
1
by brian
clean slate |
63 |
/* Short text description of the socket for those, who are curious.. */
|
64 |
const char* vio_description(Vio *vio); |
|
65 |
/* Return the type of the connection */
|
|
66 |
enum enum_vio_type vio_type(Vio* vio); |
|
67 |
/* Return last error number */
|
|
68 |
int vio_errno(Vio*vio); |
|
69 |
/* Get socket number */
|
|
268
by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef |
70 |
int vio_fd(Vio*vio); |
1
by brian
clean slate |
71 |
/* Remote peer's address and name in text form */
|
206
by Brian Aker
Removed final uint dead types. |
72 |
bool vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen); |
268
by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef |
73 |
bool vio_poll_read(Vio *vio, int timeout); |
395
by Brian Aker
Fixed uint/ushort issue in libdrizzle |
74 |
bool vio_peek_read(Vio *vio, unsigned int *bytes); |
1
by brian
clean slate |
75 |
|
76 |
void vio_end(void); |
|
77 |
||
575.2.2
by Monty Taylor
Moved vio stuff into libdrizzle. |
78 |
void vio_ignore_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout); |
79 |
void vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout); |
|
80 |
||
1
by brian
clean slate |
81 |
#ifdef __cplusplus
|
82 |
}
|
|
83 |
#endif
|
|
84 |
||
85 |
#if !defined(DONT_MAP_VIO)
|
|
86 |
#define vio_delete(vio) (vio)->viodelete(vio)
|
|
87 |
#define vio_errno(vio) (vio)->vioerrno(vio)
|
|
88 |
#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
|
|
89 |
#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
|
|
90 |
#define vio_blocking(vio, set_blocking_mode, old_mode)\
|
|
91 |
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
|
|
92 |
#define vio_is_blocking(vio) (vio)->is_blocking(vio)
|
|
93 |
#define vio_fastsend(vio) (vio)->fastsend(vio)
|
|
94 |
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
|
|
95 |
#define vio_should_retry(vio) (vio)->should_retry(vio)
|
|
96 |
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
|
|
97 |
#define vio_close(vio) ((vio)->vioclose)(vio)
|
|
98 |
#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
|
|
99 |
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
|
|
100 |
#endif /* !defined(DONT_MAP_VIO) */ |
|
101 |
||
102 |
/* This enumerator is used in parser - should be always visible */
|
|
103 |
enum SSL_type |
|
104 |
{
|
|
105 |
SSL_TYPE_NOT_SPECIFIED= -1, |
|
106 |
SSL_TYPE_NONE, |
|
107 |
SSL_TYPE_ANY, |
|
108 |
SSL_TYPE_X509, |
|
109 |
SSL_TYPE_SPECIFIED
|
|
110 |
};
|
|
111 |
||
112 |
/* HFTODO - hide this if we don't want client in embedded server */
|
|
113 |
/* This structure is for every connection on both sides */
|
|
114 |
struct st_vio |
|
115 |
{
|
|
268
by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef |
116 |
int sd; /* int - real or imaginary */ |
1
by brian
clean slate |
117 |
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
118 |
struct sockaddr_storage local; /* Local internet address */ |
|
119 |
struct sockaddr_storage remote; /* Remote internet address */ |
|
120 |
int addrLen; /* Length of remote address */ |
|
121 |
enum enum_vio_type type; /* Type of connection */ |
|
122 |
char desc[30]; /* String description */ |
|
123 |
char *read_pos; /* start of unfetched data in the |
|
124 |
read buffer */
|
|
125 |
char *read_end; /* end of unfetched data */ |
|
172
by Brian Aker
First pass of cleanup |
126 |
|
1
by brian
clean slate |
127 |
/* function pointers. They are similar for socket/SSL/whatever */
|
128 |
void (*viodelete)(Vio*); |
|
172
by Brian Aker
First pass of cleanup |
129 |
int32_t (*vioerrno)(Vio*); |
390.1.5
by Monty Taylor
Moved more functions into drizzle.c as part of the split of code. |
130 |
size_t (*read)(Vio*, unsigned char *, size_t); |
131 |
size_t (*write)(Vio*, const unsigned char *, size_t); |
|
172
by Brian Aker
First pass of cleanup |
132 |
int32_t (*vioblocking)(Vio*, bool, bool *); |
133 |
bool (*is_blocking)(Vio*); |
|
134 |
int32_t (*viokeepalive)(Vio*, bool); |
|
135 |
int32_t (*fastsend)(Vio*); |
|
136 |
bool (*peer_addr)(Vio*, char *, uint16_t *, size_t); |
|
1
by brian
clean slate |
137 |
void (*in_addr)(Vio*, struct sockaddr_storage*); |
172
by Brian Aker
First pass of cleanup |
138 |
bool (*should_retry)(Vio*); |
139 |
bool (*was_interrupted)(Vio*); |
|
140 |
int32_t (*vioclose)(Vio*); |
|
268
by Brian Aker
Merging up a bunch of assert() and cleanup of my_sock typedef |
141 |
void (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout); |
172
by Brian Aker
First pass of cleanup |
142 |
char *read_buffer; /* buffer for vio_read_buff */ |
1
by brian
clean slate |
143 |
};
|
575.2.2
by Monty Taylor
Moved vio stuff into libdrizzle. |
144 |
|
145 |
#endif /* LIBDRIZZLE_VIO_H */ |