Merge lp:~thomir-deactivatedaccount/drizzle/drizzle-struct-class-conversion into lp:drizzle/7.0

Proposed by Thomi Richards
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
Reviewer Review Type Date Requested Status
Thomi Richards (community) Needs Resubmitting
Drizzle Developers Pending
Review via email: mp+39575@code.launchpad.net

Description of the change

Changed the vio_st structure (found in plugins/mysql_protocol/vio.h) to a proper C++ class.

To post a comment you must log in.
Revision history for this message
Lee Bieber (kalebral-deactivatedaccount) wrote :

Build failures:

 CXX plugin/mysql_unix_socket_protocol/plugin_libmysql_unix_socket_protocol_plugin_la-protocol.lo
../plugin/mysql_protocol/vio.h: In function ‘uint32_t my_real_read(NET*, size_t*)’:
../plugin/mysql_protocol/vio.h:130: error: ‘int Vio::sd’ is private
../plugin/mysql_protocol/net_serv.cc:681: error: within this context
make[3]: *** [plugin/mysql_protocol/plugin_libmysql_protocol_plugin_la-net_serv.lo] Error 1

Revision history for this message
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/mysql_unix_socket_protocol
> /plugin_libmysql_unix_socket_protocol_plugin_la-protocol.lo
> ../plugin/mysql_protocol/vio.h: In function ‘uint32_t my_real_read(NET*,
> size_t*)’:
> ../plugin/mysql_protocol/vio.h:130: error: ‘int Vio::sd’ is private
> ../plugin/mysql_protocol/net_serv.cc:681: error: within this context
> make[3]: *** [plugin/mysql_protocol/plugin_libmysql_protocol_plugin_la-
> net_serv.lo] Error 1

review: Needs Information
Revision history for this message
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.

Revision history for this message
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.

review: Needs Resubmitting

Preview Diff

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

Subscribers

People subscribed via source and target branches