ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro-Mysql/Mysql.xs
(Generate patch)

Comparing Coro-Mysql/Mysql.xs (file contents):
Revision 1.7 by root, Thu Feb 17 02:05:15 2011 UTC vs.
Revision 1.15 by root, Tue Jun 3 13:38:48 2014 UTC

1#include <sys/errno.h> 1#include <errno.h>
2#include <unistd.h> 2#include <unistd.h>
3#include <fcntl.h> 3#include <fcntl.h>
4 4
5#include <mysql.h> 5#include <mysql.h>
6 6
21static CV *readable, *writable; 21static CV *readable, *writable;
22static int use_ev; 22static int use_ev;
23 23
24#include "violite.h" 24#include "violite.h"
25 25
26#define DESC_OFFSET 22
27
28#define CoMy_MAGIC 0x436f4d79 26#define CoMy_MAGIC 0x436f4d79
29 27
30typedef struct { 28typedef struct {
29#if DESC_IS_PTR
30 char desc[30];
31 const char *old_desc;
32#endif
31 int magic; 33 int magic;
32 SV *corohandle_sv, *corohandle; 34 SV *corohandle_sv, *corohandle;
33 int bufofs, bufcnt; 35 int bufofs, bufcnt;
34#if HAVE_EV 36#if HAVE_EV
35 ev_io rw, ww; 37 ev_io rw, ww;
36#endif 38#endif
37 char buf[VIO_READ_BUFFER_SIZE]; 39 char buf[VIO_READ_BUFFER_SIZE];
40 size_t (*old_read)(Vio*, uchar *, size_t);
41 size_t (*old_write)(Vio*, const uchar *, size_t);
42 int (*old_vioclose)(Vio*);
38} ourdata; 43} ourdata;
39 44
45#if DESC_IS_PTR
46# define OURDATAPTR (*(ourdata **)&((vio)->desc))
47#else
48# define DESC_OFFSET 22
40#define OURDATAPTR (*((ourdata **)((vio)->desc + DESC_OFFSET))) 49# define OURDATAPTR (*((ourdata **)((vio)->desc + DESC_OFFSET)))
50#endif
41 51
42static int 52static xlen
43our_read (Vio *vio, xgptr p, int len) 53our_read (Vio *vio, xgptr p, xlen len)
44{ 54{
45 ourdata *our = OURDATAPTR; 55 ourdata *our = OURDATAPTR;
46 56
47 if (!our->bufcnt) 57 if (!our->bufcnt)
48 { 58 {
92 our->bufcnt -= len; 102 our->bufcnt -= len;
93 103
94 return len; 104 return len;
95} 105}
96 106
97static int 107static xlen
98our_write (Vio *vio, const xgptr p, int len) 108our_write (Vio *vio, cxgptr p, xlen len)
99{ 109{
100 char *ptr = (char *)p; 110 char *ptr = (char *)p;
101 my_bool dummy; 111 my_bool dummy;
102 112
103 vio->vioblocking (vio, 0, &dummy); 113 vio->vioblocking (vio, 0, &dummy);
165#endif 175#endif
166 176
167 SvREFCNT_dec (our->corohandle); 177 SvREFCNT_dec (our->corohandle);
168 SvREFCNT_dec (our->corohandle_sv); 178 SvREFCNT_dec (our->corohandle_sv);
169 179
180#if DESC_IS_PTR
181 vio->desc = our->old_desc;
182#endif
183
184 vio->vioclose = our->old_vioclose;
185 vio->write = our->old_write;
186 vio->read = our->old_read;
187
170 Safefree (our); 188 Safefree (our);
171
172 vio->read = vio_read;
173 vio->write = vio_write;
174 vio->vioclose = vio_close;
175 189
176 vio->vioclose (vio); 190 vio->vioclose (vio);
177} 191}
178 192
179#if HAVE_EV 193#if HAVE_EV
213 227
214 XPUSHs (use_ev ? &PL_sv_yes : &PL_sv_no); 228 XPUSHs (use_ev ? &PL_sv_yes : &PL_sv_no);
215} 229}
216 230
217void 231void
218_patch (IV sock, int fd, SV *corohandle_sv, SV *corohandle) 232_patch (IV sock, int fd, unsigned long client_version, SV *corohandle_sv, SV *corohandle)
219 CODE: 233 CODE:
220{ 234{
221 MYSQL *my = (MYSQL *)sock; 235 MYSQL *my = (MYSQL *)sock;
222 Vio *vio = my->net.vio; 236 Vio *vio = my->net.vio;
223 ourdata *our; 237 ourdata *our;
224 238
239 /* matching versions are required but not sufficient */
240 if (client_version != mysql_get_client_version ())
241 croak ("DBD::mysql linked against different libmysqlclient library than Coro::Mysql (%lu vs. %lu).",
242 client_version, mysql_get_client_version ());
243
225 if (fd != my->net.fd) 244 if (fd != my->net.fd)
226 croak ("DBD::mysql fd and libmysql disagree - library mismatch, unsupported transport or API changes?"); 245 croak ("DBD::mysql fd and libmysql disagree - library mismatch, unsupported transport or API changes?");
227 246
228 if (fd != vio->sd) 247 if (fd != vio->sd)
229 croak ("DBD::mysql fd and vio-sd disagree - library mismatch, unsupported transport or API changes?"); 248 croak ("DBD::mysql fd and vio-sd disagree - library mismatch, unsupported transport or API changes?");
230 249#if MYSQL_VERSION_ID < 100010 && !defined(MARIADB_BASE_VERSION)
231 if (vio->vioclose != vio_close) 250 if (vio->vioclose != vio_close)
232 croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?"); 251 croak ("vio.vioclose has unexpected content - library mismatch, unsupported transport or API changes?");
233 252
234 if (vio->write != vio_write) 253 if (vio->write != vio_write)
235 croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?"); 254 croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?");
236 255
237 if (vio->read != vio_read 256 if (vio->read != vio_read
238 && vio->read != vio_read_buff) 257 && vio->read != vio_read_buff)
239 croak ("vio.read has unexpected content - library mismatch, unsupported transport or API changes?"); 258 croak ("vio.read has unexpected content - library mismatch, unsupported transport or API changes?");
259#endif
240 260
241 Newz (0, our, 1, ourdata); 261 Newz (0, our, 1, ourdata);
242 our->magic = CoMy_MAGIC; 262 our->magic = CoMy_MAGIC;
243 our->corohandle_sv = newSVsv (corohandle_sv); 263 our->corohandle_sv = newSVsv (corohandle_sv);
244 our->corohandle = newSVsv (corohandle); 264 our->corohandle = newSVsv (corohandle);
247 { 267 {
248 ev_io_init (&(our->rw), iocb, vio->sd, EV_READ); 268 ev_io_init (&(our->rw), iocb, vio->sd, EV_READ);
249 ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE); 269 ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE);
250 } 270 }
251#endif 271#endif
252 272#if DESC_IS_PTR
273 our->old_desc = vio->desc;
274 strncpy (our->desc, vio->desc, sizeof (our->desc));
275 our->desc [sizeof (our->desc) - 1] = 0;
276#else
253 vio->desc [DESC_OFFSET - 1] = 0; 277 vio->desc [DESC_OFFSET - 1] = 0;
278#endif
254 OURDATAPTR = our; 279 OURDATAPTR = our;
280
281 our->old_vioclose = vio->vioclose;
282 our->old_write = vio->write;
283 our->old_read = vio->read;
255 284
256 vio->vioclose = our_close; 285 vio->vioclose = our_close;
257 vio->write = our_write; 286 vio->write = our_write;
258 vio->read = our_read; 287 vio->read = our_read;
259} 288}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines