Coro-Mysql
view release on metacpan or search on metacpan
ourdata *our = OURDATAPTR;
if (VIOM (vio)->read != our_read)
croak ("vio.read has unexpected content during unpatch - wtf?");
if (VIOM (vio)->write != our_write)
croak ("vio.write has unexpected content during unpatch - wtf?");
if (VIOM (vio)->vioclose != our_close)
croak ("vio.vioclose has unexpected content during unpatch - wtf?");
#if HAVE_EV
if (use_ev)
{
ev_io_stop (EV_DEFAULT_UC, &(our->rw));
ev_io_stop (EV_DEFAULT_UC, &(our->ww));
}
#endif
SvREFCNT_dec (our->corohandle);
SvREFCNT_dec (our->corohandle_sv);
#if DESC_IS_PTR
vio->desc = our->old_desc;
#endif
#if PVIO
vio->methods = our->oldmethods;
#else
VIOM (vio)->vioclose = our->old_close;
VIOM (vio)->write = our->old_write;
VIOM (vio)->read = our->old_read;
#endif
Safefree (our);
VIOM (vio)->vioclose (vio);
}
#if HAVE_EV
static void
iocb (EV_P_ ev_io *w, int revents)
{
ev_io_stop (EV_A, w);
CORO_READY ((SV *)w->data);
}
#endif
MODULE = Coro::Mysql PACKAGE = Coro::Mysql
BOOT:
{
readable = get_cv ("Coro::Mysql::readable", 0);
writable = get_cv ("Coro::Mysql::writable", 0);
}
PROTOTYPES: ENABLE
void
_use_ev ()
PPCODE:
{
static int onceonly;
if (!onceonly)
{
onceonly = 1;
#if HAVE_EV
I_EV_API ("Coro::Mysql");
I_CORO_API ("Coro::Mysql");
use_ev = 1;
#endif
}
XPUSHs (use_ev ? &PL_sv_yes : &PL_sv_no);
}
void
_patch (IV sock, int fd, unsigned long client_version, SV *corohandle_sv, SV *corohandle)
CODE:
{
MYSQL *my = (MYSQL *)sock;
VIOPTR vio = my_to_vio (my);
ourdata *our;
/* matching versions are required but not sufficient */
if (client_version != mysql_get_client_version ())
croak ("DBD::mysql linked against different libmysqlclient library than Coro::Mysql (%lu vs. %lu).",
client_version, mysql_get_client_version ());
if (fd != my->net.fd)
croak ("DBD::mysql fd and libmysql disagree - library mismatch, unsupported transport or API changes?");
if (fd != VIOSD (vio))
croak ("DBD::mysql fd and vio-sd disagree - library mismatch, unsupported transport or API changes?");
#if MYSQL_VERSION_ID < 100010 && !defined(MARIADB_BASE_VERSION)
if (VIOM (vio)->vioclose != vio_close)
croak ("vio.vioclose has unexpected content - library mismatch, unsupported transport or API changes?");
if (VIOM (vio)->write != vio_write)
croak ("vio.write has unexpected content - library mismatch, unsupported transport or API changes?");
if (VIOM (vio)->read != vio_read
&& VIOM (vio)->read != vio_read_buff)
croak ("vio.read has unexpected content - library mismatch, unsupported transport or API changes?");
#endif
#if PVIO
if (vio->type != PVIO_TYPE_UNIXSOCKET && vio->type != PVIO_TYPE_SOCKET)
croak ("connection type mismatch: Coro::Mysql only supports 'unixsocket' and 'socket' types at this time");
#endif
Newz (0, our, 1, ourdata);
our->magic = CoMy_MAGIC;
our->corohandle_sv = newSVsv (corohandle_sv);
our->corohandle = newSVsv (corohandle);
#if HAVE_EV
if (use_ev)
{
ev_io_init (&(our->rw), iocb, VIOSD (vio), EV_READ);
ev_io_init (&(our->ww), iocb, VIOSD (vio), EV_WRITE);
}
( run in 0.474 second using v1.01-cache-2.11-cpan-71847e10f99 )