1
/* Copyright (C) 2000 MySQL AB
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.
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.
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 */
18
* Purpose: include file for Vio that will work with C and C++
21
#ifndef vio_violite_h_
22
#define vio_violite_h_
24
/* Simple vio interface in C; The functions are implemented in violite.c */
28
#endif /* __cplusplus */
32
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
33
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
37
#define VIO_LOCALHOST 1 /* a localhost connection */
38
#define VIO_BUFFERED_READ 2 /* use buffered read */
39
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
41
Vio* vio_new(int sd, enum enum_vio_type type, uint flags);
43
void vio_delete(Vio* vio);
44
int vio_close(Vio* vio);
45
void vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags);
46
size_t vio_read(Vio *vio, uchar * buf, size_t size);
47
size_t vio_read_buff(Vio *vio, uchar * buf, size_t size);
48
size_t vio_write(Vio *vio, const uchar * buf, size_t size);
49
int vio_blocking(Vio *vio, bool onoff, bool *old_mode);
50
bool vio_is_blocking(Vio *vio);
51
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
52
int vio_fastsend(Vio *vio);
53
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
54
int32_t vio_keepalive(Vio *vio, bool onoff);
55
/* Whenever we should retry the last read/write operation. */
56
bool vio_should_retry(Vio *vio);
57
/* Check that operation was timed out */
58
bool vio_was_interrupted(Vio *vio);
59
/* Short text description of the socket for those, who are curious.. */
60
const char* vio_description(Vio *vio);
61
/* Return the type of the connection */
62
enum enum_vio_type vio_type(Vio* vio);
63
/* Return last error number */
64
int vio_errno(Vio*vio);
65
/* Get socket number */
67
/* Remote peer's address and name in text form */
68
bool vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen);
69
bool vio_poll_read(Vio *vio, int timeout);
70
bool vio_peek_read(Vio *vio, uint *bytes);
78
#if !defined(DONT_MAP_VIO)
79
#define vio_delete(vio) (vio)->viodelete(vio)
80
#define vio_errno(vio) (vio)->vioerrno(vio)
81
#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
82
#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
83
#define vio_blocking(vio, set_blocking_mode, old_mode)\
84
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
85
#define vio_is_blocking(vio) (vio)->is_blocking(vio)
86
#define vio_fastsend(vio) (vio)->fastsend(vio)
87
#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
88
#define vio_should_retry(vio) (vio)->should_retry(vio)
89
#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
90
#define vio_close(vio) ((vio)->vioclose)(vio)
91
#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
92
#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
93
#endif /* !defined(DONT_MAP_VIO) */
95
/* This enumerator is used in parser - should be always visible */
98
SSL_TYPE_NOT_SPECIFIED= -1,
106
/* HFTODO - hide this if we don't want client in embedded server */
107
/* This structure is for every connection on both sides */
110
int sd; /* int - real or imaginary */
111
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
112
struct sockaddr_storage local; /* Local internet address */
113
struct sockaddr_storage remote; /* Remote internet address */
114
int addrLen; /* Length of remote address */
115
enum enum_vio_type type; /* Type of connection */
116
char desc[30]; /* String description */
117
char *read_pos; /* start of unfetched data in the
119
char *read_end; /* end of unfetched data */
121
/* function pointers. They are similar for socket/SSL/whatever */
122
void (*viodelete)(Vio*);
123
int32_t (*vioerrno)(Vio*);
124
size_t (*read)(Vio*, uchar *, size_t);
125
size_t (*write)(Vio*, const uchar *, size_t);
126
int32_t (*vioblocking)(Vio*, bool, bool *);
127
bool (*is_blocking)(Vio*);
128
int32_t (*viokeepalive)(Vio*, bool);
129
int32_t (*fastsend)(Vio*);
130
bool (*peer_addr)(Vio*, char *, uint16_t *, size_t);
131
void (*in_addr)(Vio*, struct sockaddr_storage*);
132
bool (*should_retry)(Vio*);
133
bool (*was_interrupted)(Vio*);
134
int32_t (*vioclose)(Vio*);
135
void (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout);
136
char *read_buffer; /* buffer for vio_read_buff */
138
#endif /* vio_violite_h_ */