summaryrefslogtreecommitdiff
path: root/vio/Vio.h
blob: 959d472873fa7e2f1aa7e4da0ef8d1b3f5d50ea9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Abstract Virtual IO interface - class Vio. Heavily
 * influenced by Berkeley sockets and oriented toward MySQL.
 */

/* 
**  Virtual I/O library
**  Written by Andrei Errapart <andreie@no.spam.ee>
**  Modified by Monty
*/

#ifdef __GNUC__
#pragma interface			/* gcc class implementation */
#endif

VIO_NS_BEGIN

enum enum_vio_type { VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET,
		     VIO_TYPE_NAMEDPIPE, VIO_TYPE_SSL};

class Vio {
public:
  virtual bool		is_open() const = 0;
  virtual int		read(vio_ptr buf, int size) = 0;
  virtual int		write(const vio_ptr buf, int size) = 0;
  virtual int		blocking(bool	onoff) = 0;
  virtual bool		blocking() const = 0;
  virtual bool		fcntl() const = 0;
  virtual int		fastsend(bool	onoff = true) = 0;
  virtual int		keepalive(bool	onoff) = 0;
  virtual bool		should_retry() const = 0;
  virtual int		close() = 0;
  virtual void 		release();
  virtual const char*	description() const = 0;
  virtual bool		peer_addr(char *buf) const = 0;
  virtual const char*	cipher_description() const = 0;
  virtual int 		vio_errno();
  virtual ~Vio();
};

/* Macros to simulate the violite C interface */


Vio *vio_new(my_socket	sd, enum enum_vio_type type,
	     my_bool localhost);
#ifdef __WIN__
Vio*		vio_new_win32pipe(HANDLE hPipe);
#endif

#define vio_delete(vio) delete vio
#define vio_read(vio,buf,size) vio->read(buf,size)
#define vio_write(vio,buf,size) vio->write(buf,size)
#define vio_blocking(vio,mode) vio->blocking(mode)
#define vio_is_blocking(vio) vio->is_blocking()
#define vio_fastsend(vio,mode) vio->fastsend(mode)
#define vio_keepalive(vio,mode) vio->keepalive(mode)
#define vio_shouldretry(vio) vio->shouldretry(mode)
#define vio_close(vio) vio->close()
#define vio_description(vio) vio->description()
#define vio_errno(Vio *vio) vio->errno()
#define vio_peer_addr(vio,buf) vio->peer_addr(buf)
#define vio_in_addr(vio,in) vio->in_addr(in)

VIO_NS_END