~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/mysql_protocol/vio.h

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
 
16
/*
 
17
 * Vio Lite.
 
18
 * Purpose: include file for Vio that will work with C and C++
 
19
 */
16
20
 
17
21
#ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H
18
 
#define PLUGIN_MYSQL_PROTOCOL_VIO_H
 
22
#define PLUGIN_MYSQL_PROTOCOL_VIO_H
19
23
 
20
24
#include <sys/socket.h>
21
 
#include <cerrno>
22
 
 
23
 
namespace drizzle_plugin
24
 
{
25
 
 
26
 
/**
27
 
 *@brief Virtual I/O layer, only used with TCP/IP sockets at the moment.
28
 
 */
29
 
class Vio
30
 
{
31
 
public:
32
 
  /**
33
 
   * Constructor. 
34
 
   * @param[in] sd Descriptor to use.
35
 
   */
36
 
  Vio(int sd);
37
 
  ~Vio();
38
 
 
39
 
  /**
40
 
   *Close the connection.
41
 
   *@returns 0 on success.
42
 
   */
43
 
  int close();
44
 
 
45
 
  /**
46
 
   * Read some data from the remote end.
47
 
   *@param[out] buf A buffer to write the new data to.
48
 
   *@param[in] size The size of the buffer
49
 
   *@returns The number of bytes read.
50
 
   */
51
 
  size_t read(unsigned char* buf, size_t size);
52
 
  
53
 
  /**
54
 
   * Write some data to the remote end.
55
 
   *@param[in] buf A buffer that contains the data to send.
56
 
   *@param[in] size The size of the buffer
57
 
   *@returns The number of bytes written.
58
 
   */
59
 
  size_t write(const unsigned char* buf, size_t size);
60
 
 
61
 
  /**
62
 
   * Set device blocking mode.
63
 
   *@param[in] set_blocking_mode Whether the device should block. true sets blocking mode, false clears it.
64
 
   *@param[out] old_mode This will be set to the previous blocking mode.
65
 
   *@returns 0 on success.
66
 
   */
67
 
  int blocking(bool set_blocking_mode, bool *old_mode);
68
 
 
69
 
  /**
70
 
   * Enables fast sending.
71
 
   * Setting this sets the TCP_NODELAY socket option.
72
 
   *@returns 0 on succcess.
73
 
   */
74
 
  int fastsend();
75
 
 
76
 
  /**
77
 
   * Sets or clears the keepalive option.
78
 
   *@param[in] set_keep_alive Whether to set or clear the flag. True Sets keepalive, false clears it.
79
 
   *@returns 0 on success.
80
 
   */
81
 
  int32_t keepalive(bool set_keep_alive);
82
 
 
83
 
  /**
84
 
   *@returns true if the caller should retry the last operation.
85
 
   */
86
 
  bool should_retry() const;
87
 
 
88
 
  /**
89
 
   *@returns true if the last operation was interrupted.
90
 
   */
91
 
  bool was_interrupted() const;
92
 
 
93
 
  /**
94
 
   *Gets the address details of the peer.
95
 
   @param[out] buf Buffer that will recieve the peer address.
96
 
   @param[out] port Port of remote end.
97
 
   @param[in] buflen Size of buf.
98
 
   @returns True on success, false otherwise.
99
 
   */
100
 
  bool peer_addr(char *buf, uint16_t *port, size_t buflen) const;
101
 
 
102
 
  /**
103
 
   * Sets either the send, or recieve timeouts for the socket.
104
 
   *@param[in] is_sndtimeo Set to true to change the send timeout, false to change the recieve timeout.
105
 
   *@param[in] timeout The new timeout to set, in seconds.
106
 
   */
107
 
  void timeout(bool is_sndtimeo, int32_t timeout);
108
 
 
109
 
  /**
110
 
   * Returns the last error code.
111
 
   *@returns the last error code, as described in errno.h
112
 
   */
113
 
  int get_errno() const;
114
 
 
115
 
  /**
116
 
   * Get the underlying descriptor this class is using.
117
 
   *@returns The descriptor passed in to the constructor of this class.
118
 
   */
119
 
  int get_fd() const;
120
 
 
121
 
  /**
122
 
   * Returns the current read position.
123
 
   */
124
 
  char *get_read_pos() const;
125
 
 
126
 
  /**
127
 
   * Returns the current write position.
128
 
   */
129
 
  char *get_read_end() const;
130
 
 
131
 
private:
132
 
  bool closed;
133
 
  int sd;
134
 
  int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
135
 
  struct sockaddr_storage local; /* Local internet address */
136
 
  struct sockaddr_storage remote; /* Remote internet address */
137
 
  char *read_pos; /* start of unfetched data in the read buffer */
138
 
  char *read_end; /* end of unfetched data */
139
 
 
140
 
};
141
 
 
142
 
} /* namespace drizzle_plugin */
 
