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 | |
… | |
… | |
21 | static CV *readable, *writable; |
21 | static CV *readable, *writable; |
22 | static int use_ev; |
22 | static 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 | |
30 | typedef struct { |
28 | typedef 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 | |
42 | static xlen |
52 | static xlen |
43 | our_read (Vio *vio, xgptr p, xlen len) |
53 | our_read (Vio *vio, xgptr p, xlen len) |
44 | { |
54 | { |
45 | ourdata *our = OURDATAPTR; |
55 | ourdata *our = OURDATAPTR; |
… | |
… | |
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 |
… | |
… | |
230 | if (fd != my->net.fd) |
244 | if (fd != my->net.fd) |
231 | 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?"); |
232 | |
246 | |
233 | if (fd != vio->sd) |
247 | if (fd != vio->sd) |
234 | 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?"); |
235 | |
249 | #if MYSQL_VERSION_ID < 100010 && !defined(MARIADB_BASE_VERSION) |
236 | if (vio->vioclose != vio_close) |
250 | if (vio->vioclose != vio_close) |
237 | 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?"); |
238 | |
252 | |
239 | if (vio->write != vio_write) |
253 | if (vio->write != vio_write) |
240 | 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?"); |
241 | |
255 | |
242 | if (vio->read != vio_read |
256 | if (vio->read != vio_read |
243 | && vio->read != vio_read_buff) |
257 | && vio->read != vio_read_buff) |
244 | 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 |
245 | |
260 | |
246 | Newz (0, our, 1, ourdata); |
261 | Newz (0, our, 1, ourdata); |
247 | our->magic = CoMy_MAGIC; |
262 | our->magic = CoMy_MAGIC; |
248 | our->corohandle_sv = newSVsv (corohandle_sv); |
263 | our->corohandle_sv = newSVsv (corohandle_sv); |
249 | our->corohandle = newSVsv (corohandle); |
264 | our->corohandle = newSVsv (corohandle); |
… | |
… | |
252 | { |
267 | { |
253 | ev_io_init (&(our->rw), iocb, vio->sd, EV_READ); |
268 | ev_io_init (&(our->rw), iocb, vio->sd, EV_READ); |
254 | ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE); |
269 | ev_io_init (&(our->ww), iocb, vio->sd, EV_WRITE); |
255 | } |
270 | } |
256 | #endif |
271 | #endif |
257 | |
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 |
258 | vio->desc [DESC_OFFSET - 1] = 0; |
277 | vio->desc [DESC_OFFSET - 1] = 0; |
|
|
278 | #endif |
259 | OURDATAPTR = our; |
279 | OURDATAPTR = our; |
|
|
280 | |
|
|
281 | our->old_vioclose = vio->vioclose; |
|
|
282 | our->old_write = vio->write; |
|
|
283 | our->old_read = vio->read; |
260 | |
284 | |
261 | vio->vioclose = our_close; |
285 | vio->vioclose = our_close; |
262 | vio->write = our_write; |
286 | vio->write = our_write; |
263 | vio->read = our_read; |
287 | vio->read = our_read; |
264 | } |
288 | } |