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
=== modified file 'plugin/mysql_protocol/mysql_protocol.cc'
--- plugin/mysql_protocol/mysql_protocol.cc 2010-10-27 18:03:49 +0000
+++ plugin/mysql_protocol/mysql_protocol.cc 2010-10-30 00:46:01 +0000
@@ -103,7 +103,7 @@
103ClientMySQLProtocol::~ClientMySQLProtocol()103ClientMySQLProtocol::~ClientMySQLProtocol()
104{104{
105 if (net.vio)105 if (net.vio)
106 vio_close(net.vio);106 net.vio->close();
107}107}
108108
109int ClientMySQLProtocol::getFileDescriptor(void)109int ClientMySQLProtocol::getFileDescriptor(void)
@@ -884,7 +884,7 @@
884 uint32_t pointer_seed;884 uint32_t pointer_seed;
885 memcpy(&pointer_seed, &pointer, 4);885 memcpy(&pointer_seed, &pointer, 4);
886 uint32_t random1= (seed + pointer_seed) % random_max;886 uint32_t random1= (seed + pointer_seed) % random_max;
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;
888888
889 for (char *end= scramble + SCRAMBLE_LENGTH; scramble != end; scramble++)889 for (char *end= scramble + SCRAMBLE_LENGTH; scramble != end; scramble++)
890 {890 {
891891
=== modified file 'plugin/mysql_protocol/net_serv.cc'
--- plugin/mysql_protocol/net_serv.cc 2010-10-27 06:36:38 +0000
+++ plugin/mysql_protocol/net_serv.cc 2010-10-30 00:46:01 +0000
@@ -82,15 +82,15 @@
8282
83 if (vio != 0) /* If real connection */83 if (vio != 0) /* If real connection */
84 {84 {
85 net->fd = vio_fd(vio); /* For perl DBI/DBD */85 net->fd = vio->get_fd(); /* For perl DBI/DBD */
86 vio_fastsend(vio);86 vio->fastsend();
87 }87 }
88 return(0);88 return(0);
89}89}
9090
91bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length)91bool drizzleclient_net_init_sock(NET * net, int sock, uint32_t buffer_length)
92{92{
93 Vio *vio_tmp= mysql_protocol_vio_new(sock);93 Vio *vio_tmp= new Vio(sock);
94 if (vio_tmp == NULL)94 if (vio_tmp == NULL)
95 return true;95 return true;
96 else96 else
@@ -100,7 +100,7 @@
100 * NET object.100 * NET object.
101 */101 */
102 if (vio_tmp && (net->vio != vio_tmp))102 if (vio_tmp && (net->vio != vio_tmp))
103 vio_delete(vio_tmp);103 delete vio_tmp;
104 else104 else
105 {105 {
106 (void) shutdown(sock, SHUT_RDWR);106 (void) shutdown(sock, SHUT_RDWR);
@@ -123,29 +123,29 @@
123{123{
124 if (net->vio != NULL)124 if (net->vio != NULL)
125 {125 {
126 vio_delete(net->vio);126 delete net->vio;
127 net->vio= 0;127 net->vio= 0;
128 }128 }
129}129}
130130
131bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)131bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
132{132{
133 return vio_peer_addr(net->vio, buf, port, buflen);133 return net->vio->peer_addr(buf, port, buflen);
134}134}
135135
136void drizzleclient_net_keepalive(NET *net, bool flag)136void drizzleclient_net_keepalive(NET *net, bool flag)
137{137{
138 vio_keepalive(net->vio, flag);138 net->vio->keepalive(flag);
139}139}
140140
141int drizzleclient_net_get_sd(NET *net)141int drizzleclient_net_get_sd(NET *net)
142{142{
143 return net->vio->sd;143 return net->vio->get_fd();
144}144}
145145
146bool drizzleclient_net_more_data(NET *net)146bool drizzleclient_net_more_data(NET *net)
147{147{
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());
149}149}
150150
151/** Realloc the packet buffer. */151/** Realloc the packet buffer. */
@@ -232,10 +232,10 @@
232{232{
233 if (clear_buffer)233 if (clear_buffer)
234 {234 {
235 while (net_data_is_ready(net->vio->sd) > 0)235 while (net_data_is_ready(net->vio->get_fd()) > 0)
236 {236 {
237 /* The socket is ready */237 /* The socket is ready */
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)
239 {239 {
240 net->error= 2;240 net->error= 2;
241 break;241 break;
@@ -527,7 +527,8 @@
527 while (pos != end)527 while (pos != end)
528 {528 {
529 assert(pos);529 assert(pos);
530 if ((long) (length= vio_write(net->vio, pos, (size_t) (end-pos))) <= 0)530 // TODO - see bug comment below - will we crash now?
531 if ((long) (length= net->vio->write( pos, (size_t) (end-pos))) <= 0)
531 {532 {
532 /*533 /*
533 * We could end up here with net->vio == NULL534 * We could end up here with net->vio == NULL
@@ -537,7 +538,7 @@
537 if (net->vio == NULL)538 if (net->vio == NULL)
538 break;539 break;
539 540
540 const bool interrupted= vio_should_retry(net->vio);541 const bool interrupted= net->vio->should_retry();
541 /*542 /*
542 If we read 0, or we were interrupted this means that543 If we read 0, or we were interrupted this means that
543 we need to switch to blocking mode and wait until the timeout544 we need to switch to blocking mode and wait until the timeout
@@ -547,9 +548,9 @@
547 {548 {
548 bool old_mode;549 bool old_mode;
549550
550 while (vio_blocking(net->vio, true, &old_mode) < 0)551 while (net->vio->blocking(true, &old_mode) < 0)
551 {552 {
552 if (vio_should_retry(net->vio) && retry_count++ < net->retry_count)553 if (net->vio->should_retry() && retry_count++ < net->retry_count)
553 continue;554 continue;
554 net->error= 2; /* Close socket */555 net->error= 2; /* Close socket */
555 net->last_errno= ER_NET_PACKET_TOO_LARGE;556 net->last_errno= ER_NET_PACKET_TOO_LARGE;
@@ -565,7 +566,7 @@
565 continue;566 continue;
566 }567 }
567568
568 if (vio_errno(net->vio) == EINTR)569 if (net->vio->get_errno() == EINTR)
569 {570 {
570 continue;571 continue;
571 }572 }
@@ -617,25 +618,25 @@
617 while (remain > 0)618 while (remain > 0)
618 {619 {
619 /* First read is done with non blocking mode */620 /* First read is done with non blocking mode */
620 if ((long) (length= vio_read(net->vio, pos, remain)) <= 0L)621 if ((long) (length= net->vio->read(pos, remain)) <= 0L)
621 {622 {
622 if (net->vio == NULL)623 if (net->vio == NULL)
623 goto end;624 goto end;
624625
625 const bool interrupted = vio_should_retry(net->vio);626 const bool interrupted = net->vio->should_retry();
626627
627 if (interrupted)628 if (interrupted)
628 { /* Probably in MIT threads */629 { /* Probably in MIT threads */
629 if (retry_count++ < net->retry_count)630 if (retry_count++ < net->retry_count)
630 continue;631 continue;
631 }632 }
632 if (vio_errno(net->vio) == EINTR)633 if (net->vio->get_errno() == EINTR)
633 {634 {
634 continue;635 continue;
635 }636 }
636 len= packet_error;637 len= packet_error;
637 net->error= 2; /* Close socket */638 net->error= 2; /* Close socket */
638 net->last_errno= (vio_was_interrupted(net->vio) ?639 net->last_errno= (net->vio->was_interrupted() ?
639 CR_NET_READ_INTERRUPTED :640 CR_NET_READ_INTERRUPTED :
640 CR_NET_READ_ERROR);641 CR_NET_READ_ERROR);
641 goto end;642 goto end;
@@ -677,7 +678,7 @@
677 /* Clear the buffer so libdrizzle doesn't keep retrying */678 /* Clear the buffer so libdrizzle doesn't keep retrying */
678 while (len > 0)679 while (len > 0)
679 {680 {
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));
681 assert((long)length > 0L);682 assert((long)length > 0L);
682 len-= length;683 len-= length;
683 }684 }
@@ -870,7 +871,7 @@
870 net->read_timeout= timeout;871 net->read_timeout= timeout;
871#ifndef __sun872#ifndef __sun
872 if (net->vio)873 if (net->vio)
873 vio_timeout(net->vio, 0, timeout);874 net->vio->timeout(0, timeout);
874#endif875#endif
875 return;876 return;
876}877}
@@ -881,7 +882,7 @@
881 net->write_timeout= timeout;882 net->write_timeout= timeout;
882#ifndef __sun883#ifndef __sun
883 if (net->vio)884 if (net->vio)
884 vio_timeout(net->vio, 1, timeout);885 net->vio->timeout(1, timeout);
885#endif886#endif
886 return;887 return;
887}888}
888889
=== modified file 'plugin/mysql_protocol/vio.cc'
--- plugin/mysql_protocol/vio.cc 2010-10-28 01:51:45 +0000
+++ plugin/mysql_protocol/vio.cc 2010-10-30 00:46:01 +0000
@@ -19,7 +19,6 @@
19 we are working on. In this case we should just return read errors from19 we are working on. In this case we should just return read errors from
20 the file descriptior.20 the file descriptior.
21*/21*/
22
23#include "config.h"22#include "config.h"
24#include "vio.h"23#include "vio.h"
25#include <string.h>24#include <string.h>
@@ -41,61 +40,97 @@
4140
42using namespace std;41using namespace std;
4342
44static void _vio_delete(Vio* vio)43Vio::Vio(int nsd)
45{44: closed(false),
46 if (!vio)45sd(nsd),
47 return; /* It must be safe to delete null pointers. */46fcntl_mode(0),
4847read_pos(NULL),
49 if (!vio->closed)48read_end(NULL)
50 vio->vioclose(vio);49{
51 free((unsigned char*) vio);50 closed= false;
52}51 sd= nsd;
5352
54static int _vio_errno(Vio *vio)53 /*
55{54 We call fcntl() to set the flags and then immediately read them back
56 (void)vio;55 to make sure that we and the system are in agreement on the state of
57 return errno;56 things.
58}57
5958 An example of why we need to do this is FreeBSD (and apparently some
60static 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
60 reports that the socket is set for non-blocking when it really will
61 block.
62 */
63 fcntl(sd, F_SETFL, 0);
64 fcntl_mode= fcntl(sd, F_GETFL);
65
66 memset(&local, 0, sizeof(local));
67 memset(&remote, 0, sizeof(remote));
68}
69
70Vio::~Vio()
71{
72 if (!closed)
73 close();
74}
75
76int Vio::close()
77{
78 int r=0;
79 if (!closed)
80 {
81 assert(sd >= 0);
82 if (shutdown(sd, SHUT_RDWR))
83 r= -1;
84 if (::close(sd))
85 r= -1;
86 }
87 closed= true;
88 sd= -1;
89
90 return r;
91}
92
93size_t Vio::read(unsigned char* buf, size_t size)
61{94{
62 size_t r;95 size_t r;
6396
64 /* Ensure nobody uses vio_read_buff and vio_read simultaneously */97 /* Ensure nobody uses vio_read_buff and vio_read simultaneously */
65 assert(vio->read_end == vio->read_pos);98 assert(read_end == read_pos);
66 r= read(vio->sd, buf, size);99 r= ::read(sd, buf, size);
67100
68 return r;101 return r;
69}102}
70103
71static size_t _vio_write(Vio * vio, const unsigned char* buf, size_t size)104size_t Vio::write(const unsigned char* buf, size_t size)
72{105{
73 size_t r;106 size_t r;
74107
75 r = write(vio->sd, buf, size);108 r = ::write(sd, buf, size);
76109
77 return r;110 return r;
78}111}
79112
80static int _vio_blocking(Vio * vio, bool set_blocking_mode, bool *old_mode)113int Vio::blocking(bool set_blocking_mode, bool *old_mode)
81{114{
82 int r=0;115 int r=0;
83116
84 *old_mode= drizzled::test(!(vio->fcntl_mode & O_NONBLOCK));117 // make sure ptr is not NULL:
118 if (NULL != old_mode)
119 *old_mode= drizzled::test(!(fcntl_mode & O_NONBLOCK));
85120
86 if (vio->sd >= 0)121 if (sd >= 0)
87 {122 {
88 int old_fcntl=vio->fcntl_mode;123 int old_fcntl=fcntl_mode;
89 if (set_blocking_mode)124 if (set_blocking_mode)
90 vio->fcntl_mode &= ~O_NONBLOCK; /* clear bit */125 fcntl_mode &= ~O_NONBLOCK; /* clear bit */
91 else126 else
92 vio->fcntl_mode |= O_NONBLOCK; /* set bit */127 fcntl_mode |= O_NONBLOCK; /* set bit */
93 if (old_fcntl != vio->fcntl_mode)128 if (old_fcntl != fcntl_mode)
94 {129 {
95 r= fcntl(vio->sd, F_SETFL, vio->fcntl_mode);130 r= fcntl(sd, F_SETFL, fcntl_mode);
96 if (r == -1)131 if (r == -1)
97 {132 {
98 vio->fcntl_mode= old_fcntl;133 fcntl_mode= old_fcntl;
99 }134 }
100 }135 }
101 }136 }
@@ -103,13 +138,12 @@
103 return r;138 return r;
104}139}
105140
106static int _vio_fastsend(Vio * vio)141int Vio::fastsend()
107{142{
108 (void)vio;
109 int nodelay = 1;143 int nodelay = 1;
110 int error;144 int error;
111145
112 error= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,146 error= setsockopt(sd, IPPROTO_TCP, TCP_NODELAY,
113 &nodelay, sizeof(nodelay));147 &nodelay, sizeof(nodelay));
114 if (error != 0)148 if (error != 0)
115 {149 {
@@ -119,7 +153,7 @@
119 return error;153 return error;
120}154}
121155
122static int32_t _vio_keepalive(Vio* vio, bool set_keep_alive)156int32_t Vio::keepalive(bool set_keep_alive)
123{157{
124 int r= 0;158 int r= 0;
125 uint32_t opt= 0;159 uint32_t opt= 0;
@@ -127,7 +161,7 @@
127 if (set_keep_alive)161 if (set_keep_alive)
128 opt= 1;162 opt= 1;
129163
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));
131 if (r != 0)165 if (r != 0)
132 {166 {
133 perror("setsockopt");167 perror("setsockopt");
@@ -137,54 +171,34 @@
137 return r;171 return r;
138}172}
139173
140static bool _vio_should_retry(Vio * vio)174bool Vio::should_retry() const
141{175{
142 (void)vio;
143 int en = errno;176 int en = errno;
144 return (en == EAGAIN || en == EINTR ||177 return (en == EAGAIN || en == EINTR ||
145 en == EWOULDBLOCK);178 en == EWOULDBLOCK);
146}179}
147180
148static bool _vio_was_interrupted(Vio *vio)181bool Vio::was_interrupted() const
149{182{
150 (void)vio;
151 int en= errno;183 int en= errno;
152 return (en == EAGAIN || en == EINTR ||184 return (en == EAGAIN || en == EINTR ||
153 en == EWOULDBLOCK || en == ETIMEDOUT);185 en == EWOULDBLOCK || en == ETIMEDOUT);
154}186}
155187
156static int _vio_close(Vio * vio)188bool Vio::peer_addr(char *buf, uint16_t *port, size_t buflen) const
157{
158 int r=0;
159 if (!vio->closed)
160 {
161 assert(vio->sd >= 0);
162 if (shutdown(vio->sd, SHUT_RDWR))
163 r= -1;
164 if (close(vio->sd))
165 r= -1;
166 }
167 vio->closed= true;
168 vio->sd= -1;
169
170 return r;
171}
172
173static bool _vio_peer_addr(Vio *vio, char *buf, uint16_t *port, size_t buflen)
174{189{
175 int error;190 int error;
176 char port_buf[NI_MAXSERV];191 char port_buf[NI_MAXSERV];
177 socklen_t addrLen = sizeof(vio->remote);192 socklen_t al = sizeof(remote);
178193
179 if (getpeername(vio->sd, (struct sockaddr *) (&vio->remote),194 if (getpeername(sd, (struct sockaddr *) (&remote),
180 &addrLen) != 0)195 &al) != 0)
181 {196 {
182 return true;197 return true;
183 }198 }
184 vio->addrLen= (int)addrLen;
185199
186 if ((error= getnameinfo((struct sockaddr *)(&vio->remote),200 if ((error= getnameinfo((struct sockaddr *)(&remote),
187 addrLen,201 al,
188 buf, buflen,202 buf, buflen,
189 port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV)))203 port_buf, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV)))
190 {204 {
@@ -196,18 +210,18 @@
196 return false;210 return false;
197}211}
198212
199static void _vio_timeout(Vio *vio, bool is_sndtimeo, int32_t timeout)213void Vio::timeout(bool is_sndtimeo, int32_t t)
200{214{
201 int error;215 int error;
202216
203 /* POSIX specifies time as struct timeval. */217 /* POSIX specifies time as struct timeval. */
204 struct timeval wait_timeout;218 struct timeval wait_timeout;
205 wait_timeout.tv_sec= timeout;219 wait_timeout.tv_sec= t;
206 wait_timeout.tv_usec= 0;220 wait_timeout.tv_usec= 0;
207221
208 assert(timeout >= 0 && timeout <= INT32_MAX);222 assert(t >= 0 && t <= INT32_MAX);
209 assert(vio->sd != -1);223 assert(sd != -1);
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,
211 &wait_timeout,225 &wait_timeout,
212 (socklen_t)sizeof(struct timeval));226 (socklen_t)sizeof(struct timeval));
213 if (error == -1 && errno != ENOPROTOOPT)227 if (error == -1 && errno != ENOPROTOOPT)
@@ -217,41 +231,24 @@
217 }231 }
218}232}
219233
220/* Open the socket or TCP/IP connection and read the fnctl() status */234int Vio::get_errno() const
221Vio *mysql_protocol_vio_new(int sd)235{
222{236 return errno;
223 Vio *vio = (Vio*) malloc(sizeof(Vio));237}
224 if (vio == NULL)238
225 return NULL;239int Vio::get_fd() const
226240{
227 memset(vio, 0, sizeof(*vio));241 return sd;
228 vio->closed= false;242}
229 vio->sd= sd;243
230 vio->viodelete= _vio_delete;244
231 vio->vioerrno= _vio_errno;245char *Vio::get_read_pos() const
232 vio->read= _vio_read;246{
233 vio->write= _vio_write;247 return read_pos;
234 vio->fastsend= _vio_fastsend;248}
235 vio->viokeepalive= _vio_keepalive;249
236 vio->should_retry= _vio_should_retry;250char *Vio::get_read_end() const
237 vio->was_interrupted= _vio_was_interrupted;251{
238 vio->vioclose= _vio_close;252 return read_end;
239 vio->peer_addr= _vio_peer_addr;253}
240 vio->vioblocking= _vio_blocking;254
241 vio->timeout= _vio_timeout;
242
243 /*
244 We call fcntl() to set the flags and then immediately read them back
245 to make sure that we and the system are in agreement on the state of
246 things.
247
248 An example of why we need to do this is FreeBSD (and apparently some
249 other BSD-derived systems, like Mac OS X), where the system sometimes
250 reports that the socket is set for non-blocking when it really will
251 block.
252 */
253 fcntl(sd, F_SETFL, 0);
254 vio->fcntl_mode= fcntl(sd, F_GETFL);
255
256 return vio;
257}
258255
=== modified file 'plugin/mysql_protocol/vio.h'
--- plugin/mysql_protocol/vio.h 2010-10-02 21:15:42 +0000
+++ plugin/mysql_protocol/vio.h 2010-10-30 00:46:01 +0000
@@ -13,9 +13,6 @@
13 along with this program; if not, write to the Free Software13 along with this program; if not, write to the Free Software
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 */
1515
16/*
17 * Virtual I/O layer, only used with TCP/IP sockets at the moment.
18 */
1916
20#ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H17#ifndef PLUGIN_MYSQL_PROTOCOL_VIO_H
21#define PLUGIN_MYSQL_PROTOCOL_VIO_H18#define PLUGIN_MYSQL_PROTOCOL_VIO_H
@@ -23,49 +20,121 @@
23#include <sys/socket.h>20#include <sys/socket.h>
24#include <errno.h>21#include <errno.h>
2522
26typedef struct st_vio Vio;23/**
2724 *@brief Virtual I/O layer, only used with TCP/IP sockets at the moment.
28struct st_vio25 */
26class Vio
29{27{
28public:
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
128private:
30 bool closed;129 bool closed;
31 int sd;130 int sd;
32 int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */131 int fcntl_mode; /* Buffered fcntl(sd,F_GETFL) */
33 struct sockaddr_storage local; /* Local internet address */132 struct sockaddr_storage local; /* Local internet address */
34 struct sockaddr_storage remote; /* Remote internet address */133 struct sockaddr_storage remote; /* Remote internet address */
35 int addrLen; /* Length of remote address */
36 char *read_pos; /* start of unfetched data in the read buffer */134 char *read_pos; /* start of unfetched data in the read buffer */
37 char *read_end; /* end of unfetched data */135 char *read_end; /* end of unfetched data */
38136
39 /* function pointers. They are similar for socket/SSL/whatever */
40 void (*viodelete)(Vio*);
41 int32_t (*vioerrno)(Vio*);
42 size_t (*read)(Vio*, unsigned char *, size_t);
43 size_t (*write)(Vio*, const unsigned char *, size_t);
44 int32_t (*vioblocking)(Vio*, bool, bool *);
45 int32_t (*viokeepalive)(Vio*, bool);
46 int32_t (*fastsend)(Vio*);
47 bool (*peer_addr)(Vio*, char *, uint16_t *, size_t);
48 void (*in_addr)(Vio*, struct sockaddr_storage*);
49 bool (*should_retry)(Vio*);
50 bool (*was_interrupted)(Vio*);
51 int32_t (*vioclose)(Vio*);
52 void (*timeout)(Vio*, bool is_sndtimeo, int32_t timeout);
53};137};
54138
55Vio* mysql_protocol_vio_new(int sd);
56
57#define vio_fd(vio) (vio)->sd
58#define vio_delete(vio) (vio)->viodelete(vio)
59#define vio_errno(vio) (vio)->vioerrno(vio)
60#define vio_read(vio, buf, size) ((vio)->read)(vio,buf,size)
61#define vio_write(vio, buf, size) ((vio)->write)(vio, buf, size)
62#define vio_blocking(vio, set_blocking_mode, old_mode) (vio)->vioblocking(vio, set_blocking_mode, old_mode)
63#define vio_fastsend(vio) (vio)->fastsend(vio)
64#define vio_keepalive(vio, set_keep_alive) (vio)->viokeepalive(vio, set_keep_alive)
65#define vio_should_retry(vio) (vio)->should_retry(vio)
66#define vio_was_interrupted(vio) (vio)->was_interrupted(vio)
67#define vio_close(vio) ((vio)->vioclose)(vio)
68#define vio_peer_addr(vio, buf, prt, buflen) (vio)->peer_addr(vio, buf, prt, buflen)
69#define vio_timeout(vio, which, seconds) (vio)->timeout(vio, which, seconds)
70139
71#endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */140#endif /* PLUGIN_MYSQL_PROTOCOL_VIO_H */

Subscribers

People subscribed via source and target branches