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 LIBDRIZZLE_VIO_H
22
#define LIBDRIZZLE_VIO_H
24
#include <sys/socket.h>
27
/* Simple vio interface in C; The functions are implemented in violite.c */
31
#endif /* __cplusplus */
35
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
36
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
39
typedef struct st_vio Vio;
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 */
45
Vio* vio_new(int sd, enum enum_vio_type type, unsigned int flags);
47
void vio_delete(Vio* vio);
48
int vio_close(Vio* vio);
49
void vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags);
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);
53
int vio_blocking(Vio *vio, bool onoff, bool *old_mode);
54
bool vio_is_blocking(Vio *vio);
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 */
58
int32_t vio_keepalive(Vio *vio, bool onoff);
59
/* Whenever we should retry the last read/write operation. */
60
bool vio_should_retry(Vio *vio);
61
/* Check that operation was timed out */
62
bool vio_was_interrupted(Vio *vio);
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 */
71
/* Remote peer's address and name in text form */
72
bool vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen);
73
bool vio_poll_read(Vio *vio, int timeout);
74
bool vio_peek_read(Vio *vio, unsigned int *bytes);
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);
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) */
102
/* This enumerator is used in parser - should be always visible */
105
SSL_TYPE_NOT_SPECIFIED= -1,
112
/* HFTODO - hide this if we don't want client in embedded server */
113
/* This structure is for every connection on both sides */
116
int sd; /* int - real or imaginary */
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
125
char *read_end; /* end of unfetched data */
127
/* function pointers. They are similar for socket/SSL/whatever */
128
void (*viodelete)(Vio*);
129
int32_t (*vioerrno)(Vio*);
130
size_t (*read)(Vio*, unsigned char *, size_t);
131
size_t (*write)(Vio*, const unsigned char *, size_t);
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);
137
void (*in_addr)(Vio*, struct sockaddr_storage*);
138
bool (*should_retry)(Vio*);
139
bool (*was_interrupted)(Vio*);
140
int32_t (*vioclose)(Vio*);
141
void (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout);
142
char *read_buffer; /* buffer for vio_read_buff */
145
#endif /* LIBDRIZZLE_VIO_H */