started writing the mariadb client service
This commit is contained in:
parent
4470e7705c
commit
61d1f8abd9
@ -1,49 +1,49 @@
|
||||
|
||||
#include <mio.h>
|
||||
#include <mio-maria.h>
|
||||
#include <mio-mar.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mariadb/mysql.h>
|
||||
|
||||
static void maria_on_disconnect (mio_dev_maria_t* dev)
|
||||
static void mar_on_disconnect (mio_dev_mar_t* dev)
|
||||
{
|
||||
}
|
||||
|
||||
static void maria_on_connect (mio_dev_maria_t* dev)
|
||||
static void mar_on_connect (mio_dev_mar_t* dev)
|
||||
{
|
||||
printf ("CONNECTED...\n");
|
||||
if (mio_dev_maria_querywithbchars(dev, "SHOW STATUS", 11) <= -1)
|
||||
if (mio_dev_mar_querywithbchars(dev, "SHOW STATUS", 11) <= -1)
|
||||
{
|
||||
mio_dev_maria_halt (dev);
|
||||
mio_dev_mar_halt (dev);
|
||||
}
|
||||
}
|
||||
|
||||
static void maria_on_query_started (mio_dev_maria_t* dev, int maria_ret)
|
||||
static void mar_on_query_started (mio_dev_mar_t* dev, int mar_ret)
|
||||
{
|
||||
if (maria_ret != 0)
|
||||
if (mar_ret != 0)
|
||||
{
|
||||
printf ("QUERY NOT SENT PROPERLY..%s\n", mysql_error(dev->hnd));
|
||||
}
|
||||
else
|
||||
{
|
||||
printf ("QUERY SENT..\n");
|
||||
if (mio_dev_maria_fetchrows(dev) <= -1)
|
||||
if (mio_dev_mar_fetchrows(dev) <= -1)
|
||||
{
|
||||
printf ("FETCH ROW FAILURE - %s\n", mysql_error(dev->hnd));
|
||||
mio_dev_maria_halt (dev);
|
||||
mio_dev_mar_halt (dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void maria_on_row_fetched (mio_dev_maria_t* dev, void* data)
|
||||
static void mar_on_row_fetched (mio_dev_mar_t* dev, void* data)
|
||||
{
|
||||
MYSQL_ROW row = (MYSQL_ROW)data;
|
||||
static int x = 0;
|
||||
if (!row)
|
||||
{
|
||||
printf ("NO MORE ROW..\n");
|
||||
if (x == 0 && mio_dev_maria_querywithbchars(dev, "SELECT * FROM pdns.records", 26) <= -1) mio_dev_maria_halt (dev);
|
||||
if (x == 0 && mio_dev_mar_querywithbchars(dev, "SELECT * FROM pdns.records", 26) <= -1) mio_dev_mar_halt (dev);
|
||||
x++;
|
||||
}
|
||||
else
|
||||
@ -60,9 +60,9 @@ int main (int argc, char* argv[])
|
||||
{
|
||||
|
||||
mio_t* mio = MIO_NULL;
|
||||
mio_dev_maria_t* maria;
|
||||
mio_dev_maria_make_t mi;
|
||||
mio_dev_maria_connect_t ci;
|
||||
mio_dev_mar_t* mar;
|
||||
mio_dev_mar_make_t mi;
|
||||
mio_dev_mar_connect_t ci;
|
||||
|
||||
if (argc != 6)
|
||||
{
|
||||
@ -85,23 +85,23 @@ int main (int argc, char* argv[])
|
||||
ci.dbname = argv[5];
|
||||
|
||||
memset (&mi, 0, MIO_SIZEOF(mi));
|
||||
/*mi.on_write = maria_on_write;
|
||||
mi.on_read = maria_on_read;*/
|
||||
mi.on_connect = maria_on_connect;
|
||||
mi.on_disconnect = maria_on_disconnect;
|
||||
mi.on_query_started = maria_on_query_started;
|
||||
mi.on_row_fetched = maria_on_row_fetched;
|
||||
/*mi.on_write = mar_on_write;
|
||||
mi.on_read = mar_on_read;*/
|
||||
mi.on_connect = mar_on_connect;
|
||||
mi.on_disconnect = mar_on_disconnect;
|
||||
mi.on_query_started = mar_on_query_started;
|
||||
mi.on_row_fetched = mar_on_row_fetched;
|
||||
|
||||
maria = mio_dev_maria_make(mio, 0, &mi);
|
||||
if (!maria)
|
||||
mar = mio_dev_mar_make(mio, 0, &mi);
|
||||
if (!mar)
|
||||
{
|
||||
printf ("Cannot make a maria db client device\n");
|
||||
printf ("Cannot make a mar db client device\n");
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (mio_dev_maria_connect(maria, &ci) <= -1)
|
||||
if (mio_dev_mar_connect(mar, &ci) <= -1)
|
||||
{
|
||||
printf ("Cannot connect to maria db server\n");
|
||||
printf ("Cannot connect to mar db server\n");
|
||||
goto oops;
|
||||
}
|
||||
|
||||
|
@ -90,8 +90,8 @@ libmio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||
libmio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
||||
|
||||
if ENABLE_MARIADB
|
||||
include_HEADERS += mio-maria.h
|
||||
libmio_la_SOURCES += maria.c
|
||||
include_HEADERS += mio-mar.h
|
||||
libmio_la_SOURCES += mar.c mar-cli.c
|
||||
libmio_la_LDFLAGS +=
|
||||
libmio_la_LIBADD += -lmariadb
|
||||
endif
|
||||
|
@ -89,8 +89,8 @@ PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
@ENABLE_MARIADB_TRUE@am__append_1 = mio-maria.h
|
||||
@ENABLE_MARIADB_TRUE@am__append_2 = maria.c
|
||||
@ENABLE_MARIADB_TRUE@am__append_1 = mio-mar.h
|
||||
@ENABLE_MARIADB_TRUE@am__append_2 = mar.c mar-cli.c
|
||||
@ENABLE_MARIADB_TRUE@am__append_3 =
|
||||
@ENABLE_MARIADB_TRUE@am__append_4 = -lmariadb
|
||||
subdir = lib
|
||||
@ -148,8 +148,9 @@ am__libmio_la_SOURCES_DIST = chr.c dns.c dns-cli.c ecs.c ecs-imp.h \
|
||||
http-svr.c http-thr.c http-txt.c json.c mio-prv.h mio.c nwif.c \
|
||||
path.c pipe.c pro.c sck.c skad.c sys.c sys-ass.c sys-err.c \
|
||||
sys-log.c sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h \
|
||||
uch-prop.h tmr.c utf8.c utl.c maria.c
|
||||
@ENABLE_MARIADB_TRUE@am__objects_1 = libmio_la-maria.lo
|
||||
uch-prop.h tmr.c utf8.c utl.c mar.c mar-cli.c
|
||||
@ENABLE_MARIADB_TRUE@am__objects_1 = libmio_la-mar.lo \
|
||||
@ENABLE_MARIADB_TRUE@ libmio_la-mar-cli.lo
|
||||
am_libmio_la_OBJECTS = libmio_la-chr.lo libmio_la-dns.lo \
|
||||
libmio_la-dns-cli.lo libmio_la-ecs.lo libmio_la-err.lo \
|
||||
libmio_la-fmt.lo libmio_la-htb.lo libmio_la-htrd.lo \
|
||||
@ -196,7 +197,8 @@ am__depfiles_remade = ./$(DEPDIR)/libmio_la-chr.Plo \
|
||||
./$(DEPDIR)/libmio_la-http-thr.Plo \
|
||||
./$(DEPDIR)/libmio_la-http-txt.Plo \
|
||||
./$(DEPDIR)/libmio_la-http.Plo ./$(DEPDIR)/libmio_la-json.Plo \
|
||||
./$(DEPDIR)/libmio_la-maria.Plo ./$(DEPDIR)/libmio_la-mio.Plo \
|
||||
./$(DEPDIR)/libmio_la-mar-cli.Plo \
|
||||
./$(DEPDIR)/libmio_la-mar.Plo ./$(DEPDIR)/libmio_la-mio.Plo \
|
||||
./$(DEPDIR)/libmio_la-nwif.Plo ./$(DEPDIR)/libmio_la-path.Plo \
|
||||
./$(DEPDIR)/libmio_la-pipe.Plo ./$(DEPDIR)/libmio_la-pro.Plo \
|
||||
./$(DEPDIR)/libmio_la-sck.Plo ./$(DEPDIR)/libmio_la-skad.Plo \
|
||||
@ -238,7 +240,7 @@ am__include_HEADERS_DIST = mio-cfg.h mio-chr.h mio-cmn.h mio-dns.h \
|
||||
mio-ecs.h mio-fmt.h mio-htb.h mio-htrd.h mio-htre.h mio-http.h \
|
||||
mio-json.h mio-nwif.h mio-pac1.h mio-path.h mio-pipe.h \
|
||||
mio-pro.h mio-sck.h mio-skad.h mio-thr.h mio-upac.h mio-utl.h \
|
||||
mio.h mio-maria.h
|
||||
mio.h mio-mar.h
|
||||
HEADERS = $(include_HEADERS)
|
||||
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
|
||||
$(LISP)mio-cfg.h.in
|
||||
@ -553,7 +555,8 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-http-txt.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-http.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-json.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-maria.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-mar-cli.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-mar.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-mio.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-nwif.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmio_la-path.Plo@am__quote@ # am--include-marker
|
||||
@ -826,12 +829,19 @@ libmio_la-utl.lo: utl.c
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-utl.lo `test -f 'utl.c' || echo '$(srcdir)/'`utl.c
|
||||
|
||||
libmio_la-maria.lo: maria.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-maria.lo -MD -MP -MF $(DEPDIR)/libmio_la-maria.Tpo -c -o libmio_la-maria.lo `test -f 'maria.c' || echo '$(srcdir)/'`maria.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-maria.Tpo $(DEPDIR)/libmio_la-maria.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='maria.c' object='libmio_la-maria.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
libmio_la-mar.lo: mar.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-mar.lo -MD -MP -MF $(DEPDIR)/libmio_la-mar.Tpo -c -o libmio_la-mar.lo `test -f 'mar.c' || echo '$(srcdir)/'`mar.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-mar.Tpo $(DEPDIR)/libmio_la-mar.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mar.c' object='libmio_la-mar.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-maria.lo `test -f 'maria.c' || echo '$(srcdir)/'`maria.c
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-mar.lo `test -f 'mar.c' || echo '$(srcdir)/'`mar.c
|
||||
|
||||
libmio_la-mar-cli.lo: mar-cli.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libmio_la-mar-cli.lo -MD -MP -MF $(DEPDIR)/libmio_la-mar-cli.Tpo -c -o libmio_la-mar-cli.lo `test -f 'mar-cli.c' || echo '$(srcdir)/'`mar-cli.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libmio_la-mar-cli.Tpo $(DEPDIR)/libmio_la-mar-cli.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mar-cli.c' object='libmio_la-mar-cli.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libmio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libmio_la-mar-cli.lo `test -f 'mar-cli.c' || echo '$(srcdir)/'`mar-cli.c
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
@ -1003,7 +1013,8 @@ distclean: distclean-am
|
||||
-rm -f ./$(DEPDIR)/libmio_la-http-txt.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-http.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-json.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-maria.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-mar-cli.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-mar.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-mio.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-nwif.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-path.Plo
|
||||
@ -1082,7 +1093,8 @@ maintainer-clean: maintainer-clean-am
|
||||
-rm -f ./$(DEPDIR)/libmio_la-http-txt.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-http.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-json.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-maria.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-mar-cli.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-mar.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-mio.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-nwif.Plo
|
||||
-rm -f ./$(DEPDIR)/libmio_la-path.Plo
|
||||
|
64
mio/lib/mar-cli.c
Normal file
64
mio/lib/mar-cli.c
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <mio-mar.h>
|
||||
|
||||
#include <mariadb/mysql.h>
|
||||
|
||||
struct mio_svc_marc_t
|
||||
{
|
||||
MIO_SVC_HEADER;
|
||||
};
|
||||
|
||||
mio_svc_marc_t* mio_svc_marc_start (mio_t* mio)
|
||||
{
|
||||
mio_svc_marc_t* marc = MIO_NULL;
|
||||
|
||||
|
||||
marc = (mio_svc_marc_t*)mio_callocmem(mio, MIO_SIZEOF(*marc));
|
||||
if (MIO_UNLIKELY(!marc)) goto oops;
|
||||
|
||||
marc->mio = mio;
|
||||
marc->svc_stop = mio_svc_marc_stop;
|
||||
|
||||
MIO_SVCL_APPEND_SVC (&mio->actsvc, (mio_svc_t*)marc);
|
||||
return marc;
|
||||
|
||||
oops:
|
||||
if (marc)
|
||||
{
|
||||
mio_freemem (mio, marc);
|
||||
}
|
||||
return MIO_NULL;
|
||||
}
|
||||
|
||||
void mio_svc_marc_stop (mio_svc_marc_t* marc)
|
||||
{
|
||||
mio_t* mio = marc->mio;
|
||||
|
||||
MIO_SVCL_UNLINK_SVC (marc);
|
||||
mio_freemem (mio, marc);
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <mio-maria.h>
|
||||
#include <mio-mar.h>
|
||||
#include "mio-prv.h"
|
||||
|
||||
#include <mariadb/mysql.h>
|
||||
@ -32,11 +32,11 @@
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
static int dev_maria_make (mio_dev_t* dev, void* ctx)
|
||||
static int dev_mar_make (mio_dev_t* dev, void* ctx)
|
||||
{
|
||||
mio_t* mio = dev->mio;
|
||||
mio_dev_maria_t* rdev = (mio_dev_maria_t*)dev;
|
||||
mio_dev_maria_make_t* mi = (mio_dev_maria_make_t*)ctx;
|
||||
mio_dev_mar_t* rdev = (mio_dev_mar_t*)dev;
|
||||
mio_dev_mar_make_t* mi = (mio_dev_mar_make_t*)ctx;
|
||||
|
||||
rdev->hnd = mysql_init(MIO_NULL);
|
||||
if (MIO_UNLIKELY(!rdev->hnd))
|
||||
@ -68,10 +68,10 @@ static int dev_maria_make (mio_dev_t* dev, void* ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dev_maria_kill (mio_dev_t* dev, int force)
|
||||
static int dev_mar_kill (mio_dev_t* dev, int force)
|
||||
{
|
||||
/*mio_t* mio = dev->mio;*/
|
||||
mio_dev_maria_t* rdev = (mio_dev_maria_t*)dev;
|
||||
mio_dev_mar_t* rdev = (mio_dev_mar_t*)dev;
|
||||
|
||||
if (rdev->on_disconnect) rdev->on_disconnect (rdev);
|
||||
|
||||
@ -89,9 +89,9 @@ static int dev_maria_kill (mio_dev_t* dev, int force)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static mio_syshnd_t dev_maria_getsyshnd (mio_dev_t* dev)
|
||||
static mio_syshnd_t dev_mar_getsyshnd (mio_dev_t* dev)
|
||||
{
|
||||
mio_dev_maria_t* rdev = (mio_dev_maria_t*)dev;
|
||||
mio_dev_mar_t* rdev = (mio_dev_mar_t*)dev;
|
||||
return (mio_syshnd_t)mysql_get_socket(rdev->hnd);
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ static int mysql_wstatus_to_events (int wstatus)
|
||||
return events;
|
||||
}
|
||||
|
||||
static MIO_INLINE void watch_mysql (mio_dev_maria_t* rdev, int wstatus)
|
||||
static MIO_INLINE void watch_mysql (mio_dev_mar_t* rdev, int wstatus)
|
||||
{
|
||||
if (mio_dev_watch((mio_dev_t*)rdev, MIO_DEV_WATCH_UPDATE, mysql_wstatus_to_events(wstatus)) <= -1)
|
||||
{
|
||||
@ -124,13 +124,13 @@ static MIO_INLINE void watch_mysql (mio_dev_maria_t* rdev, int wstatus)
|
||||
}
|
||||
|
||||
|
||||
static void start_fetch_row (mio_dev_maria_t* rdev)
|
||||
static void start_fetch_row (mio_dev_mar_t* rdev)
|
||||
{
|
||||
MYSQL_ROW row;
|
||||
int status;
|
||||
|
||||
status = mysql_fetch_row_start(&row, rdev->res);
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_ROW_FETCHING);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_ROW_FETCHING);
|
||||
if (status)
|
||||
{
|
||||
/* row fetched */
|
||||
@ -148,21 +148,21 @@ static void start_fetch_row (mio_dev_maria_t* rdev)
|
||||
}
|
||||
|
||||
|
||||
static int dev_maria_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
static int dev_mar_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
{
|
||||
mio_t* mio = dev->mio;
|
||||
mio_dev_maria_t* rdev = (mio_dev_maria_t*)dev;
|
||||
mio_dev_mar_t* rdev = (mio_dev_mar_t*)dev;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MIO_DEV_MARIA_CONNECT:
|
||||
case MIO_DEV_MAR_CONNECT:
|
||||
{
|
||||
mio_dev_maria_connect_t* ci = (mio_dev_maria_connect_t*)arg;
|
||||
mio_dev_mar_connect_t* ci = (mio_dev_mar_connect_t*)arg;
|
||||
MYSQL* ret;
|
||||
int status;
|
||||
|
||||
|
||||
if (MIO_DEV_MARIA_GET_PROGRESS(rdev))
|
||||
if (MIO_DEV_MAR_GET_PROGRESS(rdev))
|
||||
{
|
||||
/* can't connect again */
|
||||
mio_seterrbfmt (mio, MIO_EPERM, "operation in progress. disallowed to connect again");
|
||||
@ -174,7 +174,7 @@ static int dev_maria_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
if (status)
|
||||
{
|
||||
/* not connected */
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_CONNECTING);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_CONNECTING);
|
||||
rdev->connected = 0;
|
||||
watch_mysql (rdev, status);
|
||||
}
|
||||
@ -195,7 +195,7 @@ static int dev_maria_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
case MIO_DEV_MARIA_QUERY_WITH_BCS:
|
||||
case MIO_DEV_MAR_QUERY_WITH_BCS:
|
||||
{
|
||||
const mio_bcs_t* qstr = (const mio_bcs_t*)arg;
|
||||
int err, status;
|
||||
@ -207,7 +207,7 @@ static int dev_maria_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
}
|
||||
|
||||
status = mysql_real_query_start(&err, rdev->hnd, qstr->ptr, qstr->len);
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_QUERY_STARTING);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_QUERY_STARTING);
|
||||
if (status)
|
||||
{
|
||||
/* not done */
|
||||
@ -224,7 +224,7 @@ static int dev_maria_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
case MIO_DEV_MARIA_FETCH_ROW:
|
||||
case MIO_DEV_MAR_FETCH_ROW:
|
||||
{
|
||||
if (!rdev->res)
|
||||
{
|
||||
@ -246,25 +246,25 @@ static int dev_maria_ioctl (mio_dev_t* dev, int cmd, void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
static mio_dev_mth_t dev_maria_methods =
|
||||
static mio_dev_mth_t dev_mar_methods =
|
||||
{
|
||||
dev_maria_make,
|
||||
dev_maria_kill,
|
||||
dev_maria_getsyshnd,
|
||||
dev_mar_make,
|
||||
dev_mar_kill,
|
||||
dev_mar_getsyshnd,
|
||||
|
||||
MIO_NULL,
|
||||
MIO_NULL,
|
||||
MIO_NULL,
|
||||
dev_maria_ioctl
|
||||
dev_mar_ioctl
|
||||
};
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
|
||||
static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
static int dev_evcb_mar_ready (mio_dev_t* dev, int events)
|
||||
{
|
||||
mio_t* mio = dev->mio;
|
||||
mio_dev_maria_t* rdev = (mio_dev_maria_t*)dev;
|
||||
mio_dev_mar_t* rdev = (mio_dev_mar_t*)dev;
|
||||
|
||||
#if 0
|
||||
if (events & MIO_DEV_EVENT_ERR)
|
||||
@ -290,14 +290,14 @@ static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (MIO_DEV_MARIA_GET_PROGRESS(rdev))
|
||||
switch (MIO_DEV_MAR_GET_PROGRESS(rdev))
|
||||
{
|
||||
case MIO_DEV_MARIA_CONNECTING:
|
||||
case MIO_DEV_MAR_CONNECTING:
|
||||
|
||||
if (rdev->connected)
|
||||
{
|
||||
rdev->connected = 0;
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_CONNECTED);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_CONNECTED);
|
||||
if (rdev->on_connect) rdev->on_connect (rdev);
|
||||
}
|
||||
else
|
||||
@ -311,17 +311,17 @@ static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
if (!status)
|
||||
{
|
||||
/* connected */
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_CONNECTED);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_CONNECTED);
|
||||
if (rdev->on_connect) rdev->on_connect (rdev);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MIO_DEV_MARIA_QUERY_STARTING:
|
||||
case MIO_DEV_MAR_QUERY_STARTING:
|
||||
if (rdev->query_started)
|
||||
{
|
||||
rdev->query_started = 0;
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_QUERY_STARTED);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_QUERY_STARTED);
|
||||
if (rdev->on_query_started) rdev->on_query_started (rdev, rdev->query_ret);
|
||||
}
|
||||
else
|
||||
@ -335,14 +335,14 @@ static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
if (!status)
|
||||
{
|
||||
/* query sent */
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_QUERY_STARTED);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_QUERY_STARTED);
|
||||
if (rdev->on_query_started) rdev->on_query_started (rdev, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MIO_DEV_MARIA_ROW_FETCHING:
|
||||
case MIO_DEV_MAR_ROW_FETCHING:
|
||||
{
|
||||
int status;
|
||||
MYSQL_ROW row;
|
||||
@ -361,7 +361,7 @@ static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
watch_mysql (rdev, rdev->row_wstatus);
|
||||
}
|
||||
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_ROW_FETCHED);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_ROW_FETCHED);
|
||||
if (rdev->on_row_fetched) rdev->on_row_fetched (rdev, row);
|
||||
|
||||
if (row) start_fetch_row (rdev);
|
||||
@ -383,7 +383,7 @@ static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
rdev->res = MIO_NULL;
|
||||
}
|
||||
|
||||
MIO_DEV_MARIA_SET_PROGRESS (rdev, MIO_DEV_MARIA_ROW_FETCHED);
|
||||
MIO_DEV_MAR_SET_PROGRESS (rdev, MIO_DEV_MAR_ROW_FETCHED);
|
||||
if (rdev->on_row_fetched) rdev->on_row_fetched (rdev, row);
|
||||
|
||||
if (row) start_fetch_row (rdev); /* arrange to fetch the next row */
|
||||
@ -398,16 +398,16 @@ static int dev_evcb_maria_ready (mio_dev_t* dev, int events)
|
||||
}
|
||||
|
||||
default:
|
||||
mio_seterrbfmt (mio, MIO_EINTERN, "invalid progress state in maria");
|
||||
mio_seterrbfmt (mio, MIO_EINTERN, "invalid progress state in mar");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0; /* success. but skip core event handling */
|
||||
}
|
||||
|
||||
static mio_dev_evcb_t dev_maria_event_callbacks =
|
||||
static mio_dev_evcb_t dev_mar_event_callbacks =
|
||||
{
|
||||
dev_evcb_maria_ready,
|
||||
dev_evcb_mar_ready,
|
||||
MIO_NULL, /* no read callback */
|
||||
MIO_NULL /* no write callback */
|
||||
};
|
||||
@ -416,26 +416,26 @@ static mio_dev_evcb_t dev_maria_event_callbacks =
|
||||
/* ========================================================================= */
|
||||
|
||||
|
||||
mio_dev_maria_t* mio_dev_maria_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_maria_make_t* mi)
|
||||
mio_dev_mar_t* mio_dev_mar_make (mio_t* mio, mio_oow_t xtnsize, const mio_dev_mar_make_t* mi)
|
||||
{
|
||||
return (mio_dev_maria_t*)mio_dev_make(
|
||||
mio, MIO_SIZEOF(mio_dev_maria_t) + xtnsize,
|
||||
&dev_maria_methods, &dev_maria_event_callbacks, (void*)mi);
|
||||
return (mio_dev_mar_t*)mio_dev_make(
|
||||
mio, MIO_SIZEOF(mio_dev_mar_t) + xtnsize,
|
||||
&dev_mar_methods, &dev_mar_event_callbacks, (void*)mi);
|
||||
}
|
||||
|
||||
int mio_dev_maria_connect (mio_dev_maria_t* dev, mio_dev_maria_connect_t* ci)
|
||||
int mio_dev_mar_connect (mio_dev_mar_t* dev, mio_dev_mar_connect_t* ci)
|
||||
{
|
||||
return mio_dev_ioctl((mio_dev_t*)dev, MIO_DEV_MARIA_CONNECT, ci);
|
||||
return mio_dev_ioctl((mio_dev_t*)dev, MIO_DEV_MAR_CONNECT, ci);
|
||||
}
|
||||
|
||||
int mio_dev_maria_querywithbchars (mio_dev_maria_t* dev, const mio_bch_t* qstr, mio_oow_t qlen)
|
||||
int mio_dev_mar_querywithbchars (mio_dev_mar_t* dev, const mio_bch_t* qstr, mio_oow_t qlen)
|
||||
{
|
||||
mio_bcs_t bcs = { (mio_bch_t*)qstr, qlen};
|
||||
return mio_dev_ioctl((mio_dev_t*)dev, MIO_DEV_MARIA_QUERY_WITH_BCS, &bcs);
|
||||
return mio_dev_ioctl((mio_dev_t*)dev, MIO_DEV_MAR_QUERY_WITH_BCS, &bcs);
|
||||
}
|
||||
|
||||
int mio_dev_maria_fetchrows (mio_dev_maria_t* dev)
|
||||
int mio_dev_mar_fetchrows (mio_dev_mar_t* dev)
|
||||
{
|
||||
return mio_dev_ioctl((mio_dev_t*)dev, MIO_DEV_MARIA_FETCH_ROW, MIO_NULL);
|
||||
return mio_dev_ioctl((mio_dev_t*)dev, MIO_DEV_MAR_FETCH_ROW, MIO_NULL);
|
||||
}
|
||||
|
226
mio/lib/mio-mar.h
Normal file
226
mio/lib/mio-mar.h
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PIPEVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PIPECUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PIPEFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MIO_MAR_H_
|
||||
#define _MIO_MAR_H_
|
||||
|
||||
#include <mio.h>
|
||||
|
||||
typedef struct mio_dev_mar_t mio_dev_mar_t;
|
||||
|
||||
enum mio_dev_mar_state_t
|
||||
{
|
||||
/* the following items(progress bits) are mutually exclusive */
|
||||
MIO_DEV_MAR_CONNECTING = (1 << 0),
|
||||
MIO_DEV_MAR_CONNECTED = (1 << 1),
|
||||
MIO_DEV_MAR_QUERY_STARTING = (1 << 2),
|
||||
MIO_DEV_MAR_QUERY_STARTED = (1 << 3),
|
||||
MIO_DEV_MAR_ROW_FETCHING = (1 << 4),
|
||||
MIO_DEV_MAR_ROW_FETCHED = (1 << 5),
|
||||
|
||||
|
||||
#if 0
|
||||
/* the following items can be bitwise-ORed with an exclusive item above */
|
||||
MIO_DEV_MAR_LENIENT = (1 << 14),
|
||||
MIO_DEV_MAR_INTERCEPTED = (1 << 15),
|
||||
#endif
|
||||
|
||||
/* convenience bit masks */
|
||||
MIO_DEV_MAR_ALL_PROGRESS_BITS = (MIO_DEV_MAR_CONNECTING |
|
||||
MIO_DEV_MAR_CONNECTED |
|
||||
MIO_DEV_MAR_QUERY_STARTING |
|
||||
MIO_DEV_MAR_QUERY_STARTED |
|
||||
MIO_DEV_MAR_ROW_FETCHING |
|
||||
MIO_DEV_MAR_ROW_FETCHED)
|
||||
};
|
||||
typedef enum mio_dev_mar_state_t mio_dev_mar_state_t;
|
||||
|
||||
#define MIO_DEV_MAR_SET_PROGRESS(dev,bit) do { \
|
||||
(dev)->state &= ~MIO_DEV_MAR_ALL_PROGRESS_BITS; \
|
||||
(dev)->state |= (bit); \
|
||||
} while(0)
|
||||
|
||||
#define MIO_DEV_MAR_GET_PROGRESS(dev) ((dev)->state & MIO_DEV_MAR_ALL_PROGRESS_BITS)
|
||||
|
||||
|
||||
typedef int (*mio_dev_mar_on_read_t) (
|
||||
mio_dev_mar_t* dev,
|
||||
const void* data,
|
||||
mio_iolen_t len
|
||||
);
|
||||
|
||||
typedef int (*mio_dev_mar_on_write_t) (
|
||||
mio_dev_mar_t* dev,
|
||||
mio_iolen_t wrlen,
|
||||
void* wrctx
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_mar_on_connect_t) (
|
||||
mio_dev_mar_t* dev
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_mar_on_disconnect_t) (
|
||||
mio_dev_mar_t* dev
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_mar_on_query_started_t) (
|
||||
mio_dev_mar_t* dev,
|
||||
int mar_ret
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_mar_on_row_fetched_t) (
|
||||
mio_dev_mar_t* dev,
|
||||
void* row_data
|
||||
);
|
||||
|
||||
struct mio_dev_mar_t
|
||||
{
|
||||
MIO_DEV_HEADER;
|
||||
|
||||
void* hnd;
|
||||
void* res;
|
||||
int state;
|
||||
|
||||
unsigned int connected;
|
||||
unsigned int query_started;
|
||||
unsigned int row_fetched;
|
||||
|
||||
int query_ret;
|
||||
int row_wstatus;
|
||||
void* row;
|
||||
|
||||
mio_dev_mar_on_read_t on_read;
|
||||
mio_dev_mar_on_write_t on_write;
|
||||
mio_dev_mar_on_connect_t on_connect;
|
||||
mio_dev_mar_on_disconnect_t on_disconnect;
|
||||
mio_dev_mar_on_query_started_t on_query_started;
|
||||
mio_dev_mar_on_row_fetched_t on_row_fetched;
|
||||
};
|
||||
|
||||
typedef struct mio_dev_mar_make_t mio_dev_mar_make_t;
|
||||
struct mio_dev_mar_make_t
|
||||
{
|
||||
mio_dev_mar_on_write_t on_write; /* mandatory */
|
||||
mio_dev_mar_on_read_t on_read; /* mandatory */
|
||||
mio_dev_mar_on_connect_t on_connect; /* optional */
|
||||
mio_dev_mar_on_disconnect_t on_disconnect; /* optional */
|
||||
mio_dev_mar_on_query_started_t on_query_started;
|
||||
mio_dev_mar_on_row_fetched_t on_row_fetched;
|
||||
};
|
||||
|
||||
typedef struct mio_dev_mar_connect_t mio_dev_mar_connect_t;
|
||||
struct mio_dev_mar_connect_t
|
||||
{
|
||||
const mio_bch_t* host;
|
||||
const mio_bch_t* username;
|
||||
const mio_bch_t* password;
|
||||
const mio_bch_t* dbname;
|
||||
mio_uint16_t port;
|
||||
};
|
||||
|
||||
enum mio_dev_mar_ioctl_cmd_t
|
||||
{
|
||||
MIO_DEV_MAR_CONNECT,
|
||||
MIO_DEV_MAR_QUERY_WITH_BCS,
|
||||
MIO_DEV_MAR_FETCH_ROW
|
||||
};
|
||||
typedef enum mio_dev_mar_ioctl_cmd_t mio_dev_mar_ioctl_cmd_t;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
|
||||
typedef struct mio_svc_marc_t mio_svc_marc_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MIO_EXPORT mio_dev_mar_t* mio_dev_mar_make (
|
||||
mio_t* mio,
|
||||
mio_oow_t xtnsize,
|
||||
const mio_dev_mar_make_t* data
|
||||
);
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE mio_t* mio_dev_mar_getmio (mio_dev_mar_t* mar) { return mio_dev_getmio((mio_dev_t*)mar); }
|
||||
#else
|
||||
# define mio_dev_mar_getmio(mar) mio_dev_getmio(mar)
|
||||
#endif
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE void* mio_dev_mar_getxtn (mio_dev_mar_t* mar) { return (void*)(mar + 1); }
|
||||
#else
|
||||
# define mio_dev_mar_getxtn(mar) ((void*)(((mio_dev_mar_t*)mar) + 1))
|
||||
#endif
|
||||
|
||||
|
||||
MIO_EXPORT int mio_dev_mar_connect (
|
||||
mio_dev_mar_t* mar,
|
||||
mio_dev_mar_connect_t* ci
|
||||
);
|
||||
|
||||
MIO_EXPORT int mio_dev_mar_querywithbchars (
|
||||
mio_dev_mar_t* mar,
|
||||
const mio_bch_t* qstr,
|
||||
mio_oow_t qlen
|
||||
);
|
||||
|
||||
MIO_EXPORT int mio_dev_mar_fetchrows (
|
||||
mio_dev_mar_t* mar
|
||||
);
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE void mio_dev_mar_kill (mio_dev_mar_t* mar) { mio_dev_kill ((mio_dev_t*)mar); }
|
||||
static MIO_INLINE void mio_dev_mar_halt (mio_dev_mar_t* mar) { mio_dev_halt ((mio_dev_t*)mar); }
|
||||
#else
|
||||
# define mio_dev_mar_kill(mar) mio_dev_kill((mio_dev_t*)mar)
|
||||
# define mio_dev_mar_halt(mar) mio_dev_halt((mio_dev_t*)mar)
|
||||
#endif
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* MARDB CLIENT SERVICE */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
MIO_EXPORT mio_svc_marc_t* mio_svc_marc_start (
|
||||
mio_t* mio
|
||||
);
|
||||
|
||||
MIO_EXPORT void mio_svc_marc_stop (
|
||||
mio_svc_marc_t* marc
|
||||
);
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE mio_t* mio_svc_marc_getmio(mio_svc_marc_t* svc) { return mio_svc_getmio((mio_svc_t*)svc); }
|
||||
#else
|
||||
# define mio_svc_marc_getmio(svc) mio_svc_getmio(svc)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,203 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted mariavided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must remariaduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials mariavided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PIPEVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WAfRRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PIPECUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PIPEFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _MIO_PIPE_H_
|
||||
#define _MIO_PIPE_H_
|
||||
|
||||
#include <mio.h>
|
||||
|
||||
typedef struct mio_dev_maria_t mio_dev_maria_t;
|
||||
|
||||
enum mio_dev_maria_state_t
|
||||
{
|
||||
/* the following items(progress bits) are mutually exclusive */
|
||||
MIO_DEV_MARIA_CONNECTING = (1 << 0),
|
||||
MIO_DEV_MARIA_CONNECTED = (1 << 1),
|
||||
MIO_DEV_MARIA_QUERY_STARTING = (1 << 2),
|
||||
MIO_DEV_MARIA_QUERY_STARTED = (1 << 3),
|
||||
MIO_DEV_MARIA_ROW_FETCHING = (1 << 4),
|
||||
MIO_DEV_MARIA_ROW_FETCHED = (1 << 5),
|
||||
|
||||
|
||||
#if 0
|
||||
/* the following items can be bitwise-ORed with an exclusive item above */
|
||||
MIO_DEV_MARIA_LENIENT = (1 << 14),
|
||||
MIO_DEV_MARIA_INTERCEPTED = (1 << 15),
|
||||
#endif
|
||||
|
||||
/* convenience bit masks */
|
||||
MIO_DEV_MARIA_ALL_PROGRESS_BITS = (MIO_DEV_MARIA_CONNECTING |
|
||||
MIO_DEV_MARIA_CONNECTED |
|
||||
MIO_DEV_MARIA_QUERY_STARTING |
|
||||
MIO_DEV_MARIA_QUERY_STARTED |
|
||||
MIO_DEV_MARIA_ROW_FETCHING |
|
||||
MIO_DEV_MARIA_ROW_FETCHED)
|
||||
};
|
||||
typedef enum mio_dev_maria_state_t mio_dev_maria_state_t;
|
||||
|
||||
#define MIO_DEV_MARIA_SET_PROGRESS(dev,bit) do { \
|
||||
(dev)->state &= ~MIO_DEV_MARIA_ALL_PROGRESS_BITS; \
|
||||
(dev)->state |= (bit); \
|
||||
} while(0)
|
||||
|
||||
#define MIO_DEV_MARIA_GET_PROGRESS(dev) ((dev)->state & MIO_DEV_MARIA_ALL_PROGRESS_BITS)
|
||||
|
||||
|
||||
typedef int (*mio_dev_maria_on_read_t) (
|
||||
mio_dev_maria_t* dev,
|
||||
const void* data,
|
||||
mio_iolen_t len
|
||||
);
|
||||
|
||||
typedef int (*mio_dev_maria_on_write_t) (
|
||||
mio_dev_maria_t* dev,
|
||||
mio_iolen_t wrlen,
|
||||
void* wrctx
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_maria_on_connect_t) (
|
||||
mio_dev_maria_t* dev
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_maria_on_disconnect_t) (
|
||||
mio_dev_maria_t* dev
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_maria_on_query_started_t) (
|
||||
mio_dev_maria_t* dev,
|
||||
int maria_ret
|
||||
);
|
||||
|
||||
typedef void (*mio_dev_maria_on_row_fetched_t) (
|
||||
mio_dev_maria_t* dev,
|
||||
void* row_data
|
||||
);
|
||||
|
||||
struct mio_dev_maria_t
|
||||
{
|
||||
MIO_DEV_HEADER;
|
||||
|
||||
void* hnd;
|
||||
void* res;
|
||||
int state;
|
||||
|
||||
unsigned int connected;
|
||||
unsigned int query_started;
|
||||
unsigned int row_fetched;
|
||||
|
||||
int query_ret;
|
||||
int row_wstatus;
|
||||
void* row;
|
||||
|
||||
mio_dev_maria_on_read_t on_read;
|
||||
mio_dev_maria_on_write_t on_write;
|
||||
mio_dev_maria_on_connect_t on_connect;
|
||||
mio_dev_maria_on_disconnect_t on_disconnect;
|
||||
mio_dev_maria_on_query_started_t on_query_started;
|
||||
mio_dev_maria_on_row_fetched_t on_row_fetched;
|
||||
};
|
||||
|
||||
typedef struct mio_dev_maria_make_t mio_dev_maria_make_t;
|
||||
struct mio_dev_maria_make_t
|
||||
{
|
||||
mio_dev_maria_on_write_t on_write; /* mandatory */
|
||||
mio_dev_maria_on_read_t on_read; /* mandatory */
|
||||
mio_dev_maria_on_connect_t on_connect; /* optional */
|
||||
mio_dev_maria_on_disconnect_t on_disconnect; /* optional */
|
||||
mio_dev_maria_on_query_started_t on_query_started;
|
||||
mio_dev_maria_on_row_fetched_t on_row_fetched;
|
||||
};
|
||||
|
||||
typedef struct mio_dev_maria_connect_t mio_dev_maria_connect_t;
|
||||
struct mio_dev_maria_connect_t
|
||||
{
|
||||
const mio_bch_t* host;
|
||||
const mio_bch_t* username;
|
||||
const mio_bch_t* password;
|
||||
const mio_bch_t* dbname;
|
||||
mio_uint16_t port;
|
||||
};
|
||||
|
||||
enum mio_dev_maria_ioctl_cmd_t
|
||||
{
|
||||
MIO_DEV_MARIA_CONNECT,
|
||||
MIO_DEV_MARIA_QUERY_WITH_BCS,
|
||||
MIO_DEV_MARIA_FETCH_ROW
|
||||
};
|
||||
typedef enum mio_dev_maria_ioctl_cmd_t mio_dev_maria_ioctl_cmd_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MIO_EXPORT mio_dev_maria_t* mio_dev_maria_make (
|
||||
mio_t* mio,
|
||||
mio_oow_t xtnsize,
|
||||
const mio_dev_maria_make_t* data
|
||||
);
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE mio_t* mio_dev_maria_getmio (mio_dev_maria_t* maria) { return mio_dev_getmio((mio_dev_t*)maria); }
|
||||
#else
|
||||
# define mio_dev_maria_getmio(maria) mio_dev_getmio(maria)
|
||||
#endif
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE void* mio_dev_maria_getxtn (mio_dev_maria_t* maria) { return (void*)(maria + 1); }
|
||||
#else
|
||||
# define mio_dev_maria_getxtn(maria) ((void*)(((mio_dev_maria_t*)maria) + 1))
|
||||
#endif
|
||||
|
||||
|
||||
MIO_EXPORT int mio_dev_maria_connect (
|
||||
mio_dev_maria_t* maria,
|
||||
mio_dev_maria_connect_t* ci
|
||||
);
|
||||
|
||||
MIO_EXPORT int mio_dev_maria_querywithbchars (
|
||||
mio_dev_maria_t* maria,
|
||||
const mio_bch_t* qstr,
|
||||
mio_oow_t qlen
|
||||
);
|
||||
|
||||
MIO_EXPORT int mio_dev_maria_fetchrows (
|
||||
mio_dev_maria_t* maria
|
||||
);
|
||||
|
||||
#if defined(MIO_HAVE_INLINE)
|
||||
static MIO_INLINE void mio_dev_maria_kill (mio_dev_maria_t* maria) { mio_dev_kill ((mio_dev_t*)maria); }
|
||||
static MIO_INLINE void mio_dev_maria_halt (mio_dev_maria_t* maria) { mio_dev_halt ((mio_dev_t*)maria); }
|
||||
#else
|
||||
# define mio_dev_maria_kill(maria) mio_dev_kill((mio_dev_t*)maria)
|
||||
# define mio_dev_maria_halt(maria) mio_dev_halt((mio_dev_t*)maria)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user