~drizzle-trunk/drizzle/development

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
21
#ifndef vio_violite_h_
22
#define	vio_violite_h_
23
24
#include "my_net.h"			/* needed because of struct in_addr */
25
26
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
39
40
#define VIO_LOCALHOST 1                         /* a localhost connection */
41
#define VIO_BUFFERED_READ 2                     /* use buffered read */
42
#define VIO_READ_BUFFER_SIZE 16384              /* size of read buffer */
43
44
Vio*	vio_new(my_socket sd, enum enum_vio_type type, uint flags);
45
#define HANDLE void *
46
47
void	vio_delete(Vio* vio);
48
int	vio_close(Vio* vio);
49
void    vio_reset(Vio* vio, enum enum_vio_type type,
50
                  my_socket sd, HANDLE hPipe, uint flags);
51
size_t	vio_read(Vio *vio, uchar *	buf, size_t size);
52
size_t  vio_read_buff(Vio *vio, uchar * buf, size_t size);
53
size_t	vio_write(Vio *vio, const uchar * buf, size_t size);
54
int	vio_blocking(Vio *vio, my_bool onoff, my_bool *old_mode);
55
my_bool	vio_is_blocking(Vio *vio);
56
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
57
int	vio_fastsend(Vio *vio);
58
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
59
int	vio_keepalive(Vio *vio, my_bool	onoff);
60
/* Whenever we should retry the last read/write operation. */
61
my_bool	vio_should_retry(Vio *vio);
62
/* Check that operation was timed out */
63
my_bool	vio_was_interrupted(Vio *vio);
64
/* Short text description of the socket for those, who are curious.. */
65
const char* vio_description(Vio *vio);
66
/* Return the type of the connection */
67
enum enum_vio_type vio_type(Vio* vio);
68
/* Return last error number */
69
int	vio_errno(Vio*vio);
70
/* Get socket number */
71
my_socket vio_fd(Vio*vio);
72
/* Remote peer's address and name in text form */
73
my_bool vio_peer_addr(Vio *vio, char *buf, uint16 *port, size_t buflen);
74
my_bool	vio_poll_read(Vio *vio,uint timeout);
75
my_bool vio_peek_read(Vio *vio, uint *bytes);
76
77
#ifdef HAVE_SMEM
78
size_t vio_read_shared_memory(Vio *vio, uchar * buf, size_t size);
79
size_t vio_write_shared_memory(Vio *vio, const uchar * buf, size_t size);
80
int vio_close_shared_memory(Vio * vio);
81
#endif
82
83
void vio_end(void);
84
85
#ifdef	__cplusplus
86
}
87
#endif
88
89
#if !defined(DONT_MAP_VIO)
90
#define vio_delete(vio) 			(vio)->viodelete(vio)
91
#define vio_errno(vio)	 			(vio)->vioerrno(vio)
92
#define vio_read(vio, buf, size)                ((vio)->read)(vio,buf,size)
93
#define vio_write(vio, buf, size)               ((vio)->write)(vio, buf, size)
94
#define vio_blocking(vio, set_blocking_mode, old_mode)\
95
 	(vio)->vioblocking(vio, set_blocking_mode, old_mode)
96
#define vio_is_blocking(vio) 			(vio)->is_blocking(vio)
97
#define vio_fastsend(vio)			(vio)->fastsend(vio)
98
#define vio_keepalive(vio, set_keep_alive)	(vio)->viokeepalive(vio, set_keep_alive)
99
#define vio_should_retry(vio) 			(vio)->should_retry(vio)
100
#define vio_was_interrupted(vio) 		(vio)->was_interrupted(vio)
101
#define vio_close(vio)				((vio)->vioclose)(vio)
102
#define vio_peer_addr(vio, buf, prt, buflen)	(vio)->peer_addr(vio, buf, prt, buflen)
103
#define vio_timeout(vio, which, seconds)	(vio)->timeout(vio, which, seconds)
104
#endif /* !defined(DONT_MAP_VIO) */
105
106
/* This enumerator is used in parser - should be always visible */
107
enum SSL_type
108
{
109
  SSL_TYPE_NOT_SPECIFIED= -1,
110
  SSL_TYPE_NONE,
111
  SSL_TYPE_ANY,
112
  SSL_TYPE_X509,
113
  SSL_TYPE_SPECIFIED
114
};
115
116
117
/* HFTODO - hide this if we don't want client in embedded server */
118
/* This structure is for every connection on both sides */
119
struct st_vio
120
{
121
  my_socket		sd;		/* my_socket - real or imaginary */
122
  HANDLE hPipe;
123
  my_bool		localhost;	/* Are we from localhost? */
124
  int			fcntl_mode;	/* Buffered fcntl(sd,F_GETFL) */
125
  struct sockaddr_storage	local;		/* Local internet address */
126
  struct sockaddr_storage	remote;		/* Remote internet address */
127
  int addrLen;                          /* Length of remote address */
128
  enum enum_vio_type	type;		/* Type of connection */
129
  char			desc[30];	/* String description */
130
  char                  *read_buffer;   /* buffer for vio_read_buff */
131
  char                  *read_pos;      /* start of unfetched data in the
132
                                           read buffer */
133
  char                  *read_end;      /* end of unfetched data */
134
  /* function pointers. They are similar for socket/SSL/whatever */
135
  void    (*viodelete)(Vio*);
136
  int     (*vioerrno)(Vio*);
137
  size_t  (*read)(Vio*, uchar *, size_t);
138
  size_t  (*write)(Vio*, const uchar *, size_t);
139
  int     (*vioblocking)(Vio*, my_bool, my_bool *);
140
  my_bool (*is_blocking)(Vio*);
141
  int     (*viokeepalive)(Vio*, my_bool);
142
  int     (*fastsend)(Vio*);
143
  my_bool (*peer_addr)(Vio*, char *, uint16*, size_t);
144
  void    (*in_addr)(Vio*, struct sockaddr_storage*);
145
  my_bool (*should_retry)(Vio*);
146
  my_bool (*was_interrupted)(Vio*);
147
  int     (*vioclose)(Vio*);
148
  void	  (*timeout)(Vio*, unsigned int which, unsigned int timeout);
149
#ifdef HAVE_SMEM
150
  HANDLE  handle_file_map;
151
  char    *handle_map;
152
  HANDLE  event_server_wrote;
153
  HANDLE  event_server_read;
154
  HANDLE  event_client_wrote;
155
  HANDLE  event_client_read;
156
  HANDLE  event_conn_closed;
157
  size_t  shared_memory_remain;
158
  char    *shared_memory_pos;
159
  NET     *net;
160
#endif /* HAVE_SMEM */
161
};
162
#endif /* vio_violite_h_ */