1
/* Copyright (C) 2000 MySQL AB
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
#ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H
18
#define PLUGIN_MYSQL_PROTOCOL_VIO_H
20
#include <sys/socket.h>
23
namespace drizzle_plugin
27
*@brief Virtual I/O layer, only used with TCP/IP sockets at the moment.
34
* @param[in] sd Descriptor to use.
40
*Close the connection.
41
*@returns 0 on success.
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.
51
size_t read(unsigned char* buf, size_t size);
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.
59
size_t write(const unsigned char* buf, size_t size);
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.
67
int blocking(bool set_blocking_mode, bool *old_mode);
70
* Enables fast sending.
71
* Setting this sets the TCP_NODELAY socket option.
72
*@returns 0 on succcess.
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.
81
int32_t keepalive(bool set_keep_alive);
84
*@returns true if the caller should retry the last operation.
86
bool should_retry() const;
89
*@returns true if the last operation was interrupted.
91
bool was_interrupted() const;
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.
100
bool peer_addr(char *buf, uint16_t *port, size_t buflen) const;
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.
107
void timeout(bool is_sndtimeo, int32_t timeout);
110
* Returns the last error code.
111
*@returns the last error code, as described in errno.h
113
int get_errno() const;
116
* Get the underlying descriptor this class is using.
117
*@returns The descriptor passed in to the constructor of this class.
122
* Returns the current read position.
124
char *get_read_pos() const;
127
* Returns the current write position.
129
char *get_read_end() const;
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 */
142
} /* namespace drizzle_plugin */
144
#endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */