971.7.10
by Eric Day
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port. |
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
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
971.7.10
by Eric Day
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port. |
15 |
|
16 |
||
971.7.11
by Eric Day
Fixed header file guards and fixed test cases. |
17 |
#ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H
|
1337.4.1
by Eric Day
Removed unused functions and extra complexity in MySQL module. Not rewriting any code here (yet?), just reshuffling to make it easier to manage. |
18 |
#define PLUGIN_MYSQL_PROTOCOL_VIO_H
|
971.7.10
by Eric Day
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port. |
19 |
|
20 |
#include <sys/socket.h> |
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
21 |
#include <cerrno> |
22 |
||
23 |
namespace drizzle_plugin |
|
24 |
{
|
|
971.7.10
by Eric Day
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port. |
25 |
|
1878.6.1
by Thomi Richards
Converted the vio_st struct to the Vio class. |
26 |
/**
|
27 |
*@brief Virtual I/O layer, only used with TCP/IP sockets at the moment.
|
|
28 |
*/
|
|
29 |
class Vio |
|
971.7.10
by Eric Day
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port. |
30 |
{
|
1878.6.1
by Thomi Richards
Converted the vio_st struct to the Vio class. |
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: |
|
1337.4.1
by Eric Day
Removed unused functions and extra complexity in MySQL module. Not rewriting any code here (yet?), just reshuffling to make it easier to manage. |
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 */ |
|
971.7.10
by Eric Day
Duplicated oldlibdrizzle module, one for Drizzle protocol and one for MySQL, per Brian's request from merge proposal. Port options are now --drizzle-protocol-port and --mysql-protocol-port. |
139 |
|
140 |
};
|
|
141 |
||
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
142 |
} /* namespace drizzle_plugin */ |
1337.4.1
by Eric Day
Removed unused functions and extra complexity in MySQL module. Not rewriting any code here (yet?), just reshuffling to make it easier to manage. |
143 |
|
971.7.11
by Eric Day
Fixed header file guards and fixed test cases. |
144 |
#endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */ |