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.11 by root, Sat Aug 3 02:11:27 2013 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];
38} ourdata; 40} ourdata;
39 41
42#if DESC_IS_PTR
43# define OURDATAPTR (*(ourdata **)&((vio)->desc))
44#else
45# define DESC_OFFSET 22
40#define OURDATAPTR (*((ourdata **)((vio)->desc + DESC_OFFSET))) 46# define OURDATAPTR (*((ourdata **)((vio)->desc + DESC_OFFSET)))
47#endif
41 48
42static int 49static xlen
43our_read (Vio *vio, xgptr p, int len) 50our_read (Vio *vio, xgptr p, xlen len)
44{ 51{
45 ourdata *our = OURDATAPTR; 52 ourdata *our = OURDATAPTR;
46 53
47 if (!our->bufcnt) 54 if (!our->bufcnt)
48 { 55 {
92 our->bufcnt -= len; 99 our->bufcnt -= len;
93 100
94 return len; 101 return len;
95} 102}
96 103
97static int 104static xlen
98our_write (Vio *vio, const xgptr p, int len) 105our_write (Vio *vio, cxgptr p, xlen len)
99{ 106{
100 char *ptr = (char *)p; 107 char *ptr = (char *)p;
101 my_bool dummy; 108 my_bool dummy;
102 109
103 vio->vioblocking (vio, 0, &dummy); 110 vio->vioblocking (vio, 0, &dummy);
165#endif 172#endif
166 173
167 SvREFCNT_dec (our->corohandle); 174 SvREFCNT_dec (our->corohandle);
168 SvREFCNT_dec (our->corohandle_sv); 175 SvREFCNT_dec (our->corohandle_sv);
169 176
177#if DESC_IS_PTR
178 vio->desc = our->old_desc;
179#endif
180
170 Safefree (our); 181 Safefree (our);
171 182
172 vio->read = vio_read; 183 vio->read = vio_read;
173 vio->write = vio_write; 184 vio->write = vio_write;
174 vio->vioclose = vio_close; 185 vio->vioclose = vio_close;
213 224
214 XPUSHs (use_ev ? &PL_sv_yes : &PL_sv_no); 225 XPUSHs (use_ev ? &PL_sv_yes : &PL_sv_no);
215} 226}
216 227
217void 228void
218_patch (IV sock, int fd, SV *corohandle_sv, SV *corohandle) 229_patch (IV sock, int fd, unsigned long client_version, SV *corohandle_sv, SV *corohandle)
219 CODE: 230 CODE:
220{ 231{
221 MYSQL *my = (MYSQL *)sock; 232 MYSQL *my = (MYSQL *)sock;
222 Vio *vio = my->net.vio; 233 Vio *vio = my->net.vio;
223 ourdata *our; 234 ourdata *our;
224 235
236 /* matching versions are required but not sufficient */
237 if (client_version != mysql_get_client_version ())
238 croak ("DBD::mysql linked against different libmysqlclient library than Coro::Mysql (%lu vs. %lu).",
239 client_version, mysql_get_client_version ());
240
225 if (fd != my->net.fd) 241 if (fd != my->net.fd)
226 croak ("DBD::mysql fd and libmysql disagree - library mismatch, unsupported transport or API changes?"); 242 croak ("DBD::mysql fd and libmysql disagree - library mismatch, unsupported transport or API changes?");
227 243
228 if (fd != vio->sd) 244 if (fd != vio->sd)
229 croak ("DBD::mysql fd and vio-sd disagree - library mismatch, unsupported transport or API changes?"); 245 croak ("DBD::mysql fd and vio-sd disagree - library mismatch, unsupported transport or API changes?");
230 246
231 if (vio->vioclose != vio_close) 247 if (vio->vioclose != vio_close)
232 croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?"); 248 croak ("vio.vioclose has unexpected content - library mismatch, unsupported transport or API changes?");
233 249
234 if (vio->write != vio_write) 250 if (vio->write != vio_write)
235 croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?"); 251 croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?");
236 252
237 if (vio->read != vio_read 253 if (vio->read != vio_read
247 { 263 {
248 ev_io_init (&(our->rw), iocb, vio->sd, EV_READ); 264 ev_io_init (&(our->rw), iocb, vio->sd, EV_READ);
249 ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE); 265 ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE);
250 } 266 }
251#endif 267#endif
252 268#if DESC_IS_PTR
269 our->old_desc = vio->desc;
270 strncpy (our->desc, vio->desc, sizeof (our->desc));
271 our->desc [sizeof (our->desc) - 1] = 0;
272#else
253 vio->desc [DESC_OFFSET - 1] = 0; 273 vio->desc [DESC_OFFSET - 1] = 0;
274#endif
254 OURDATAPTR = our; 275 OURDATAPTR = our;
255 276
256 vio->vioclose = our_close; 277 vio->vioclose = our_close;
257 vio->write = our_write; 278 vio->write = our_write;
258 vio->read = our_read; 279 vio->read = our_read;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines