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> |
|
21 |
#include <errno.h> |
|
22 |
||
1878.6.1
by Thomi Richards
Converted the vio_st struct to the Vio class. |
23 |
/**
|
24 |
*@brief Virtual I/O layer, only used with TCP/IP sockets at the moment.
|
|
25 |
*/
|
|
26 |
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. |
27 |
{
|
1878.6.1
by Thomi Richards
Converted the vio_st struct to the Vio class. |
28 |
public: |
29 |
/**
|
|
30 |
* Constructor.
|
|
31 |
* @param[in] sd Descriptor to use.
|
|
32 |
*/
|
|
33 |
Vio(int sd); |
|
34 |
~Vio(); |
|
35 |
||
36 |
/**
|
|
37 |
*Close the connection.
|
|
38 |
*@returns 0 on success.
|
|
39 |
*/
|
|
40 |
int close(); |
|
41 |
||
42 |
/**
|
|
43 |
* Read some data from the remote end.
|
|
44 |
*@param[out] buf A buffer to write the new data to.
|
|
45 |
*@param[in] size The size of the buffer
|
|
46 |
*@returns The number of bytes read.
|
|
47 |
*/
|
|
48 |
size_t read(unsigned char* buf, size_t size); |
|
49 |
||
50 |
/**
|
|
51 |
* Write some data to the remote end.
|
|
52 |
*@param[in] buf A buffer that contains the data to send.
|
|
53 |
*@param[in] size The size of the buffer
|
|
54 |
*@returns The number of bytes written.
|
|
55 |
*/
|
|
56 |
size_t write(const unsigned char* buf, size_t size); |
|
57 |
||
58 |
/**
|
|
59 |
* Set device blocking mode.
|
|
60 |
*@param[in] set_blocking_mode Whether the device should block. true sets blocking mode, false clears it.
|
|
61 |
*@param[out] old_mode This will be set to the previous blocking mode.
|
|
62 |
*@returns 0 on success.
|
|
63 |
*/
|
|
64 |
int blocking(bool set_blocking_mode, bool *old_mode); |
|
65 |
||
66 |
/**
|
|
67 |
* Enables fast sending.
|
|
68 |
* Setting this sets the TCP_NODELAY socket option.
|
|
69 |
*@returns 0 on succcess.
|
|
70 |
*/
|
|
71 |
int fastsend(); |
|
72 |
||
73 |
/**
|
|
74 |
* Sets or clears the keepalive option.
|
|
75 |
*@param[in] set_keep_alive Whether to set or clear the flag. True Sets keepalive, false clears it.
|
|
76 |
*@returns 0 on success.
|
|
77 |
*/
|
|
78 |
int32_t keepalive(bool set_keep_alive); |
|
79 |
||
80 |
/**
|
|
81 |
*@returns true if the caller should retry the last operation.
|
|
82 |
*/
|
|
83 |
bool should_retry() const; |
|
84 |
||
85 |
/**
|
|
86 |
*@returns true if the last operation was interrupted.
|
|
87 |
*/
|
|
88 |
bool was_interrupted() const; |
|
89 |
||
90 |
/**
|
|
91 |
*Gets the address details of the peer.
|
|
92 |
@param[out] buf Buffer that will recieve the peer address.
|
|
93 |
@param[out] port Port of remote end.
|
|
94 |
@param[in] buflen Size of buf.
|
|
95 |
@returns True on success, false otherwise.
|
|
96 |
*/
|
|
97 |
bool peer_addr(char *buf, uint16_t *port, size_t buflen) const; |
|
98 |
||
99 |
/**
|
|
100 |
* Sets either the send, or recieve timeouts for the socket.
|
|
101 |
*@param[in] is_sndtimeo Set to true to change the send timeout, false to change the recieve timeout.
|
|
102 |
*@param[in] timeout The new timeout to set, in seconds.
|
|
103 |
*/
|
|
104 |
void timeout(bool is_sndtimeo, int32_t timeout); |
|
105 |
||
106 |
/**
|
|
107 |
* Returns the last error code.
|
|
108 |
*@returns the last error code, as described in errno.h
|
|
109 |
*/
|
|
110 |
int get_errno() const; |
|
111 |
||
112 |
/**
|
|
113 |
* Get the underlying descriptor this class is using.
|
|
114 |
*@returns The descriptor passed in to the constructor of this class.
|
|
115 |
*/
|
|
116 |
int get_fd() const; |
|
117 |
||
118 |
/**
|
|
119 |
* Returns the current read position.
|
|
120 |
*/
|
|
121 |
char *get_read_pos() const; |
|
122 |
||
123 |
/**
|
|
124 |
* Returns the current write position.
|
|
125 |
*/
|
|
126 |
char *get_read_end() const; |
|
127 |
||
128 |
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. |
129 |
bool closed; |
130 |
int sd; |
|
131 |
int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
|
132 |
struct sockaddr_storage local; /* Local internet address */ |
|
133 |
struct sockaddr_storage remote; /* Remote internet address */ |
|
134 |
char *read_pos; /* start of unfetched data in the read buffer */ |
|
135 |
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. |
136 |
|
137 |
};
|
|
138 |
||
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. |
139 |
|
971.7.11
by Eric Day
Fixed header file guards and fixed test cases. |
140 |
#endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */ |