18
18
* Purpose: include file for Vio that will work with C and C++
21
#ifndef LIBDRIZZLECLIENT_VIO_H
22
#define LIBDRIZZLECLIENT_VIO_H
24
#include <sys/socket.h>
21
#ifndef vio_violite_h_
22
#define vio_violite_h_
24
#include "my_net.h" /* needed because of struct in_addr */
27
27
/* Simple vio interface in C; The functions are implemented in violite.c */
31
#endif /* __cplusplus */
31
35
VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
32
36
VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
35
typedef struct st_vio Vio;
37
40
#define VIO_LOCALHOST 1 /* a localhost connection */
38
41
#define VIO_BUFFERED_READ 2 /* use buffered read */
39
42
#define VIO_READ_BUFFER_SIZE 16384 /* size of read buffer */
41
Vio* drizzleclient_vio_new(int sd, enum enum_vio_type type, unsigned int flags);
44
Vio* vio_new(my_socket sd, enum enum_vio_type type, uint flags);
43
void drizzleclient_vio_delete(Vio* vio);
44
int drizzleclient_vio_close(Vio* vio);
45
void drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags);
46
size_t drizzleclient_vio_read(Vio *vio, unsigned char * buf, size_t size);
47
size_t drizzleclient_vio_read_buff(Vio *vio, unsigned char * buf, size_t size);
48
size_t drizzleclient_vio_write(Vio *vio, const unsigned char * buf, size_t size);
49
int drizzleclient_vio_blocking(Vio *vio, bool onoff, bool *old_mode);
50
bool drizzleclient_vio_is_blocking(Vio *vio);
46
void vio_delete(Vio* vio);
47
int vio_close(Vio* vio);
48
void vio_reset(Vio* vio, enum enum_vio_type type, my_socket sd, uint32_t flags);
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);
52
int vio_blocking(Vio *vio, bool onoff, bool *old_mode);
53
bool vio_is_blocking(Vio *vio);
51
54
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
52
int drizzleclient_vio_fastsend(Vio *vio);
55
int vio_fastsend(Vio *vio);
53
56
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
54
int32_t drizzleclient_vio_keepalive(Vio *vio, bool onoff);
57
int32_t vio_keepalive(Vio *vio, bool onoff);
55
58
/* Whenever we should retry the last read/write operation. */
56
bool drizzleclient_vio_should_retry(Vio *vio);
59
bool vio_should_retry(Vio *vio);
57
60
/* Check that operation was timed out */
58
bool drizzleclient_vio_was_interrupted(Vio *vio);
61
bool vio_was_interrupted(Vio *vio);
59
62
/* Short text description of the socket for those, who are curious.. */
60
const char* drizzleclient_vio_description(Vio *vio);
63
const char* vio_description(Vio *vio);
61
64
/* Return the type of the connection */
62
enum enum_vio_type drizzleclient_vio_type(Vio* vio);
65
enum enum_vio_type vio_type(Vio* vio);
63
66
/* Return last error number */
64
int drizzleclient_vio_errno(Vio*vio);
67
int vio_errno(Vio*vio);
65
68
/* Get socket number */
66
int drizzleclient_vio_fd(Vio*vio);
69
my_socket vio_fd(Vio*vio);
67
70
/* Remote peer's address and name in text form */
68
bool drizzleclient_vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen);
69
bool drizzleclient_vio_poll_read(Vio *vio, int timeout);
70
bool drizzleclient_vio_peek_read(Vio *vio, unsigned int *bytes);
72
void drizzleclient_vio_end(void);
74
void drizzleclient_vio_ignore_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
75
void drizzleclient_vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
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);
77
81
#if !defined(DONT_MAP_VIO)
78
#define drizzleclient_vio_delete(vio) (vio)->viodelete(vio)
79
#define drizzleclient_vio_errno(vio) (vio)->vioerrno(vio)
80
#define drizzleclient_vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
81
#define drizzleclient_vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
82
#define drizzleclient_vio_blocking(vio, set_blocking_mode, old_mode)\
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)\
83
87
(vio)->vioblocking(vio, set_blocking_mode, old_mode)
84
#define drizzleclient_vio_is_blocking(vio) (vio)->is_blocking(vio)
85
#define drizzleclient_vio_fastsend(vio) (vio)->fastsend(vio)
86
#define drizzleclient_vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
87
#define drizzleclient_vio_should_retry(vio) (vio)->should_retry(vio)
88
#define drizzleclient_vio_was_interrupted(vio) (vio)->was_interrupted(vio)
89
#define drizzleclient_vio_close(vio) ((vio)->vioclose)(vio)
90
#define drizzleclient_vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
91
#define drizzleclient_vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
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)
92
96
#endif /* !defined(DONT_MAP_VIO) */
94
98
/* This enumerator is used in parser - should be always visible */