~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/vio.h

  • Committer: Brian Aker
  • Date: 2009-01-07 21:26:58 UTC
  • Revision ID: brian@tangent.org-20090107212658-2fh0s2uwh10w68y2
Committing fix lock_multi

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 LIBDRIZZLE_VIO_H
 
22
#define LIBDRIZZLE_VIO_H
 
23
 
 
24
#include <sys/socket.h>
 
25
#include <errno.h>
 
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
typedef struct st_vio Vio;
 
40
 
 
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 */
 
44
 
 
45
Vio*    vio_new(int sd, enum enum_vio_type type, unsigned int flags);
 
46
 
 
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 */
 
70
int vio_fd(Vio*vio);
 
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);
 
75
 
 
76
void vio_end(void);
 
77
 
 
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);
 
80
 
 
81
#ifdef  __cplusplus
 
82
}
 
83
#endif
 
84
 
 
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) */
 
101
 
 
102
/* This enumerator is used in parser - should be always visible */
 
103
enum SSL_type
 
104
{
 
105
  SSL_TYPE_NOT_SPECIFIED= -1,
 
106
  SSL_TYPE_NONE,
 
107
  SSL_TYPE_ANY,
 
108
  SSL_TYPE_X509,
 
109
  SSL_TYPE_SPECIFIED
 
110
};
 
111
 
 
112
/* HFTODO - hide this if we don't want client in embedded server */
 
113
/* This structure is for every connection on both sides */
 
114
struct st_vio
 
115
{
 
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
 
124
                                           read buffer */
 
125
  char                  *read_end;      /* end of unfetched data */
 
126
 
 
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 */
 
143
};
 
144
 
 
145
#endif /* LIBDRIZZLE_VIO_H */