25
#include <errno.h>
 
26
 
 
27
/* Simple vio interface in C;  The functions are implemented in violite.c */
 
28
 
 
29
enum enum_vio_type
 
30
{
 
31
  VIO_CLOSED, VIO_TYPE_TCPIP, VIO_TYPE_SOCKET, VIO_TYPE_NAMEDPIPE,
 
32
  VIO_TYPE_SSL, VIO_TYPE_SHARED_MEMORY
 
33
};
 
34
 
 
35
typedef struct st_vio Vio;
 
36
 
 
37
#define VIO_BUFFERED_READ 2                     /* use buffered read */
 
38
#define VIO_READ_BUFFER_SIZE 16384              /* size of read buffer */
 
39
 
 
40
Vio*    drizzleclient_vio_new(int sd, enum enum_vio_type type, unsigned int flags);
 
41
 
 
42
void    drizzleclient_vio_delete(Vio* vio);
 
43
int     drizzleclient_vio_close(Vio* vio);
 
44
void    drizzleclient_vio_reset(Vio* vio, enum enum_vio_type type, int sd, uint32_t flags);
 
45
size_t  drizzleclient_vio_read(Vio *vio, unsigned char *        buf, size_t size);
 
46
size_t  drizzleclient_vio_read_buff(Vio *vio, unsigned char * buf, size_t size);
 
47
size_t  drizzleclient_vio_write(Vio *vio, const unsigned char * buf, size_t size);
 
48
int     drizzleclient_vio_blocking(Vio *vio, bool onoff, bool *old_mode);
 
49
bool    drizzleclient_vio_is_blocking(Vio *vio);
 
50
/* setsockopt TCP_NODELAY at IPPROTO_TCP level, when possible */
 
51
int     drizzleclient_vio_fastsend(Vio *vio);
 
52
/* setsockopt SO_KEEPALIVE at SOL_SOCKET level, when possible */
 
53
int32_t drizzleclient_vio_keepalive(Vio *vio, bool      onoff);
 
54
/* Whenever we should retry the last read/write operation. */
 
55
bool    drizzleclient_vio_should_retry(Vio *vio);
 
56
/* Check that operation was timed out */
 
57
bool    drizzleclient_vio_was_interrupted(Vio *vio);
 
58
/* Short text description of the socket for those, who are curious.. */
 
59
const char* drizzleclient_vio_description(Vio *vio);
 
60
/* Return the type of the connection */
 
61
enum enum_vio_type drizzleclient_vio_type(Vio* vio);
 
62
/* Return last error number */
 
63
int     drizzleclient_vio_errno(Vio*vio);
 
64
/* Get socket number */
 
65
int drizzleclient_vio_fd(Vio*vio);
 
66
/* Remote peer's address and name in text form */
 
67
bool drizzleclient_vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen);
 
68
bool drizzleclient_vio_poll_read(Vio *vio, int timeout);
 
69
bool drizzleclient_vio_peek_read(Vio *vio, unsigned int *bytes);
 
70
 
 
71
void drizzleclient_vio_end(void);
 
72
 
 
73
void drizzleclient_vio_ignore_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
 
74
void drizzleclient_vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout);
 
