some code to implement dns over tcp in dnc
This commit is contained in:
parent
c620afe4c9
commit
ef50d2458b
@ -28,3 +28,9 @@ mio_t01_SOURCES = t01.c
|
|||||||
mio_t01_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
mio_t01_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||||
mio_t01_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
mio_t01_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||||
mio_t01_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
mio_t01_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
||||||
|
|
||||||
|
bin_PROGRAMS += mio-t02
|
||||||
|
mio_t02_SOURCES = t02.c
|
||||||
|
mio_t02_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||||
|
mio_t02_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||||
|
mio_t02_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
||||||
|
@ -88,7 +88,7 @@ PRE_UNINSTALL = :
|
|||||||
POST_UNINSTALL = :
|
POST_UNINSTALL = :
|
||||||
build_triplet = @build@
|
build_triplet = @build@
|
||||||
host_triplet = @host@
|
host_triplet = @host@
|
||||||
bin_PROGRAMS = mio-execd$(EXEEXT) mio-t01$(EXEEXT)
|
bin_PROGRAMS = mio-execd$(EXEEXT) mio-t01$(EXEEXT) mio-t02$(EXEEXT)
|
||||||
subdir = bin
|
subdir = bin
|
||||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
|
||||||
@ -126,6 +126,13 @@ mio_t01_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
|
|||||||
mio_t01_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
mio_t01_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||||
$(mio_t01_LDFLAGS) $(LDFLAGS) -o $@
|
$(mio_t01_LDFLAGS) $(LDFLAGS) -o $@
|
||||||
|
am_mio_t02_OBJECTS = mio_t02-t02.$(OBJEXT)
|
||||||
|
mio_t02_OBJECTS = $(am_mio_t02_OBJECTS)
|
||||||
|
mio_t02_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \
|
||||||
|
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
|
||||||
|
mio_t02_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||||
|
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||||
|
$(mio_t02_LDFLAGS) $(LDFLAGS) -o $@
|
||||||
AM_V_P = $(am__v_P_@AM_V@)
|
AM_V_P = $(am__v_P_@AM_V@)
|
||||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||||
am__v_P_0 = false
|
am__v_P_0 = false
|
||||||
@ -142,7 +149,7 @@ DEFAULT_INCLUDES =
|
|||||||
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
|
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
|
||||||
am__maybe_remake_depfiles = depfiles
|
am__maybe_remake_depfiles = depfiles
|
||||||
am__depfiles_remade = ./$(DEPDIR)/mio_execd-execd.Po \
|
am__depfiles_remade = ./$(DEPDIR)/mio_execd-execd.Po \
|
||||||
./$(DEPDIR)/mio_t01-t01.Po
|
./$(DEPDIR)/mio_t01-t01.Po ./$(DEPDIR)/mio_t02-t02.Po
|
||||||
am__mv = mv -f
|
am__mv = mv -f
|
||||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||||
@ -162,8 +169,9 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@)
|
|||||||
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||||
am__v_CCLD_1 =
|
am__v_CCLD_1 =
|
||||||
SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES)
|
SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) $(mio_t02_SOURCES)
|
||||||
DIST_SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES)
|
DIST_SOURCES = $(mio_execd_SOURCES) $(mio_t01_SOURCES) \
|
||||||
|
$(mio_t02_SOURCES)
|
||||||
am__can_run_installinfo = \
|
am__can_run_installinfo = \
|
||||||
case $$AM_UPDATE_INFO_DIR in \
|
case $$AM_UPDATE_INFO_DIR in \
|
||||||
n|no|NO) false;; \
|
n|no|NO) false;; \
|
||||||
@ -361,6 +369,10 @@ mio_t01_SOURCES = t01.c
|
|||||||
mio_t01_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
mio_t01_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||||
mio_t01_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
mio_t01_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||||
mio_t01_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
mio_t01_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
||||||
|
mio_t02_SOURCES = t02.c
|
||||||
|
mio_t02_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||||
|
mio_t02_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||||
|
mio_t02_LDADD = $(LIBADD_LIB_COMMON) -lmio $(SSL_LIBS) $(SOCKET_LIBS) $(SENDFILE_LIBS)
|
||||||
all: all-am
|
all: all-am
|
||||||
|
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
@ -452,6 +464,10 @@ mio-t01$(EXEEXT): $(mio_t01_OBJECTS) $(mio_t01_DEPENDENCIES) $(EXTRA_mio_t01_DEP
|
|||||||
@rm -f mio-t01$(EXEEXT)
|
@rm -f mio-t01$(EXEEXT)
|
||||||
$(AM_V_CCLD)$(mio_t01_LINK) $(mio_t01_OBJECTS) $(mio_t01_LDADD) $(LIBS)
|
$(AM_V_CCLD)$(mio_t01_LINK) $(mio_t01_OBJECTS) $(mio_t01_LDADD) $(LIBS)
|
||||||
|
|
||||||
|
mio-t02$(EXEEXT): $(mio_t02_OBJECTS) $(mio_t02_DEPENDENCIES) $(EXTRA_mio_t02_DEPENDENCIES)
|
||||||
|
@rm -f mio-t02$(EXEEXT)
|
||||||
|
$(AM_V_CCLD)$(mio_t02_LINK) $(mio_t02_OBJECTS) $(mio_t02_LDADD) $(LIBS)
|
||||||
|
|
||||||
mostlyclean-compile:
|
mostlyclean-compile:
|
||||||
-rm -f *.$(OBJEXT)
|
-rm -f *.$(OBJEXT)
|
||||||
|
|
||||||
@ -460,6 +476,7 @@ distclean-compile:
|
|||||||
|
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_execd-execd.Po@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_execd-execd.Po@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t01-t01.Po@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t01-t01.Po@am__quote@ # am--include-marker
|
||||||
|
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mio_t02-t02.Po@am__quote@ # am--include-marker
|
||||||
|
|
||||||
$(am__depfiles_remade):
|
$(am__depfiles_remade):
|
||||||
@$(MKDIR_P) $(@D)
|
@$(MKDIR_P) $(@D)
|
||||||
@ -519,6 +536,20 @@ mio_t01-t01.obj: t01.c
|
|||||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t01-t01.obj `if test -f 't01.c'; then $(CYGPATH_W) 't01.c'; else $(CYGPATH_W) '$(srcdir)/t01.c'; fi`
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t01_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t01-t01.obj `if test -f 't01.c'; then $(CYGPATH_W) 't01.c'; else $(CYGPATH_W) '$(srcdir)/t01.c'; fi`
|
||||||
|
|
||||||
|
mio_t02-t02.o: t02.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t02_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_t02-t02.o -MD -MP -MF $(DEPDIR)/mio_t02-t02.Tpo -c -o mio_t02-t02.o `test -f 't02.c' || echo '$(srcdir)/'`t02.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_t02-t02.Tpo $(DEPDIR)/mio_t02-t02.Po
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t02.c' object='mio_t02-t02.o' libtool=no @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t02_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t02-t02.o `test -f 't02.c' || echo '$(srcdir)/'`t02.c
|
||||||
|
|
||||||
|
mio_t02-t02.obj: t02.c
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t02_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT mio_t02-t02.obj -MD -MP -MF $(DEPDIR)/mio_t02-t02.Tpo -c -o mio_t02-t02.obj `if test -f 't02.c'; then $(CYGPATH_W) 't02.c'; else $(CYGPATH_W) '$(srcdir)/t02.c'; fi`
|
||||||
|
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/mio_t02-t02.Tpo $(DEPDIR)/mio_t02-t02.Po
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='t02.c' object='mio_t02-t02.obj' libtool=no @AMDEPBACKSLASH@
|
||||||
|
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||||
|
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(mio_t02_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o mio_t02-t02.obj `if test -f 't02.c'; then $(CYGPATH_W) 't02.c'; else $(CYGPATH_W) '$(srcdir)/t02.c'; fi`
|
||||||
|
|
||||||
mostlyclean-libtool:
|
mostlyclean-libtool:
|
||||||
-rm -f *.lo
|
-rm -f *.lo
|
||||||
|
|
||||||
@ -654,6 +685,7 @@ clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
|
|||||||
distclean: distclean-am
|
distclean: distclean-am
|
||||||
-rm -f ./$(DEPDIR)/mio_execd-execd.Po
|
-rm -f ./$(DEPDIR)/mio_execd-execd.Po
|
||||||
-rm -f ./$(DEPDIR)/mio_t01-t01.Po
|
-rm -f ./$(DEPDIR)/mio_t01-t01.Po
|
||||||
|
-rm -f ./$(DEPDIR)/mio_t02-t02.Po
|
||||||
-rm -f Makefile
|
-rm -f Makefile
|
||||||
distclean-am: clean-am distclean-compile distclean-generic \
|
distclean-am: clean-am distclean-compile distclean-generic \
|
||||||
distclean-tags
|
distclean-tags
|
||||||
@ -701,6 +733,7 @@ installcheck-am:
|
|||||||
maintainer-clean: maintainer-clean-am
|
maintainer-clean: maintainer-clean-am
|
||||||
-rm -f ./$(DEPDIR)/mio_execd-execd.Po
|
-rm -f ./$(DEPDIR)/mio_execd-execd.Po
|
||||||
-rm -f ./$(DEPDIR)/mio_t01-t01.Po
|
-rm -f ./$(DEPDIR)/mio_t01-t01.Po
|
||||||
|
-rm -f ./$(DEPDIR)/mio_t02-t02.Po
|
||||||
-rm -f Makefile
|
-rm -f Makefile
|
||||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||||
|
|
||||||
|
@ -713,7 +713,6 @@ static void on_dnc_resolve_brief (mio_svc_dnc_t* dnc, mio_dns_msg_t* reqmsg, mio
|
|||||||
|
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
|
||||||
#if 1
|
|
||||||
static mio_t* g_mio;
|
static mio_t* g_mio;
|
||||||
|
|
||||||
static void handle_signal (int sig)
|
static void handle_signal (int sig)
|
||||||
@ -932,7 +931,8 @@ for (i = 0; i < 5; i++)
|
|||||||
|
|
||||||
|
|
||||||
//mio_bcstrtoskad (mio, "8.8.8.8:53", &servaddr);
|
//mio_bcstrtoskad (mio, "8.8.8.8:53", &servaddr);
|
||||||
mio_bcstrtoskad (mio, "[fe80::c7e2:bd6e:1209:ac1b]:1153", &servaddr);
|
//mio_bcstrtoskad (mio, "[fe80::c7e2:bd6e:1209:ac1b]:1153", &servaddr);
|
||||||
|
mio_bcstrtoskad (mio, "[fe80::c7e2:bd6e:1209:ac1b%eno1]:1153", &servaddr);
|
||||||
dnc = mio_svc_dnc_start (mio, &servaddr, MIO_NULL, &send_tmout, &reply_tmout, 2); /* option - send to all, send one by one */
|
dnc = mio_svc_dnc_start (mio, &servaddr, MIO_NULL, &send_tmout, &reply_tmout, 2); /* option - send to all, send one by one */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -1056,59 +1056,3 @@ oops:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
int main (int argc, char* argv[])
|
|
||||||
{
|
|
||||||
mio_t* mio = MIO_NULL;
|
|
||||||
mio_dev_sck_t* tcpsvr;
|
|
||||||
mio_dev_sck_make_t tcp_make;
|
|
||||||
mio_dev_sck_connect_t tcp_conn;
|
|
||||||
tcp_server_t* ts;
|
|
||||||
mio_svc_dnc_t dnc = MIO_NULL;
|
|
||||||
|
|
||||||
mio = mio_open(&mmgr, 0, MIO_NULL, 512, MIO_NULL);
|
|
||||||
if (!mio)
|
|
||||||
{
|
|
||||||
printf ("Cannot open mio\n");
|
|
||||||
goto oops;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset (&tcp_make, 0, MIO_SIZEOF(tcp_make));
|
|
||||||
tcp_make.type = MIO_DEV_SCK_TCP4;
|
|
||||||
tcp_make.on_write = tcp_sck_on_write;
|
|
||||||
tcp_make.on_read = tcp_sck_on_read;
|
|
||||||
tcp_make.on_connect = tcp_sck_on_connect;
|
|
||||||
tcp_make.on_disconnect = tcp_sck_on_disconnect;
|
|
||||||
tcpsvr = mio_dev_sck_make(mio, MIO_SIZEOF(tcp_server_t), &tcp_make);
|
|
||||||
if (!tcpsvr)
|
|
||||||
{
|
|
||||||
printf ("Cannot make a tcp server\n");
|
|
||||||
goto oops;
|
|
||||||
}
|
|
||||||
|
|
||||||
ts = (tcp_server_t*)(tcpsvr + 1);
|
|
||||||
ts->tally = 0;
|
|
||||||
|
|
||||||
memset (&tcp_conn, 0, MIO_SIZEOF(tcp_conn));
|
|
||||||
mio_bcstroskad(mio, "127.0.0.1:9999", &tcp_conn.remoteaddr);
|
|
||||||
|
|
||||||
MIO_INIT_NTIME (&tcp_conn.connect_tmout, 5, 0);
|
|
||||||
tcp_conn.options = 0;
|
|
||||||
if (mio_dev_sck_connect(tcpsvr, &tcp_conn) <= -1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
mio_exec (mio);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
mio_loop (mio);
|
|
||||||
|
|
||||||
oops:
|
|
||||||
if (mio) mio_close (mio);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -56,6 +56,7 @@ struct mio_svc_dnc_t
|
|||||||
struct dnc_sck_xtn_t
|
struct dnc_sck_xtn_t
|
||||||
{
|
{
|
||||||
mio_svc_dnc_t* dnc;
|
mio_svc_dnc_t* dnc;
|
||||||
|
mio_dns_msg_t* reqmsg; /* used when switching to TCP from UDP for truncation */
|
||||||
};
|
};
|
||||||
typedef struct dnc_sck_xtn_t dnc_sck_xtn_t;
|
typedef struct dnc_sck_xtn_t dnc_sck_xtn_t;
|
||||||
|
|
||||||
@ -147,6 +148,118 @@ MIO_DEBUG1 (mio, "releasing dns msg %d\n", (int)mio_ntoh16(mio_dns_msg_to_pkt(ms
|
|||||||
mio_dns_free_msg (dnc->mio, msg);
|
mio_dns_free_msg (dnc->mio, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
static int on_tcp_read (mio_dev_sck_t* dev, const void* data, mio_iolen_t dlen, const mio_skad_t* srcaddr)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int on_tcp_write (mio_dev_sck_t* dev, mio_iolen_t wrlen, void* wrctx, const mio_skad_t* dstaddr)
|
||||||
|
{
|
||||||
|
printf ("ON WRITE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void on_tcp_connect (mio_dev_sck_t* dev)
|
||||||
|
{
|
||||||
|
mio_t* mio = dev->mio;
|
||||||
|
mio_svc_dnc_t* dnc = ((dnc_sck_xtn_t*)mio_dev_sck_getxtn(dev))->dnc;
|
||||||
|
mio_dns_msg_t* reqmsg = ((dnc_sck_xtn_t*)mio_dev_sck_getxtn(dev))->reqmsg;
|
||||||
|
dnc_dns_msg_xtn_t* reqmsgxtn = dnc_dns_msg_getxtn(reqmsg);
|
||||||
|
mio_uint16_t pktlen;
|
||||||
|
|
||||||
|
MIO_ASSERT (mio, dev == dnc->tcp_sck);
|
||||||
|
|
||||||
|
pktlen = mio_hton16(reqmsg->pktlen);
|
||||||
|
|
||||||
|
/* TODO: create writev... which triggered on_write_once */
|
||||||
|
mio_dev_sck_timedwrite(dev, &pktlen, MIO_SIZEOF(pktlen), &reqmsgxtn->rtmout, reqmsg, MIO_NULL);
|
||||||
|
if (mio_dev_sck_timedwrite(dev, mio_dns_msg_to_pkt(reqmsg), reqmsg->pktlen, &reqmsgxtn->rtmout, reqmsg, MIO_NULL) <= -1)
|
||||||
|
{
|
||||||
|
if (MIO_LIKELY(reqmsgxtn->on_reply))
|
||||||
|
reqmsgxtn->on_reply (dnc, reqmsg, mio_geterrnum(mio), MIO_NULL, 0);
|
||||||
|
|
||||||
|
release_dns_msg (dnc, reqmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_tcp_disconnect (mio_dev_sck_t* dev)
|
||||||
|
{
|
||||||
|
mio_t* mio = dev->mio;
|
||||||
|
mio_svc_dnc_t* dnc = ((dnc_sck_xtn_t*)mio_dev_sck_getxtn(dev))->dnc;
|
||||||
|
mio_dns_msg_t* reqmsg = ((dnc_sck_xtn_t*)mio_dev_sck_getxtn(dev))->reqmsg;
|
||||||
|
dnc_dns_msg_xtn_t* reqmsgxtn = dnc_dns_msg_getxtn(reqmsg);
|
||||||
|
int status;
|
||||||
|
|
||||||
|
/* UNABLE TO CONNECT or CONNECT TIMED OUT */
|
||||||
|
if (reqmsgxtn->rtries <= 0)
|
||||||
|
{
|
||||||
|
status = mio_geterrnum(mio);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = mio_geterrnum(mio);
|
||||||
|
}
|
||||||
|
MIO_DEBUG2 (mio, "TCP UNABLED TO CONNECT .. OR DISCONNECTED ... ---> %d -> %js\n", status, mio_errnum_to_errstr(status));
|
||||||
|
|
||||||
|
if (MIO_LIKELY(reqmsgxtn->on_reply))
|
||||||
|
reqmsgxtn->on_reply (dnc, reqmsg, status, MIO_NULL, 0);
|
||||||
|
|
||||||
|
|
||||||
|
release_dns_msg (dnc, reqmsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int switch_reqmsg_transport_to_tcp (mio_svc_dnc_t* dnc, mio_dns_msg_t* reqmsg)
|
||||||
|
{
|
||||||
|
mio_t* mio = dnc->mio;
|
||||||
|
dnc_dns_msg_xtn_t* reqmsgxtn = dnc_dns_msg_getxtn(reqmsg);
|
||||||
|
dnc_sck_xtn_t* sckxtn;
|
||||||
|
|
||||||
|
mio_dev_sck_make_t mkinfo;
|
||||||
|
mio_dev_sck_connect_t cinfo;
|
||||||
|
|
||||||
|
if (!dnc->tcp_sck)
|
||||||
|
{
|
||||||
|
MIO_MEMSET (&mkinfo, 0, MIO_SIZEOF(mkinfo));
|
||||||
|
switch (mio_skad_family(&reqmsgxtn->servaddr))
|
||||||
|
{
|
||||||
|
case MIO_AF_INET:
|
||||||
|
mkinfo.type = MIO_DEV_SCK_TCP4;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MIO_AF_INET6:
|
||||||
|
mkinfo.type = MIO_DEV_SCK_TCP6;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
mio_seterrnum (mio, MIO_EINTERN);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mkinfo.on_write = on_tcp_write;
|
||||||
|
mkinfo.on_read = on_tcp_read;
|
||||||
|
mkinfo.on_connect = on_tcp_connect;
|
||||||
|
mkinfo.on_disconnect = on_tcp_disconnect;
|
||||||
|
dnc->tcp_sck = mio_dev_sck_make(mio, MIO_SIZEOF(*sckxtn), &mkinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
sckxtn = (dnc_sck_xtn_t*)mio_dev_sck_getxtn(dnc->tcp_sck);
|
||||||
|
sckxtn->dnc = dnc;
|
||||||
|
sckxtn->reqmsg = reqmsg;
|
||||||
|
|
||||||
|
MIO_MEMSET (&cinfo, 0, MIO_SIZEOF(cinfo));
|
||||||
|
cinfo.remoteaddr = reqmsgxtn->servaddr;
|
||||||
|
cinfo.connect_tmout = reqmsgxtn->rtmout; /* TOOD: create a separate connect timeout or treate rtmout as a whole transaction time and calculate the remaining time from the transaction start, and use it */
|
||||||
|
|
||||||
|
reqmsgxtn->rtries = 0; /* reset the number of tries back to 0 which means it's never sent over tcp */
|
||||||
|
return mio_dev_sck_connect(dnc->tcp_sck, &cinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int on_udp_read (mio_dev_sck_t* dev, const void* data, mio_iolen_t dlen, const mio_skad_t* srcaddr)
|
static int on_udp_read (mio_dev_sck_t* dev, const void* data, mio_iolen_t dlen, const mio_skad_t* srcaddr)
|
||||||
{
|
{
|
||||||
mio_t* mio = dev->mio;
|
mio_t* mio = dev->mio;
|
||||||
@ -180,10 +293,15 @@ static int on_udp_read (mio_dev_sck_t* dev, const void* data, mio_iolen_t dlen,
|
|||||||
|
|
||||||
if (dev == (mio_dev_sck_t*)reqmsgxtn->dev && pkt->id == reqpkt->id && mio_equal_skads(&reqmsgxtn->servaddr, srcaddr, 0))
|
if (dev == (mio_dev_sck_t*)reqmsgxtn->dev && pkt->id == reqpkt->id && mio_equal_skads(&reqmsgxtn->servaddr, srcaddr, 0))
|
||||||
{
|
{
|
||||||
|
////////////////////////
|
||||||
|
pkt->tc = 1;
|
||||||
|
////////////////////////
|
||||||
if (pkt->tc) /* truncated */
|
if (pkt->tc) /* truncated */
|
||||||
{
|
{
|
||||||
/* TODO: add an option for this behavior */
|
/* TODO: add an option for this behavior */
|
||||||
/* TODO: switch to tc ... send the same request over tcp... */
|
/* TODO: switch to tc ... send the same request over tcp... */
|
||||||
|
switch_reqmsg_transport_to_tcp (dnc, reqmsg);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MIO_DEBUG1 (mio, "received dns response...id %d\n", id);
|
MIO_DEBUG1 (mio, "received dns response...id %d\n", id);
|
||||||
@ -209,6 +327,7 @@ static void on_udp_reply_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob
|
|||||||
mio_svc_dnc_t* dnc = ((dnc_sck_xtn_t*)mio_dev_sck_getxtn(dev))->dnc;
|
mio_svc_dnc_t* dnc = ((dnc_sck_xtn_t*)mio_dev_sck_getxtn(dev))->dnc;
|
||||||
|
|
||||||
MIO_ASSERT (mio, msgxtn->rtmridx == MIO_TMRIDX_INVALID);
|
MIO_ASSERT (mio, msgxtn->rtmridx == MIO_TMRIDX_INVALID);
|
||||||
|
MIO_ASSERT (mio, dev == dnc->udp_sck);
|
||||||
|
|
||||||
MIO_DEBUG0 (mio, "*** TIMEOUT ==> unable to receive dns response in time...\n");
|
MIO_DEBUG0 (mio, "*** TIMEOUT ==> unable to receive dns response in time...\n");
|
||||||
if (msgxtn->rtries < msgxtn->rmaxtries)
|
if (msgxtn->rtries < msgxtn->rmaxtries)
|
||||||
@ -216,7 +335,7 @@ MIO_DEBUG0 (mio, "*** TIMEOUT ==> unable to receive dns response in time...\n");
|
|||||||
mio_ntime_t* tmout;
|
mio_ntime_t* tmout;
|
||||||
|
|
||||||
tmout = MIO_IS_POS_NTIME(&msgxtn->wtmout)? &msgxtn->wtmout: MIO_NULL;
|
tmout = MIO_IS_POS_NTIME(&msgxtn->wtmout)? &msgxtn->wtmout: MIO_NULL;
|
||||||
if (mio_dev_sck_timedwrite(dnc->udp_sck, mio_dns_msg_to_pkt(reqmsg), reqmsg->pktlen, tmout, reqmsg, &msgxtn->servaddr) <= -1)
|
if (mio_dev_sck_timedwrite(dev, mio_dns_msg_to_pkt(reqmsg), reqmsg->pktlen, tmout, reqmsg, &msgxtn->servaddr) <= -1)
|
||||||
{
|
{
|
||||||
if (MIO_LIKELY(msgxtn->on_reply))
|
if (MIO_LIKELY(msgxtn->on_reply))
|
||||||
msgxtn->on_reply (dnc, reqmsg, MIO_ETMOUT, MIO_NULL, 0);
|
msgxtn->on_reply (dnc, reqmsg, MIO_ETMOUT, MIO_NULL, 0);
|
||||||
|
@ -57,6 +57,7 @@ static mio_ooch_t errstr_26[] = {'n', 'o', ' ', 'c', 'a', 'p', 'a', 'b', 'i', 'l
|
|||||||
static mio_ooch_t errstr_27[] = {'t', 'i', 'm', 'e', 'd', ' ', 'o', 'u', 't', '\0' };
|
static mio_ooch_t errstr_27[] = {'t', 'i', 'm', 'e', 'd', ' ', 'o', 'u', 't', '\0' };
|
||||||
static mio_ooch_t errstr_28[] = {'u', 'n', 'a', 'b', 'l', 'e', ' ', 't', 'o', ' ', 'm', 'a', 'k', 'e', ' ', 'd', 'e', 'v', 'i', 'c', 'e', '\0' };
|
static mio_ooch_t errstr_28[] = {'u', 'n', 'a', 'b', 'l', 'e', ' ', 't', 'o', ' ', 'm', 'a', 'k', 'e', ' ', 'd', 'e', 'v', 'i', 'c', 'e', '\0' };
|
||||||
static mio_ooch_t errstr_29[] = {'d', 'e', 'v', 'i', 'c', 'e', ' ', 'e', 'r', 'r', 'o', 'r', '\0' };
|
static mio_ooch_t errstr_29[] = {'d', 'e', 'v', 'i', 'c', 'e', ' ', 'e', 'r', 'r', 'o', 'r', '\0' };
|
||||||
|
static mio_ooch_t errstr_30[] = {'d', 'e', 'v', 'i', 'c', 'e', ' ', 'h', 'a', 'n', 'g', '-', 'u', 'p', '\0' };
|
||||||
static mio_ooch_t* errstr[] =
|
static mio_ooch_t* errstr[] =
|
||||||
{
|
{
|
||||||
errstr_0, errstr_1, errstr_2, errstr_3, errstr_4,
|
errstr_0, errstr_1, errstr_2, errstr_3, errstr_4,
|
||||||
@ -64,7 +65,8 @@ static mio_ooch_t* errstr[] =
|
|||||||
errstr_10, errstr_11, errstr_12, errstr_13, errstr_14,
|
errstr_10, errstr_11, errstr_12, errstr_13, errstr_14,
|
||||||
errstr_15, errstr_16, errstr_17, errstr_18, errstr_19,
|
errstr_15, errstr_16, errstr_17, errstr_18, errstr_19,
|
||||||
errstr_20, errstr_21, errstr_22, errstr_23, errstr_24,
|
errstr_20, errstr_21, errstr_22, errstr_23, errstr_24,
|
||||||
errstr_25, errstr_26, errstr_27, errstr_28, errstr_29
|
errstr_25, errstr_26, errstr_27, errstr_28, errstr_29,
|
||||||
|
errstr_30
|
||||||
};
|
};
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
#
|
#
|
||||||
# qseawk --striprecspace=on -f generr.awk mio.h
|
# hawk -f generr.awk mio.h
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@pragma striprecspc on
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
|
##STRIPRECSPC=1
|
||||||
FS = "[[:space:]]+";
|
FS = "[[:space:]]+";
|
||||||
capture = 0;
|
capture = 0;
|
||||||
msgcount = 0;
|
msgcount = 0;
|
||||||
@ -13,7 +16,7 @@ capture == 1 {
|
|||||||
{
|
{
|
||||||
capture = 0;
|
capture = 0;
|
||||||
}
|
}
|
||||||
else if ($1 ~ /^MIO_E.+,/)
|
else if ($1 ~ /^MIO_E[[:alnum:]]+,*/)
|
||||||
{
|
{
|
||||||
msg = "";
|
msg = "";
|
||||||
for (i = 3; i < NF; i++)
|
for (i = 3; i < NF; i++)
|
||||||
|
@ -47,9 +47,6 @@ static int kill_and_free_device (mio_dev_t* dev, int force);
|
|||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void on_read_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* job);
|
static void on_read_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* job);
|
||||||
static void on_write_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* job);
|
static void on_write_timeout (mio_t* mio, const mio_ntime_t* now, mio_tmrjob_t* job);
|
||||||
|
|
||||||
@ -681,7 +678,6 @@ mio_dev_t* mio_dev_make (mio_t* mio, mio_oow_t dev_size, mio_dev_mth_t* dev_mth,
|
|||||||
APPEND_DEVICE_TO_LIST (&mio->actdev, dev);
|
APPEND_DEVICE_TO_LIST (&mio->actdev, dev);
|
||||||
dev->dev_cap |= MIO_DEV_CAP_ACTIVE;
|
dev->dev_cap |= MIO_DEV_CAP_ACTIVE;
|
||||||
|
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
|
|
||||||
oops_after_make:
|
oops_after_make:
|
||||||
|
@ -1383,16 +1383,19 @@ int mio_skad_ifindex (const mio_skad_t* _skad)
|
|||||||
|
|
||||||
void mio_skad_init_for_ip4 (mio_skad_t* skad, mio_uint16_t port, mio_ip4addr_t* ip4addr)
|
void mio_skad_init_for_ip4 (mio_skad_t* skad, mio_uint16_t port, mio_ip4addr_t* ip4addr)
|
||||||
{
|
{
|
||||||
|
#if (MIO_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||||
struct sockaddr_in* sin = (struct sockaddr_in*)skad;
|
struct sockaddr_in* sin = (struct sockaddr_in*)skad;
|
||||||
|
|
||||||
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
|
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
|
||||||
sin->sin_family = AF_INET;
|
sin->sin_family = AF_INET;
|
||||||
sin->sin_port = htons(port);
|
sin->sin_port = htons(port);
|
||||||
if (ip4addr) MIO_MEMCPY (&sin->sin_addr, ip4addr, MIO_IP4ADDR_LEN);
|
if (ip4addr) MIO_MEMCPY (&sin->sin_addr, ip4addr, MIO_IP4ADDR_LEN);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void mio_skad_init_for_ip6 (mio_skad_t* skad, mio_uint16_t port, mio_ip6addr_t* ip6addr, int scope_id)
|
void mio_skad_init_for_ip6 (mio_skad_t* skad, mio_uint16_t port, mio_ip6addr_t* ip6addr, int scope_id)
|
||||||
{
|
{
|
||||||
|
#if (MIO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||||
struct sockaddr_in6* sin = (struct sockaddr_in6*)skad;
|
struct sockaddr_in6* sin = (struct sockaddr_in6*)skad;
|
||||||
|
|
||||||
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
|
MIO_MEMSET (sin, 0, MIO_SIZEOF(*sin));
|
||||||
@ -1400,6 +1403,7 @@ void mio_skad_init_for_ip6 (mio_skad_t* skad, mio_uint16_t port, mio_ip6addr_t*
|
|||||||
sin->sin6_port = htons(port);
|
sin->sin6_port = htons(port);
|
||||||
sin->sin6_scope_id = scope_id;
|
sin->sin6_scope_id = scope_id;
|
||||||
if (ip6addr) MIO_MEMCPY (&sin->sin6_addr, ip6addr, MIO_IP6ADDR_LEN);
|
if (ip6addr) MIO_MEMCPY (&sin->sin6_addr, ip6addr, MIO_IP6ADDR_LEN);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void mio_skad_init_for_eth (mio_skad_t* skad, int ifindex, mio_ethaddr_t* ethaddr)
|
void mio_skad_init_for_eth (mio_skad_t* skad, int ifindex, mio_ethaddr_t* ethaddr)
|
||||||
@ -1447,11 +1451,13 @@ int mio_equal_skads (const mio_skad_t* addr1, const mio_skad_t* addr2, int stric
|
|||||||
|
|
||||||
switch (f1)
|
switch (f1)
|
||||||
{
|
{
|
||||||
|
#if defined(AF_INET) && (MIO_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return ((struct sockaddr_in*)addr1)->sin_addr.s_addr == ((struct sockaddr_in*)addr2)->sin_addr.s_addr &&
|
return ((struct sockaddr_in*)addr1)->sin_addr.s_addr == ((struct sockaddr_in*)addr2)->sin_addr.s_addr &&
|
||||||
((struct sockaddr_in*)addr1)->sin_port == ((struct sockaddr_in*)addr2)->sin_port;
|
((struct sockaddr_in*)addr1)->sin_port == ((struct sockaddr_in*)addr2)->sin_port;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(AF_INET6)
|
#if defined(AF_INET6) && (MIO_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
|
|
||||||
if (strict)
|
if (strict)
|
||||||
@ -1468,7 +1474,7 @@ int mio_equal_skads (const mio_skad_t* addr1, const mio_skad_t* addr2, int stric
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AF_UNIX)
|
#if defined(AF_UNIX) && (MIO_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
return mio_comp_bcstr(((struct sockaddr_un*)addr1)->sun_path, ((struct sockaddr_un*)addr2)->sun_path) == 0;
|
return mio_comp_bcstr(((struct sockaddr_un*)addr1)->sun_path, ((struct sockaddr_un*)addr2)->sun_path) == 0;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user