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 PLUGIN_DRIZZLE_PROTOCOL_VIO_H
22
#define PLUGIN_DRIZZLE_PROTOCOL_VIO_H
24
#include <sys/socket.h>
27
namespace drizzle_protocol
30
/* Simple vio interface in C; The functions are implemented in violite.c */
34
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
35
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
38
typedef struct st_vio Vio;
40
#define VIO_BUFFERED_READ 2 /* use buffered read */
41
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
43
Vio* drizzleclient_vio_new(int sd, enum enum_vio_type type, unsigned int flags);
45
void drizzleclient_vio_delete(Vio* vio);
46
int drizzleclient_vio_close(Vio* vio);
47
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags);
48
size_t drizzleclient_vio_read(Vio *vio, unsigned char * buf, size_t size);
49
size_t drizzleclient_vio_read_buff(Vio *vio, unsigned char * buf, size_t size);
50
size_t drizzleclient_vio_write(Vio *vio, const unsigned char * buf, size_t size);
51
int drizzleclient_vio_blocking(Vio *vio, bool onoff, bool *old_mode);
52
bool drizzleclient_vio_is_blocking(Vio *vio);
53
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
54
int drizzleclient_vio_fastsend(Vio *vio);
55
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
56
int32_t drizzleclient_vio_keepalive(Vio *vio, bool onoff);
57
/* Whenever we should retry the last read/write operation. */
58
bool drizzleclient_vio_should_retry(Vio *vio);
59
/* Check that operation was timed out */
60
bool drizzleclient_vio_was_interrupted(Vio *vio);
61
/* Short text description of the socket for those, who are curious.. */
62
const char* drizzleclient_vio_description(Vio *vio);
63
/* Return the type of the connection */
64
enum enum_vio_type drizzleclient_vio_type(Vio* vio);
65
/* Return last error number */
66
int drizzleclient_vio_errno(Vio*vio);
67
/* Get socket number */
68
int drizzleclient_vio_fd(Vio*vio);
69
/* Remote peer's address and name in text form */
70
bool drizzleclient_vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen);
71
bool drizzleclient_vio_poll_read(Vio *vio, int timeout);
72
bool drizzleclient_vio_peek_read(Vio *vio, unsigned int *bytes);
74
void drizzleclient_vio_end(void);
76
void drizzleclient_vio_ignore_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
77
void drizzleclient_vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
79
#if !defined(DONT_MAP_VIO)
80
#define drizzleclient_vio_delete(vio) (vio)->viodelete(vio)
81
#define drizzleclient_vio_errno(vio) (vio)->vioerrno(vio)
82
#define drizzleclient_vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
83
#define drizzleclient_vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
84
#define drizzleclient_vio_blocking(vio, set_blocking_mode, old_mode)\
85
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
86
#define drizzleclient_vio_is_blocking(vio) (vio)->is_blocking(vio)
87
#define drizzleclient_vio_fastsend(vio) (vio)->fastsend(vio)
88
#define drizzleclient_vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
89
#define drizzleclient_vio_should_retry(vio) (vio)->should_retry(vio)
90
#define drizzleclient_vio_was_interrupted(vio) (vio)->was_interrupted(vio)
91
#define drizzleclient_vio_close(vio) ((vio)->vioclose)(vio)
92
#define drizzleclient_vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
93
#define drizzleclient_vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
94
#endif /* !defined(DONT_MAP_VIO) */
96
/* This enumerator is used in parser - should be always visible */
99
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*, unsigned char *, size_t);
125
size_t (*write)(Vio*, const unsigned char *, 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 drizzleclient_vio_read_buff */
139
} /* namespace drizzle_procotol */
141
#endif /* PLUGIN_DRIZZLE_PROTOCOL_VIO_H */