75
 
 
76
#if !defined(DONT_MAP_VIO)
 
77
#define drizzleclient_vio_delete(vio)                   (vio)->viodelete(vio)
 
78
#define drizzleclient_vio_errno(vio)                            (vio)->vioerrno(vio)
 
79
#define drizzleclient_vio_read(vio, buf, size)                ((vio)->read)(vio,buf,size)
 
80
#define drizzleclient_vio_write(vio, buf, size)               ((vio)->write)(vio, buf, size)
 
81
#define drizzleclient_vio_blocking(vio, set_blocking_mode, old_mode)\
 
82
        (vio)->vioblocking(vio, set_blocking_mode, old_mode)
 
83
#define drizzleclient_vio_is_blocking(vio)                      (vio)->is_blocking(vio)
 
84
#define drizzleclient_vio_fastsend(vio)                 (vio)->fastsend(vio)
 
85
#define drizzleclient_vio_keepalive(vio, set_keep_alive)        (vio)->viokeepalive(vio, set_keep_alive)
 
86
#define drizzleclient_vio_should_retry(vio)                     (vio)->should_retry(vio)
 
87
#define drizzleclient_vio_was_interrupted(vio)          (vio)->was_interrupted(vio)
 
88
#define drizzleclient_vio_close(vio)                            ((vio)->vioclose)(vio)
 
89
#define drizzleclient_vio_peer_addr(vio, buf, prt, buflen)      (vio)->peer_addr(vio, buf, prt, buflen)
 
90
#define drizzleclient_vio_timeout(vio, which, seconds)  (vio)->timeout(vio, which, seconds)
 
91
#endif /* !defined(DONT_MAP_VIO) */
 
92
 
 
93
/* This enumerator is used in parser - should be always visible */
 
94
enum SSL_type
 
95
{
 
96
  SSL_TYPE_NOT_SPECIFIED= -1,
 
97
  SSL_TYPE_NONE,
 
98
  SSL_TYPE_ANY,
 
99
  SSL_TYPE_X509,
 
100
  SSL_TYPE_SPECIFIED
 
101
};
 
102
 
 
103
/* HFTODO - hide this if we don't want client in embedded server */
 
104
/* This structure is for every connection on both sides */
 
105
struct st_vio
 
106
{
 
107
  int           sd;             /* int - real or imaginary */
 
108
  int                   fcntl_mode;     /* Buffered fcntl(sd,F_GETFL) */
 
109
  struct sockaddr_storage       local;          /* Local internet address */
 
110
  struct sockaddr_storage       remote;         /* Remote internet address */
 
111
  int addrLen;                          /* Length of remote address */
 
112
  enum enum_vio_type    type;           /* Type of connection */
 
113
  char                  desc[30];       /* String description */
 
114
  char                  *read_pos;      /* start of unfetched data in the
 
115
                                           read buffer */
 
116
  char                  *read_end;      /* end of unfetched data */
 
117
 
 
118
  /* function pointers. They are similar for socket/SSL/whatever */
 
119
  void    (*viodelete)(Vio*);
 
120
  int32_t     (*vioerrno)(Vio*);
 
121
  size_t  (*read)(Vio*, unsigned char *, size_t);
 
122
  size_t  (*write)(Vio*, const unsigned char *, size_t);
 
123
  int32_t     (*vioblocking)(Vio*, bool, bool *);
 
124
  bool (*is_blocking)(Vio*);
 
125
  int32_t     (*viokeepalive)(Vio*, bool);
 
126
  int32_t     (*fastsend)(Vio*);
 
127
  bool (*peer_addr)(Vio*, char *, uint16_t *, size_t);
 
128
  void    (*in_addr)(Vio*, struct sockaddr_storage*);
 
129
  bool (*should_retry)(Vio*);
 
130
  bool (*was_interrupted)(Vio*);
 
131
  int32_t     (*vioclose)(Vio*);
 
132
  void    (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout);
 
133
  char                  *read_buffer;   /* buffer for drizzleclient_vio_read_buff */
 
134
};
143
135
 
144
136
#endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */