Merge lp:~thomir-deactivatedaccount/drizzle/drizzle-struct-class-conversion into lp:drizzle/7.0
- drizzle-struct-class-conversion
- Merge into 7.0
Status: | Merged |
---|---|
Approved by: | Lee Bieber |
Approved revision: | 1880 |
Merged at revision: | 1894 |
Proposed branch: | lp:~thomir-deactivatedaccount/drizzle/drizzle-struct-class-conversion |
Merge into: | lp:drizzle/7.0 |
Diff against target: |
695 lines (+239/-172) 4 files modified
plugin/mysql_protocol/mysql_protocol.cc (+2/-2) plugin/mysql_protocol/net_serv.cc (+24/-23) plugin/mysql_protocol/vio.cc (+108/-111) plugin/mysql_protocol/vio.h (+105/-36) |
To merge this branch: | bzr merge lp:~thomir-deactivatedaccount/drizzle/drizzle-struct-class-conversion |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Thomi Richards (community) | Needs Resubmitting | ||
Drizzle Developers | Pending | ||
Review via email: mp+39575@code.launchpad.net |
Commit message
Description of the change
Changed the vio_st structure (found in plugins/
Lee Bieber (kalebral-deactivatedaccount) wrote : | # |
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
> Build failures:
This confuses me somewhat, for several reasons:
First, I made sure that my branch built (and worked) before submitting it. Second, I can't find the problem.
I did have to change code in net_serv.cc from accessing the 'sd' member directly - it should now call Vio::get_fd() instead. However, in trunk (rev 1878) I can't find anywhere in 'my_real_read' that attempts to access the member variable in question.
Is it possible that somehow the changes in my branch aren't being applied correctly? Or have I missed something? I'm new to bzr & launchpad, so maybe I've overlooked something obvious...
> CXX plugin/
> /plugin_
> ../plugin/
> size_t*)’:
> ../plugin/
> ../plugin/
> make[3]: *** [plugin/
> net_serv.lo] Error 1
Andrew Hutchings (linuxjedi) wrote : | # |
Hi Thomi,
Can you please merge trunk into your branch and re-commit/push? This is due to some changes I made to vio in the last few days that are in trunk which when merged with yours cause this.
Thomi Richards (thomir-deactivatedaccount) wrote : | # |
> Hi Thomi,
>
> Can you please merge trunk into your branch and re-commit/push? This is due
> to some changes I made to vio in the last few days that are in trunk which
> when merged with yours cause this.
Done. Hopefully it should work now. Let me know if there are still problems.
Cheers.
Preview Diff
1 | === modified file 'plugin/mysql_protocol/mysql_protocol.cc' | |||
2 | --- plugin/mysql_protocol/mysql_protocol.cc 2010-10-27 18:03:49 +0000 | |||
3 | +++ plugin/mysql_protocol/mysql_protocol.cc 2010-10-30 00:46:01 +0000 | |||
4 | @@ -103,7 +103,7 @@ | |||
5 | 103 | ClientMySQLProtocol::~ClientMySQLProtocol() | 103 | ClientMySQLProtocol::~ClientMySQLProtocol() |
6 | 104 | { | 104 | { |
7 | 105 | if (net.vio) | 105 | if (net.vio) |
9 | 106 | vio_close(net.vio); | 106 | net.vio->close(); |
10 | 107 | } | 107 | } |
11 | 108 | 108 | ||
12 | 109 | int ClientMySQLProtocol::getFileDescriptor(void) | 109 | int ClientMySQLProtocol::getFileDescriptor(void) |
13 | @@ -884,7 +884,7 @@ | |||
14 | 884 | uint32_t pointer_seed; | 884 | uint32_t pointer_seed; |
15 | 885 | memcpy(&pointer_seed, &pointer, 4); | 885 | memcpy(&pointer_seed, &pointer, 4); |
16 | 886 | uint32_t random1= (seed + pointer_seed) % random_max; | 886 | uint32_t random1= (seed + pointer_seed) % random_max; |
18 | 887 | uint32_t random2= (seed + session->variables.pseudo_thread_id + net.vio->sd) % random_max; | 887 | uint32_t random2= (seed + session->variables.pseudo_thread_id + net.vio->get_fd()) % random_max; |
19 | 888 | 888 | ||
20 | 889 | for (char *end= scramble + SCRAMBLE_LENGTH; scramble != end; scramble++) | 889 | for (char *end= scramble + SCRAMBLE_LENGTH; scramble != end; scramble++) |
21 | 890 | { | 890 | { |
22 | 891 | 891 | ||
23 | === modified file 'plugin/mysql_protocol/net_serv.cc' | |||
24 | --- plugin/mysql_protocol/net_serv.cc 2010-10-27 06:36:38 +0000 | |||
25 | +++ plugin/mysql_protocol/net_serv.cc 2010-10-30 00:46:01 +0000 | |||
26 | @@ -82,15 +82,15 @@ | |||
27 | 82 | 82 | ||
28 | 83 | if (vio != 0) /* If real connection */ | 83 | if (vio != 0) /* If real connection */ |
29 | 84 | { | 84 | { |
32 | 85 | net->fd = vio_fd(vio); /* For perl DBI/DBD */ | 85 | net->fd = vio->get_fd(); /* For perl DBI/DBD */ |
33 | 86 | vio_fastsend(vio); | 86 | vio->fastsend(); |
34 | 87 | } | 87 | } |
35 | 88 | return(0); | 88 | return(0); |
36 | 89 | } | 89 | } |
37 | 90 | 90 | ||
38 | 91 | bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length) | 91 | bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length) |
39 | 92 | { | 92 | { |
41 | 93 | Vio *vio_tmp= mysql_protocol_vio_new(sock); | 93 | Vio *vio_tmp= new Vio(sock); |
42 | 94 | if (vio_tmp == NULL) | 94 | if (vio_tmp == NULL) |
43 | 95 | return true; | 95 | return true; |
44 | 96 | else | 96 | else |
45 | @@ -100,7 +100,7 @@ | |||
46 | 100 | * NET object. | 100 | * NET object. |
47 | 101 | */ | 101 | */ |
48 | 102 | if (vio_tmp && (net->vio != vio_tmp)) | 102 | if (vio_tmp && (net->vio != vio_tmp)) |
50 | 103 | vio_delete(vio_tmp); | 103 | delete vio_tmp; |
51 | 104 | else | 104 | else |
52 | 105 | { | 105 | { |
53 | 106 | (void) shutdown(sock, SHUT_RDWR); | 106 | (void) shutdown(sock, SHUT_RDWR); |
54 | @@ -123,29 +123,29 @@ | |||
55 | 123 | { | 123 | { |
56 | 124 | if (net->vio != NULL) | 124 | if (net->vio != NULL) |
57 | 125 | { | 125 | { |
59 | 126 | vio_delete(net->vio); | 126 | delete net->vio; |
60 | 127 | net->vio= 0; | 127 | net->vio= 0; |
61 | 128 | } | 128 | } |
62 | 129 | } | 129 | } |
63 | 130 | 130 | ||
64 | 131 | bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen) | 131 | bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen) |
65 | 132 | { | 132 | { |
67 | 133 | return vio_peer_addr(net->vio, buf, port, buflen); | 133 | return net->vio->peer_addr(buf, port, buflen); |
68 | 134 | } | 134 | } |
69 | 135 | 135 | ||
70 | 136 | void drizzleclient_net_keepalive(NET *net, bool flag) | 136 | void drizzleclient_net_keepalive(NET *net, bool flag) |
71 | 137 | { | 137 | { |
73 | 138 | vio_keepalive(net->vio, flag); | 138 | net->vio->keepalive(flag); |
74 | 139 | } | 139 | } |
75 | 140 | 140 | ||
76 | 141 | int drizzleclient_net_get_sd(NET *net) | 141 | int drizzleclient_net_get_sd(NET *net) |
77 | 142 | { | 142 | { |
79 | 143 | return net->vio->sd; | 143 | return net->vio->get_fd(); |
80 | 144 | } | 144 | } |
81 | 145 | 145 | ||
82 | 146 | bool drizzleclient_net_more_data(NET *net) | 146 | bool drizzleclient_net_more_data(NET *net) |
83 | 147 | { | 147 | { |
85 | 148 | return (net->vio == 0 || net->vio->read_pos < net->vio->read_end); | 148 | return (net->vio == 0 || net->vio->get_read_pos() < net->vio->get_read_end()); |
86 | 149 | } | 149 | } |
87 | 150 | 150 | ||
88 | 151 | /** Realloc the packet buffer. */ | 151 | /** Realloc the packet buffer. */ |
89 | @@ -232,10 +232,10 @@ | |||
90 | 232 | { | 232 | { |
91 | 233 | if (clear_buffer) | 233 | if (clear_buffer) |
92 | 234 | { | 234 | { |
94 | 235 | while (net_data_is_ready(net->vio->sd) > 0) | 235 | while (net_data_is_ready(net->vio->get_fd()) > 0) |
95 | 236 | { | 236 | { |
96 | 237 | /* The socket is ready */ | 237 | /* The socket is ready */ |
98 | 238 | if (vio_read(net->vio, net->buff, (size_t) net->max_packet) <= 0) | 238 | if (net->vio->read(net->buff, (size_t) net->max_packet) <= 0) |
99 | 239 | { | 239 | { |
100 | 240 | net->error= 2; | 240 | net->error= 2; |
101 | 241 | break; | 241 | break; |
102 | @@ -527,7 +527,8 @@ | |||
103 | 527 | while (pos != end) | 527 | while (pos != end) |
104 | 528 | { | 528 | { |
105 | 529 | assert(pos); | 529 | assert(pos); |
107 | 530 | if ((long) (length= vio_write(net->vio, pos, (size_t) (end-pos))) <= 0) | 530 | // TODO - see bug comment below - will we crash now? |
108 | 531 | if ((long) (length= net->vio->write( pos, (size_t) (end-pos))) <= 0) | ||
109 | 531 | { | 532 | { |
110 | 532 | /* | 533 | /* |
111 | 533 | * We could end up here with net->vio == NULL | 534 | * We could end up here with net->vio == NULL |
112 | @@ -537,7 +538,7 @@ | |||
113 | 537 | if (net->vio == NULL) | 538 | if (net->vio == NULL) |
114 | 538 | break; | 539 | break; |
115 | 539 | 540 | ||
117 | 540 | const bool interrupted= vio_should_retry(net->vio); | 541 | const bool interrupted= net->vio->should_retry(); |
118 | 541 | /* | 542 | /* |
119 | 542 | If we read 0, or we were interrupted this means that | 543 | If we read 0, or we were interrupted this means that |
120 | 543 | we need to switch to blocking mode and wait until the timeout | 544 | we need to switch to blocking mode and wait until the timeout |
121 | @@ -547,9 +548,9 @@ | |||
122 | 547 | { | 548 | { |
123 | 548 | bool old_mode; | 549 | bool old_mode; |
124 | 549 | 550 | ||
126 | 550 | while (vio_blocking(net->vio, true, &old_mode) < 0) | 551 | while (net->vio->blocking(true, &old_mode) < 0) |
127 | 551 | { | 552 | { |
129 | 552 | if (vio_should_retry(net->vio) && retry_count++ < net->retry_count) | 553 | if (net->vio->should_retry() && retry_count++ < net->retry_count) |
130 | 553 | continue; | 554 | continue; |
131 | 554 | net->error= 2; /* Close socket */ | 555 | net->error= 2; /* Close socket */ |
132 | 555 | net->last_errno= ER_NET_PACKET_TOO_LARGE; | 556 | net->last_errno= ER_NET_PACKET_TOO_LARGE; |
133 | @@ -565,7 +566,7 @@ | |||
134 | 565 | continue; | 566 | continue; |
135 | 566 | } | 567 | } |
136 | 567 | 568 | ||
138 | 568 | if (vio_errno(net->vio) == EINTR) | 569 | if (net->vio->get_errno() == EINTR) |
139 | 569 | { | 570 | { |
140 | 570 | continue; | 571 | continue; |
141 | 571 | } | 572 | } |
142 | @@ -617,25 +618,25 @@ | |||
143 | 617 | while (remain > 0) | 618 | while (remain > 0) |
144 | 618 | { | 619 | { |
145 | 619 | /* First read is done with non blocking mode */ | 620 | /* First read is done with non blocking mode */ |
147 | 620 | if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L) | 621 | if ((long) (length= net->vio->read(pos, remain)) <= 0L) |
148 | 621 | { | 622 | { |
149 | 622 | if (net->vio == NULL) | 623 | if (net->vio == NULL) |
150 | 623 | goto end; | 624 | goto end; |
151 | 624 | 625 | ||
153 | 625 | const bool interrupted = vio_should_retry(net->vio); | 626 | const bool interrupted = net->vio->should_retry(); |
154 | 626 | 627 | ||
155 | 627 | if (interrupted) | 628 | if (interrupted) |
156 | 628 | { /* Probably in MIT threads */ | 629 | { /* Probably in MIT threads */ |
157 | 629 | if (retry_count++ < net->retry_count) | 630 | if (retry_count++ < net->retry_count) |
158 | 630 | continue; | 631 | continue; |
159 | 631 | } | 632 | } |
161 | 632 | if (vio_errno(net->vio) == EINTR) | 633 | if (net->vio->get_errno() == EINTR) |
162 | 633 | { | 634 | { |
163 | 634 | continue; | 635 | continue; |
164 | 635 | } | 636 | } |
165 | 636 | len= packet_error; | 637 | len= packet_error; |
166 | 637 | net->error= 2; /* Close socket */ | 638 | net->error= 2; /* Close socket */ |
168 | 638 | net->last_errno= (vio_was_interrupted(net->vio) ? | 639 | net->last_errno= (net->vio->was_interrupted() ? |
169 | 639 | CR_NET_READ_INTERRUPTED : | 640 | CR_NET_READ_INTERRUPTED : |
170 | 640 | CR_NET_READ_ERROR); | 641 | CR_NET_READ_ERROR); |
171 | 641 | goto end; | 642 | goto end; |
172 | @@ -677,7 +678,7 @@ | |||
173 | 677 | /* Clear the buffer so libdrizzle doesn't keep retrying */ | 678 | /* Clear the buffer so libdrizzle doesn't keep retrying */ |
174 | 678 | while (len > 0) | 679 | while (len > 0) |
175 | 679 | { | 680 | { |
177 | 680 | length= read(net->vio->sd, net->buff, min((size_t)net->max_packet, len)); | 681 | length= read(net->vio->get_fd(), net->buff, min((size_t)net->max_packet, len)); |
178 | 681 | assert((long)length > 0L); | 682 | assert((long)length > 0L); |
179 | 682 | len-= length; | 683 | len-= length; |
180 | 683 | } | 684 | } |
181 | @@ -870,7 +871,7 @@ | |||
182 | 870 | net->read_timeout= timeout; | 871 | net->read_timeout= timeout; |
183 | 871 | #ifndef __sun | 872 | #ifndef __sun |
184 | 872 | if (net->vio) | 873 | if (net->vio) |
186 | 873 | vio_timeout(net->vio, 0, timeout); | 874 | net->vio->timeout(0, timeout); |
187 | 874 | #endif | 875 | #endif |
188 | 875 | return; | 876 | return; |
189 | 876 | } | 877 | } |
190 | @@ -881,7 +882,7 @@ | |||
191 | 881 | net->write_timeout= timeout; | 882 | net->write_timeout= timeout; |
192 | 882 | #ifndef __sun | 883 | #ifndef __sun |
193 | 883 | if (net->vio) | 884 | if (net->vio) |
195 | 884 | vio_timeout(net->vio, 1, timeout); | 885 | net->vio->timeout(1, timeout); |
196 | 885 | #endif | 886 | #endif |
197 | 886 | return; | 887 | return; |
198 | 887 | } | 888 | } |
199 | 888 | 889 | ||
200 | === modified file 'plugin/mysql_protocol/vio.cc' | |||
201 | --- plugin/mysql_protocol/vio.cc 2010-10-28 01:51:45 +0000 | |||
202 | +++ plugin/mysql_protocol/vio.cc 2010-10-30 00:46:01 +0000 | |||
203 | @@ -19,7 +19,6 @@ | |||
204 | 19 | we are working on. In this case we should just return read errors from | 19 | we are working on. In this case we should just return read errors from |
205 | 20 | the file descriptior. | 20 | the file descriptior. |
206 | 21 | */ | 21 | */ |
207 | 22 | |||
208 | 23 | #include "config.h" | 22 | #include "config.h" |
209 | 24 | #include "vio.h" | 23 | #include "vio.h" |
210 | 25 | #include <string.h> | 24 | #include <string.h> |
211 | @@ -41,61 +40,97 @@ | |||
212 | 41 | 40 | ||
213 | 42 | using namespace std; | 41 | using namespace std; |
214 | 43 | 42 | ||
232 | 44 | static void _vio_delete(Vio* vio) | 43 | Vio::Vio(int nsd) |
233 | 45 | { | 44 | : closed(false), |
234 | 46 | if (!vio) | 45 | sd(nsd), |
235 | 47 | return; /* It must be safe to delete null pointers. */ | 46 | fcntl_mode(0), |
236 | 48 | 47 | read_pos(NULL), | |
237 | 49 | if (!vio->closed) | 48 | read_end(NULL) |
238 | 50 | vio->vioclose(vio); | 49 | { |
239 | 51 | free((unsigned char*) vio); | 50 | closed= false; |
240 | 52 | } | 51 | sd= nsd; |
241 | 53 | 52 | ||
242 | 54 | static int _vio_errno(Vio *vio) | 53 | /* |
243 | 55 | { | 54 | We call fcntl() to set the flags and then immediately read them back |
244 | 56 | (void)vio; | 55 | to make sure that we and the system are in agreement on the state of |
245 | 57 | return errno; | 56 | things. |
246 | 58 | } | 57 | |
247 | 59 | 58 | An example of why we need to do this is FreeBSD (and apparently some | |
248 | 60 | static size_t _vio_read(Vio * vio, unsigned char* buf, size_t size) | 59 | other BSD-derived systems, like Mac OS X), where the system sometimes |
249 | 60 | reports that the socket is set for non-blocking when it really will | ||
250 | 61 | block. | ||
251 | 62 | */ | ||
252 | 63 | fcntl(sd, F_SETFL, 0); | ||
253 | 64 | fcntl_mode= fcntl(sd, F_GETFL); | ||
254 | 65 | |||
255 | 66 | memset(&local, 0, sizeof(local)); | ||
256 | 67 | memset(&remote, 0, sizeof(remote)); | ||
257 | 68 | } | ||
258 | 69 | |||
259 | 70 | Vio::~Vio() | ||
260 | 71 | { | ||
261 | 72 | if (!closed) | ||
262 | 73 | close(); | ||
263 | 74 | } | ||
264 | 75 | |||
265 | 76 | int Vio::close() | ||
266 | 77 | { | ||
267 | 78 | int r=0; | ||
268 | 79 | if (!closed) | ||
269 | 80 | { | ||
270 | 81 | assert(sd >= 0); | ||
271 | 82 | if (shutdown(sd, SHUT_RDWR)) | ||
272 | 83 | r= -1; | ||
273 | 84 | if (::close(sd)) | ||
274 | 85 | r= -1; | ||
275 | 86 | } | ||
276 | 87 | closed= true; | ||
277 | 88 | sd= -1; | ||
278 | 89 | |||
279 | 90 | return r; | ||
280 | 91 | } | ||
281 | 92 | |||
282 | 93 | size_t Vio::read(unsigned char* buf, size_t size) | ||
283 | 61 | { | 94 | { |
284 | 62 | size_t r; | 95 | size_t r; |
285 | 63 | 96 | ||
286 | 64 | /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ | 97 | /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ |
289 | 65 | assert(vio->read_end == vio->read_pos); | 98 | assert(read_end == read_pos); |
290 | 66 | r= read(vio->sd, buf, size); | 99 | r= ::read(sd, buf, size); |
291 | 67 | 100 | ||
292 | 68 | return r; | 101 | return r; |
293 | 69 | } | 102 | } |
294 | 70 | 103 | ||
296 | 71 | static size_t _vio_write(Vio * vio, const unsigned char* buf, size_t size) | 104 | size_t Vio::write(const unsigned char* buf, size_t size) |
297 | 72 | { | 105 | { |
298 | 73 | size_t r; | 106 | size_t r; |
299 | 74 | 107 | ||
301 | 75 | r = write(vio->sd, buf, size); | 108 | r = ::write(sd, buf, size); |
302 | 76 | 109 | ||
303 | 77 | return r; | 110 | return r; |
304 | 78 | } | 111 | } |
305 | 79 | 112 | ||
307 | 80 | static int _vio_blocking(Vio * vio, bool set_blocking_mode, bool *old_mode) | 113 | int Vio::blocking(bool set_blocking_mode, bool *old_mode) |
308 | 81 | { | 114 | { |
309 | 82 | int r=0; | 115 | int r=0; |
310 | 83 | 116 | ||
312 | 84 | *old_mode= drizzled::test(!(vio->fcntl_mode & O_NONBLOCK)); | 117 | // make sure ptr is not NULL: |
313 | 118 | if (NULL != old_mode) | ||
314 | 119 | *old_mode= drizzled::test(!(fcntl_mode & O_NONBLOCK)); | ||
315 | 85 | 120 | ||
317 | 86 | if (vio->sd >= 0) | 121 | if (sd >= 0) |
318 | 87 | { | 122 | { |
320 | 88 | int old_fcntl=vio->fcntl_mode; | 123 | int old_fcntl=fcntl_mode; |
321 | 89 | if (set_blocking_mode) | 124 | if (set_blocking_mode) |
323 | 90 | vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */ | 125 | fcntl_mode &= ~O_NONBLOCK; /* clear bit */ |
324 | 91 | else | 126 | else |
327 | 92 | vio->fcntl_mode |= O_NONBLOCK; /* set bit */ | 127 | fcntl_mode |= O_NONBLOCK; /* set bit */ |
328 | 93 | if (old_fcntl != vio->fcntl_mode) | 128 | if (old_fcntl != fcntl_mode) |
329 | 94 | { | 129 | { |
331 | 95 | r= fcntl(vio->sd, F_SETFL, vio->fcntl_mode); | 130 | r= fcntl(sd, F_SETFL, fcntl_mode); |
332 | 96 | if (r == -1) | 131 | if (r == -1) |
333 | 97 | { | 132 | { |
335 | 98 | vio->fcntl_mode= old_fcntl; | 133 | fcntl_mode= old_fcntl; |
336 | 99 | } | 134 | } |
337 | 100 | } | 135 | } |
338 | 101 | } | 136 | } |
339 | @@ -103,13 +138,12 @@ | |||
340 | 103 | return r; | 138 | return r; |
341 | 104 | } | 139 | } |
342 | 105 | 140 | ||
344 | 106 | static int _vio_fastsend(Vio * vio) | 141 | int Vio::fastsend() |
345 | 107 | { | 142 | { |
346 | 108 | (void)vio; | ||
347 | 109 | int nodelay = 1; | 143 | int nodelay = 1; |
348 | 110 | int error; | 144 | int error; |
349 | 111 | 145 | ||
351 | 112 | error= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY, | 146 | error= setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, |
352 | 113 | &nodelay, sizeof(nodelay)); | 147 | &nodelay, sizeof(nodelay)); |
353 | 114 | if (error != 0) | 148 | if (error != 0) |
354 | 115 | { | 149 | { |
355 | @@ -119,7 +153,7 @@ | |||
356 | 119 | return error; | 153 | return error; |
357 | 120 | } | 154 | } |
358 | 121 | 155 | ||
360 | 122 | static int32_t _vio_keepalive(Vio* vio, bool set_keep_alive) | 156 | int32_t Vio::keepalive(bool set_keep_alive) |
361 | 123 | { | 157 | { |
362 | 124 | int r= 0; | 158 | int r= 0; |
363 | 125 | uint32_t opt= 0; | 159 | uint32_t opt= 0; |
364 | @@ -127,7 +161,7 @@ | |||
365 | 127 | if (set_keep_alive) | 161 | if (set_keep_alive) |
366 | 128 | opt= 1; | 162 | opt= 1; |
367 | 129 | 163 | ||
369 | 130 | r= setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, sizeof(opt)); | 164 | r= setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt, sizeof(opt)); |
370 | 131 | if (r != 0) | 165 | if (r != 0) |
371 | 132 | { | 166 | { |
372 | 133 | perror("setsockopt"); | 167 | perror("setsockopt"); |
373 | @@ -137,54 +171,34 @@ | |||
374 | 137 | return r; | 171 | return r; |
375 | 138 | } | 172 | } |
376 | 139 | 173 | ||
378 | 140 | static bool _vio_should_retry(Vio * vio) | 174 | bool Vio::should_retry() const |
379 | 141 | { | 175 | { |
380 | 142 | (void)vio; | ||
381 | 143 | int en = errno; | 176 | int en = errno; |
382 | 144 | return (en == EAGAIN || en == EINTR || | 177 | return (en == EAGAIN || en == EINTR || |
384 | 145 | en == EWOULDBLOCK); | 178 | en == EWOULDBLOCK); |
385 | 146 | } | 179 | } |
386 | 147 | 180 | ||
388 | 148 | static bool _vio_was_interrupted(Vio *vio) | 181 | bool Vio::was_interrupted() const |
389 | 149 | { | 182 | { |
390 | 150 | (void)vio; | ||
391 | 151 | int en= errno; | 183 | int en= errno; |
392 | 152 | return (en == EAGAIN || en == EINTR || | 184 | return (en == EAGAIN || en == EINTR || |
414 | 153 | en == EWOULDBLOCK || en == ETIMEDOUT); | 185 | en == EWOULDBLOCK || en == ETIMEDOUT); |
415 | 154 | } | 186 | } |
416 | 155 | 187 | ||
417 | 156 | static int _vio_close(Vio * vio) | 188 | bool Vio::peer_addr(char *buf, uint16_t *port, size_t buflen) const |
397 | 157 | { | ||
398 | 158 | int r=0; | ||
399 | 159 | if (!vio->closed) | ||
400 | 160 | { | ||
401 | 161 | assert(vio->sd >= 0); | ||
402 | 162 | if (shutdown(vio->sd, SHUT_RDWR)) | ||
403 | 163 | r= -1; | ||
404 | 164 | if (close(vio->sd)) | ||
405 | 165 | r= -1; | ||
406 | 166 | } | ||
407 | 167 | vio->closed= true; | ||
408 | 168 | vio->sd= -1; | ||
409 | 169 | |||
410 | 170 | return r; | ||
411 | 171 | } | ||
412 | 172 | |||
413 | 173 | static bool _vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen) | ||
418 | 174 | { | 189 | { |
419 | 175 | int error; | 190 | int error; |
420 | 176 | char port_buf[NI_MAXSERV]; | 191 | char port_buf[NI_MAXSERV]; |
422 | 177 | socklen_t addrLen = sizeof(vio->remote); | 192 | socklen_t al = sizeof(remote); |
423 | 178 | 193 | ||
426 | 179 | if (getpeername(vio->sd, (struct sockaddr *) (&vio->remote), | 194 | if (getpeername(sd, (struct sockaddr *) (&remote), |
427 | 180 | &addrLen) != 0) | 195 | &al) != 0) |
428 | 181 | { | 196 | { |
429 | 182 | return true; | 197 | return true; |
430 | 183 | } | 198 | } |
431 | 184 | vio->addrLen= (int)addrLen; | ||
432 | 185 | 199 | ||
435 | 186 | if ((error= getnameinfo((struct sockaddr *)(&vio->remote), | 200 | if ((error= getnameinfo((struct sockaddr *)(&remote), |
436 | 187 | addrLen, | 201 | al, |
437 | 188 | buf, buflen, | 202 | buf, buflen, |
438 | 189 | port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV))) | 203 | port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV))) |
439 | 190 | { | 204 | { |
440 | @@ -196,18 +210,18 @@ | |||
441 | 196 | return false; | 210 | return false; |
442 | 197 | } | 211 | } |
443 | 198 | 212 | ||
445 | 199 | static void _vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout) | 213 | void Vio::timeout(bool is_sndtimeo, int32_t t) |
446 | 200 | { | 214 | { |
447 | 201 | int error; | 215 | int error; |
448 | 202 | 216 | ||
449 | 203 | /* POSIX specifies time as struct timeval. */ | 217 | /* POSIX specifies time as struct timeval. */ |
450 | 204 | struct timeval wait_timeout; | 218 | struct timeval wait_timeout; |
452 | 205 | wait_timeout.tv_sec= timeout; | 219 | wait_timeout.tv_sec= t; |
453 | 206 | wait_timeout.tv_usec= 0; | 220 | wait_timeout.tv_usec= 0; |
454 | 207 | 221 | ||
458 | 208 | assert(timeout >= 0 && timeout <= INT32_MAX); | 222 | assert(t >= 0 && t <= INT32_MAX); |
459 | 209 | assert(vio->sd != -1); | 223 | assert(sd != -1); |
460 | 210 | error= setsockopt(vio->sd, SOL_SOCKET, is_sndtimeo ? SO_SNDTIMEO : SO_RCVTIMEO, | 224 | error= setsockopt(sd, SOL_SOCKET, is_sndtimeo ? SO_SNDTIMEO : SO_RCVTIMEO, |
461 | 211 | &wait_timeout, | 225 | &wait_timeout, |
462 | 212 | (socklen_t)sizeof(struct timeval)); | 226 | (socklen_t)sizeof(struct timeval)); |
463 | 213 | if (error == -1 && errno != ENOPROTOOPT) | 227 | if (error == -1 && errno != ENOPROTOOPT) |
464 | @@ -217,41 +231,24 @@ | |||
465 | 217 | } | 231 | } |
466 | 218 | } | 232 | } |
467 | 219 | 233 | ||
506 | 220 | /* Open the socket or TCP/IP connection and read the fnctl() status */ | 234 | int Vio::get_errno() const |
507 | 221 | Vio *mysql_protocol_vio_new(int sd) | 235 | { |
508 | 222 | { | 236 | return errno; |
509 | 223 | Vio *vio = (Vio*) malloc(sizeof(Vio)); | 237 | } |
510 | 224 | if (vio == NULL) | 238 | |
511 | 225 | return NULL; | 239 | int Vio::get_fd() const |
512 | 226 | 240 | { | |
513 | 227 | memset(vio, 0, sizeof(*vio)); | 241 | return sd; |
514 | 228 | vio->closed= false; | 242 | } |
515 | 229 | vio->sd= sd; | 243 | |
516 | 230 | vio->viodelete= _vio_delete; | 244 | |
517 | 231 | vio->vioerrno= _vio_errno; | 245 | char *Vio::get_read_pos() const |
518 | 232 | vio->read= _vio_read; | 246 | { |
519 | 233 | vio->write= _vio_write; | 247 | return read_pos; |
520 | 234 | vio->fastsend= _vio_fastsend; | 248 | } |
521 | 235 | vio->viokeepalive= _vio_keepalive; | 249 | |
522 | 236 | vio->should_retry= _vio_should_retry; | 250 | char *Vio::get_read_end() const |
523 | 237 | vio->was_interrupted= _vio_was_interrupted; | 251 | { |
524 | 238 | vio->vioclose= _vio_close; | 252 | return read_end; |
525 | 239 | vio->peer_addr= _vio_peer_addr; | 253 | } |
526 | 240 | vio->vioblocking= _vio_blocking; | 254 | |
489 | 241 | vio->timeout= _vio_timeout; | ||
490 | 242 | |||
491 | 243 | /* | ||
492 | 244 | We call fcntl() to set the flags and then immediately read them back | ||
493 | 245 | to make sure that we and the system are in agreement on the state of | ||
494 | 246 | things. | ||
495 | 247 | |||
496 | 248 | An example of why we need to do this is FreeBSD (and apparently some | ||
497 | 249 | other BSD-derived systems, like Mac OS X), where the system sometimes | ||
498 | 250 | reports that the socket is set for non-blocking when it really will | ||
499 | 251 | block. | ||
500 | 252 | */ | ||
501 | 253 | fcntl(sd, F_SETFL, 0); | ||
502 | 254 | vio->fcntl_mode= fcntl(sd, F_GETFL); | ||
503 | 255 | |||
504 | 256 | return vio; | ||
505 | 257 | } | ||
527 | 258 | 255 | ||
528 | === modified file 'plugin/mysql_protocol/vio.h' | |||
529 | --- plugin/mysql_protocol/vio.h 2010-10-02 21:15:42 +0000 | |||
530 | +++ plugin/mysql_protocol/vio.h 2010-10-30 00:46:01 +0000 | |||
531 | @@ -13,9 +13,6 @@ | |||
532 | 13 | along with this program; if not, write to the Free Software | 13 | along with this program; if not, write to the Free Software |
533 | 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
534 | 15 | 15 | ||
535 | 16 | /* | ||
536 | 17 | * Virtual I/O layer, only used with TCP/IP sockets at the moment. | ||
537 | 18 | */ | ||
538 | 19 | 16 | ||
539 | 20 | #ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H | 17 | #ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H |
540 | 21 | #define PLUGIN_MYSQL_PROTOCOL_VIO_H | 18 | #define PLUGIN_MYSQL_PROTOCOL_VIO_H |
541 | @@ -23,49 +20,121 @@ | |||
542 | 23 | #include <sys/socket.h> | 20 | #include <sys/socket.h> |
543 | 24 | #include <errno.h> | 21 | #include <errno.h> |
544 | 25 | 22 | ||
548 | 26 | typedef struct st_vio Vio; | 23 | /** |
549 | 27 | 24 | *@brief Virtual I/O layer, only used with TCP/IP sockets at the moment. | |
550 | 28 | struct st_vio | 25 | */ |
551 | 26 | class Vio | ||
552 | 29 | { | 27 | { |
553 | 28 | public: | ||
554 | 29 | /** | ||
555 | 30 | * Constructor. | ||
556 | 31 | * @param[in] sd Descriptor to use. | ||
557 | 32 | */ | ||
558 | 33 | Vio(int sd); | ||
559 | 34 | ~Vio(); | ||
560 | 35 | |||
561 | 36 | /** | ||
562 | 37 | *Close the connection. | ||
563 | 38 | *@returns 0 on success. | ||
564 | 39 | */ | ||
565 | 40 | int close(); | ||
566 | 41 | |||
567 | 42 | /** | ||
568 | 43 | * Read some data from the remote end. | ||
569 | 44 | *@param[out] buf A buffer to write the new data to. | ||
570 | 45 | *@param[in] size The size of the buffer | ||
571 | 46 | *@returns The number of bytes read. | ||
572 | 47 | */ | ||
573 | 48 | size_t read(unsigned char* buf, size_t size); | ||
574 | 49 | |||
575 | 50 | /** | ||
576 | 51 | * Write some data to the remote end. | ||
577 | 52 | *@param[in] buf A buffer that contains the data to send. | ||
578 | 53 | *@param[in] size The size of the buffer | ||
579 | 54 | *@returns The number of bytes written. | ||
580 | 55 | */ | ||
581 | 56 | size_t write(const unsigned char* buf, size_t size); | ||
582 | 57 | |||
583 | 58 | /** | ||
584 | 59 | * Set device blocking mode. | ||
585 | 60 | *@param[in] set_blocking_mode Whether the device should block. true sets blocking mode, false clears it. | ||
586 | 61 | *@param[out] old_mode This will be set to the previous blocking mode. | ||
587 | 62 | *@returns 0 on success. | ||
588 | 63 | */ | ||
589 | 64 | int blocking(bool set_blocking_mode, bool *old_mode); | ||
590 | 65 | |||
591 | 66 | /** | ||
592 | 67 | * Enables fast sending. | ||
593 | 68 | * Setting this sets the TCP_NODELAY socket option. | ||
594 | 69 | *@returns 0 on succcess. | ||
595 | 70 | */ | ||
596 | 71 | int fastsend(); | ||
597 | 72 | |||
598 | 73 | /** | ||
599 | 74 | * Sets or clears the keepalive option. | ||
600 | 75 | *@param[in] set_keep_alive Whether to set or clear the flag. True Sets keepalive, false clears it. | ||
601 | 76 | *@returns 0 on success. | ||
602 | 77 | */ | ||
603 | 78 | int32_t keepalive(bool set_keep_alive); | ||
604 | 79 | |||
605 | 80 | /** | ||
606 | 81 | *@returns true if the caller should retry the last operation. | ||
607 | 82 | */ | ||
608 | 83 | bool should_retry() const; | ||
609 | 84 | |||
610 | 85 | /** | ||
611 | 86 | *@returns true if the last operation was interrupted. | ||
612 | 87 | */ | ||
613 | 88 | bool was_interrupted() const; | ||
614 | 89 | |||
615 | 90 | /** | ||
616 | 91 | *Gets the address details of the peer. | ||
617 | 92 | @param[out] buf Buffer that will recieve the peer address. | ||
618 | 93 | @param[out] port Port of remote end. | ||
619 | 94 | @param[in] buflen Size of buf. | ||
620 | 95 | @returns True on success, false otherwise. | ||
621 | 96 | */ | ||
622 | 97 | bool peer_addr(char *buf, uint16_t *port, size_t buflen) const; | ||
623 | 98 | |||
624 | 99 | /** | ||
625 | 100 | * Sets either the send, or recieve timeouts for the socket. | ||
626 | 101 | *@param[in] is_sndtimeo Set to true to change the send timeout, false to change the recieve timeout. | ||
627 | 102 | *@param[in] timeout The new timeout to set, in seconds. | ||
628 | 103 | */ | ||
629 | 104 | void timeout(bool is_sndtimeo, int32_t timeout); | ||
630 | 105 | |||
631 | 106 | /** | ||
632 | 107 | * Returns the last error code. | ||
633 | 108 | *@returns the last error code, as described in errno.h | ||
634 | 109 | */ | ||
635 | 110 | int get_errno() const; | ||
636 | 111 | |||
637 | 112 | /** | ||
638 | 113 | * Get the underlying descriptor this class is using. | ||
639 | 114 | *@returns The descriptor passed in to the constructor of this class. | ||
640 | 115 | */ | ||
641 | 116 | int get_fd() const; | ||
642 | 117 | |||
643 | 118 | /** | ||
644 | 119 | * Returns the current read position. | ||
645 | 120 | */ | ||
646 | 121 | char *get_read_pos() const; | ||
647 | 122 | |||
648 | 123 | /** | ||
649 | 124 | * Returns the current write position. | ||
650 | 125 | */ | ||
651 | 126 | char *get_read_end() const; | ||
652 | 127 | |||
653 | 128 | private: | ||
654 | 30 | bool closed; | 129 | bool closed; |
655 | 31 | int sd; | 130 | int sd; |
656 | 32 | int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ | 131 | int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */ |
657 | 33 | struct sockaddr_storage local; /* Local internet address */ | 132 | struct sockaddr_storage local; /* Local internet address */ |
658 | 34 | struct sockaddr_storage remote; /* Remote internet address */ | 133 | struct sockaddr_storage remote; /* Remote internet address */ |
659 | 35 | int addrLen; /* Length of remote address */ | ||
660 | 36 | char *read_pos; /* start of unfetched data in the read buffer */ | 134 | char *read_pos; /* start of unfetched data in the read buffer */ |
661 | 37 | char *read_end; /* end of unfetched data */ | 135 | char *read_end; /* end of unfetched data */ |
662 | 38 | 136 | ||
663 | 39 | /* function pointers. They are similar for socket/SSL/whatever */ | ||
664 | 40 | void (*viodelete)(Vio*); | ||
665 | 41 | int32_t (*vioerrno)(Vio*); | ||
666 | 42 | size_t (*read)(Vio*, unsigned char *, size_t); | ||
667 | 43 | size_t (*write)(Vio*, const unsigned char *, size_t); | ||
668 | 44 | int32_t (*vioblocking)(Vio*, bool, bool *); | ||
669 | 45 | int32_t (*viokeepalive)(Vio*, bool); | ||
670 | 46 | int32_t (*fastsend)(Vio*); | ||
671 | 47 | bool (*peer_addr)(Vio*, char *, uint16_t *, size_t); | ||
672 | 48 | void (*in_addr)(Vio*, struct sockaddr_storage*); | ||
673 | 49 | bool (*should_retry)(Vio*); | ||
674 | 50 | bool (*was_interrupted)(Vio*); | ||
675 | 51 | int32_t (*vioclose)(Vio*); | ||
676 | 52 | void (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout); | ||
677 | 53 | }; | 137 | }; |
678 | 54 | 138 | ||
679 | 55 | Vio* mysql_protocol_vio_new(int sd); | ||
680 | 56 | |||
681 | 57 | #define vio_fd(vio) (vio)->sd | ||
682 | 58 | #define vio_delete(vio) (vio)->viodelete(vio) | ||
683 | 59 | #define vio_errno(vio) (vio)->vioerrno(vio) | ||
684 | 60 | #define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size) | ||
685 | 61 | #define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size) | ||
686 | 62 | #define vio_blocking(vio, set_blocking_mode, old_mode) (vio)->vioblocking(vio, set_blocking_mode, old_mode) | ||
687 | 63 | #define vio_fastsend(vio) (vio)->fastsend(vio) | ||
688 | 64 | #define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive) | ||
689 | 65 | #define vio_should_retry(vio) (vio)->should_retry(vio) | ||
690 | 66 | #define vio_was_interrupted(vio) (vio)->was_interrupted(vio) | ||
691 | 67 | #define vio_close(vio) ((vio)->vioclose)(vio) | ||
692 | 68 | #define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen) | ||
693 | 69 | #define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds) | ||
694 | 70 | 139 | ||
695 | 71 | #endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */ | 140 | #endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */ |
Build failures:
CXX plugin/ mysql_unix_ socket_ protocol/ plugin_ libmysql_ unix_socket_ protocol_ plugin_ la-protocol. lo mysql_protocol/ vio.h: In function ‘uint32_t my_real_read(NET*, size_t*)’: mysql_protocol/ vio.h:130: error: ‘int Vio::sd’ is private mysql_protocol/ net_serv. cc:681: error: within this context mysql_protocol/ plugin_ libmysql_ protocol_ plugin_ la-net_ serv.lo] Error 1
../plugin/
../plugin/
../plugin/
make[3]: *** [plugin/