renamed stio to mio

This commit is contained in:
2018-12-12 13:06:37 +00:00
parent 60cff400ac
commit daf5143ba3
37 changed files with 0 additions and 0 deletions

2
mio/lib/Makefile Normal file
View File

@ -0,0 +1,2 @@
all:
cc -g -I. -Wall -o stio main.c stio.c stio-tcp.c stio-udp.c stio-sck.c

58
mio/lib/Makefile.am Normal file
View File

@ -0,0 +1,58 @@
AUTOMAKE_OPTIONS = nostdinc
CPPFLAGS_ALL_COMMON = \
-I$(abs_builddir) \
-I$(abs_srcdir) \
-I$(includedir)
LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
##################################################
# MAIN LIBRARY
##################################################
CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(LTDLINCL)
LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined
LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL)
#pkgincludedir = $(includedir)
#pkglibdir = $(libdir)
#pkgbindir = $(bindir)
include_HEADERS = \
stio-cfg.h \
stio-cmn.h \
stio-pro.h \
stio-sck.h \
stio.h
lib_LTLIBRARIES = libstio.la
libstio_la_SOURCES = \
stio-prv.h \
stio.c \
stio-pro.c \
stio-sck.c \
stio-tim.c \
stio-tmr.c \
stio-utl.c
libstio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
libstio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
libstio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS)
bin_PROGRAMS = stio
stio_SOURCES = main.c
stio_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
stio_LDFLAGS = $(LDFLAGS_LIB_COMMON)
stio_LDADD = $(LIBADD_LIB_COMMON) -lstio
install-data-hook:
@echo "#ifndef _STIO_CFG_H_" > "$(DESTDIR)$(includedir)/stio-cfg.h"
@echo "#define _STIO_CFG_H_" >> "$(DESTDIR)$(includedir)/stio-cfg.h"
@$(EGREP) "#define[ ]+STIO_" "$(abs_builddir)/stio-cfg.h" >> "$(DESTDIR)$(includedir)/stio-cfg.h"
@echo "#endif" >> "$(DESTDIR)$(includedir)/stio-cfg.h"
@$(RM) "$(DESTDIR)$(includedir)/stio-cfg.h.in"
@$(SED) 's|/\*#define STIO_HAVE_CFG_H\*/|#define STIO_HAVE_CFG_H|' "$(srcdir)/stio-cmn.h" > "$(DESTDIR)$(includedir)/stio-cmn.h"
uninstall-hook:
@$(RM) "$(DESTDIR)$(includedir)/stio-cfg.h"

831
mio/lib/Makefile.in Normal file
View File

@ -0,0 +1,831 @@
# Makefile.in generated by automake 1.11.6 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
# Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
VPATH = @srcdir@
am__make_dryrun = \
{ \
am__dry=no; \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \
| grep '^AM OK$$' >/dev/null || am__dry=yes;; \
*) \
for am__flg in $$MAKEFLAGS; do \
case $$am__flg in \
*=*|--*) ;; \
*n*) am__dry=yes; break;; \
esac; \
done;; \
esac; \
test $$am__dry = yes; \
}
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = stio$(EXEEXT)
subdir = lib
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/stio-cfg.h.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
$(top_srcdir)/m4/ax_cxx_namespace.m4 \
$(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = stio-cfg.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
*) f=$$p;; \
esac;
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
am__install_max = 40
am__nobase_strip_setup = \
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
am__nobase_strip = \
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
am__nobase_list = $(am__nobase_strip_setup); \
for p in $$list; do echo "$$p $$p"; done | \
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
if (++n[$$2] == $(am__install_max)) \
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
END { for (dir in files) print dir, files[dir] }'
am__base_list = \
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
am__uninstall_files_from_dir = { \
test -z "$$files" \
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
$(am__cd) "$$dir" && rm -f $$files; }; \
}
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \
"$(DESTDIR)$(includedir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 =
am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
libstio_la_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1)
am_libstio_la_OBJECTS = libstio_la-stio.lo libstio_la-stio-pro.lo \
libstio_la-stio-sck.lo libstio_la-stio-tim.lo \
libstio_la-stio-tmr.lo libstio_la-stio-utl.lo
libstio_la_OBJECTS = $(am_libstio_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
libstio_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libstio_la_LDFLAGS) $(LDFLAGS) -o $@
PROGRAMS = $(bin_PROGRAMS)
am_stio_OBJECTS = stio-main.$(OBJEXT)
stio_OBJECTS = $(am_stio_OBJECTS)
stio_DEPENDENCIES = $(am__DEPENDENCIES_2)
stio_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(stio_LDFLAGS) $(LDFLAGS) -o $@
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/ac/depcomp
am__depfiles_maybe = depfiles
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
SOURCES = $(libstio_la_SOURCES) $(stio_SOURCES)
DIST_SOURCES = $(libstio_la_SOURCES) $(stio_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
HEADERS = $(include_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BUILD_MODE = @BUILD_MODE@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
CXXCPP = @CXXCPP@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO = @ECHO@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
GREP = @GREP@
HAVE_CXX = @HAVE_CXX@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBM = @LIBM@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBTOOL = @LIBTOOL@
LIBTOOL_DEPS = @LIBTOOL_DEPS@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_VERSION_MAJOR = @PACKAGE_VERSION_MAJOR@
PACKAGE_VERSION_MINOR = @PACKAGE_VERSION_MINOR@
PACKAGE_VERSION_PATCH = @PACKAGE_VERSION_PATCH@
PATH_SEPARATOR = @PATH_SEPARATOR@
QUADMATH_LIBS = @QUADMATH_LIBS@
RANLIB = @RANLIB@
RM = @RM@
RMDIR = @RMDIR@
SED = @SED@
SENDFILE_LIBS = @SENDFILE_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SOCKET_LIBS = @SOCKET_LIBS@
SSL_LIBS = @SSL_LIBS@
STIO_PROJECT_AUTHOR = @STIO_PROJECT_AUTHOR@
STIO_PROJECT_URL = @STIO_PROJECT_URL@
STIO_SIZEOF_CHAR = @STIO_SIZEOF_CHAR@
STIO_SIZEOF_DOUBLE = @STIO_SIZEOF_DOUBLE@
STIO_SIZEOF_FLOAT = @STIO_SIZEOF_FLOAT@
STIO_SIZEOF_INT = @STIO_SIZEOF_INT@
STIO_SIZEOF_LONG = @STIO_SIZEOF_LONG@
STIO_SIZEOF_LONG_DOUBLE = @STIO_SIZEOF_LONG_DOUBLE@
STIO_SIZEOF_LONG_LONG = @STIO_SIZEOF_LONG_LONG@
STIO_SIZEOF_OFF64_T = @STIO_SIZEOF_OFF64_T@
STIO_SIZEOF_OFF_T = @STIO_SIZEOF_OFF_T@
STIO_SIZEOF_SHORT = @STIO_SIZEOF_SHORT@
STIO_SIZEOF_VOID_P = @STIO_SIZEOF_VOID_P@
STIO_SIZEOF_WCHAR_T = @STIO_SIZEOF_WCHAR_T@
STRIP = @STRIP@
TRUE = @TRUE@
UNICOWS_LIBS = @UNICOWS_LIBS@
VERSION = @VERSION@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = nostdinc
CPPFLAGS_ALL_COMMON = \
-I$(abs_builddir) \
-I$(abs_srcdir) \
-I$(includedir)
LDFLAGS_ALL_COMMON = -L$(abs_builddir) -L$(libdir)
##################################################
# MAIN LIBRARY
##################################################
CPPFLAGS_LIB_COMMON = $(CPPFLAGS_ALL_COMMON) $(LTDLINCL)
LDFLAGS_LIB_COMMON = $(LDFLAGS_ALL_COMMON) -version-info 1:0:0 -no-undefined
LIBADD_LIB_COMMON = $(LIBM) $(LIBLTDL)
#pkgincludedir = $(includedir)
#pkglibdir = $(libdir)
#pkgbindir = $(bindir)
include_HEADERS = \
stio-cfg.h \
stio-cmn.h \
stio-pro.h \
stio-sck.h \
stio.h
lib_LTLIBRARIES = libstio.la
libstio_la_SOURCES = \
stio-prv.h \
stio.c \
stio-pro.c \
stio-sck.c \
stio-tim.c \
stio-tmr.c \
stio-utl.c
libstio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
libstio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
libstio_la_LIBADD = $(LIBADD_LIB_COMMON) $(SSL_LIBS)
stio_SOURCES = main.c
stio_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
stio_LDFLAGS = $(LDFLAGS_LIB_COMMON)
stio_LDADD = $(LIBADD_LIB_COMMON) -lstio
all: stio-cfg.h
$(MAKE) $(AM_MAKEFLAGS) all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign lib/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign lib/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
esac;
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
stio-cfg.h: stamp-h1
@if test ! -f $@; then rm -f stamp-h1; else :; fi
@if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
stamp-h1: $(srcdir)/stio-cfg.h.in $(top_builddir)/config.status
@rm -f stamp-h1
cd $(top_builddir) && $(SHELL) ./config.status lib/stio-cfg.h
$(srcdir)/stio-cfg.h.in: $(am__configure_deps)
($(am__cd) $(top_srcdir) && $(AUTOHEADER))
rm -f stamp-h1
touch $@
distclean-hdr:
-rm -f stio-cfg.h stamp-h1
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
@$(NORMAL_INSTALL)
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
list2=; for p in $$list; do \
if test -f $$p; then \
list2="$$list2 $$p"; \
else :; fi; \
done; \
test -z "$$list2" || { \
echo " $(MKDIR_P) '$(DESTDIR)$(libdir)'"; \
$(MKDIR_P) "$(DESTDIR)$(libdir)" || exit 1; \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(libdir)'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(libdir)"; \
}
uninstall-libLTLIBRARIES:
@$(NORMAL_UNINSTALL)
@list='$(lib_LTLIBRARIES)'; test -n "$(libdir)" || list=; \
for p in $$list; do \
$(am__strip_dir) \
echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$f'"; \
$(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$f"; \
done
clean-libLTLIBRARIES:
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
test "$$dir" != "$$p" || dir=.; \
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libstio.la: $(libstio_la_OBJECTS) $(libstio_la_DEPENDENCIES) $(EXTRA_libstio_la_DEPENDENCIES)
$(AM_V_CCLD)$(libstio_la_LINK) -rpath $(libdir) $(libstio_la_OBJECTS) $(libstio_la_LIBADD) $(LIBS)
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
$(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
fi; \
for p in $$list; do echo "$$p $$p"; done | \
sed 's/$(EXEEXT)$$//' | \
while read p p1; do if test -f $$p || test -f $$p1; \
then echo "$$p"; echo "$$p"; else :; fi; \
done | \
sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
-e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
sed 'N;N;N;s,\n, ,g' | \
$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
{ d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
if ($$2 == $$4) files[d] = files[d] " " $$1; \
else { print "f", $$3 "/" $$4, $$1; } } \
END { for (d in files) print "f", d, files[d] }' | \
while read type dir files; do \
if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
test -z "$$files" || { \
echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
$(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
} \
; done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
files=`for p in $$list; do echo "$$p"; done | \
sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
-e 's/$$/$(EXEEXT)/' `; \
test -n "$$list" || exit 0; \
echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(bindir)" && rm -f $$files
clean-binPROGRAMS:
@list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
stio$(EXEEXT): $(stio_OBJECTS) $(stio_DEPENDENCIES) $(EXTRA_stio_DEPENDENCIES)
@rm -f stio$(EXEEXT)
$(AM_V_CCLD)$(stio_LINK) $(stio_OBJECTS) $(stio_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-pro.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-sck.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tim.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-tmr.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio-utl.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libstio_la-stio.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stio-main.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
libstio_la-stio.lo: stio.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio.Tpo -c -o libstio_la-stio.lo `test -f 'stio.c' || echo '$(srcdir)/'`stio.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio.Tpo $(DEPDIR)/libstio_la-stio.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio.c' object='libstio_la-stio.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) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio.lo `test -f 'stio.c' || echo '$(srcdir)/'`stio.c
libstio_la-stio-pro.lo: stio-pro.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-pro.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-pro.Tpo -c -o libstio_la-stio-pro.lo `test -f 'stio-pro.c' || echo '$(srcdir)/'`stio-pro.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-pro.Tpo $(DEPDIR)/libstio_la-stio-pro.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-pro.c' object='libstio_la-stio-pro.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) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-pro.lo `test -f 'stio-pro.c' || echo '$(srcdir)/'`stio-pro.c
libstio_la-stio-sck.lo: stio-sck.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-sck.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-sck.Tpo -c -o libstio_la-stio-sck.lo `test -f 'stio-sck.c' || echo '$(srcdir)/'`stio-sck.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-sck.Tpo $(DEPDIR)/libstio_la-stio-sck.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-sck.c' object='libstio_la-stio-sck.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) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-sck.lo `test -f 'stio-sck.c' || echo '$(srcdir)/'`stio-sck.c
libstio_la-stio-tim.lo: stio-tim.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-tim.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-tim.Tpo -c -o libstio_la-stio-tim.lo `test -f 'stio-tim.c' || echo '$(srcdir)/'`stio-tim.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-tim.Tpo $(DEPDIR)/libstio_la-stio-tim.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-tim.c' object='libstio_la-stio-tim.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) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-tim.lo `test -f 'stio-tim.c' || echo '$(srcdir)/'`stio-tim.c
libstio_la-stio-tmr.lo: stio-tmr.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-tmr.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-tmr.Tpo -c -o libstio_la-stio-tmr.lo `test -f 'stio-tmr.c' || echo '$(srcdir)/'`stio-tmr.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-tmr.Tpo $(DEPDIR)/libstio_la-stio-tmr.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-tmr.c' object='libstio_la-stio-tmr.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) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-tmr.lo `test -f 'stio-tmr.c' || echo '$(srcdir)/'`stio-tmr.c
libstio_la-stio-utl.lo: stio-utl.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libstio_la-stio-utl.lo -MD -MP -MF $(DEPDIR)/libstio_la-stio-utl.Tpo -c -o libstio_la-stio-utl.lo `test -f 'stio-utl.c' || echo '$(srcdir)/'`stio-utl.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libstio_la-stio-utl.Tpo $(DEPDIR)/libstio_la-stio-utl.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='stio-utl.c' object='libstio_la-stio-utl.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) $(libstio_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libstio_la-stio-utl.lo `test -f 'stio-utl.c' || echo '$(srcdir)/'`stio-utl.c
stio-main.o: main.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stio_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stio-main.o -MD -MP -MF $(DEPDIR)/stio-main.Tpo -c -o stio-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stio-main.Tpo $(DEPDIR)/stio-main.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='stio-main.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) $(stio_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stio-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
stio-main.obj: main.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(stio_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT stio-main.obj -MD -MP -MF $(DEPDIR)/stio-main.Tpo -c -o stio-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/stio-main.Tpo $(DEPDIR)/stio-main.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='main.c' object='stio-main.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) $(stio_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o stio-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
install-includeHEADERS: $(include_HEADERS)
@$(NORMAL_INSTALL)
@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \
$(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \
fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(includedir)'"; \
$(INSTALL_HEADER) $$files "$(DESTDIR)$(includedir)" || exit $$?; \
done
uninstall-includeHEADERS:
@$(NORMAL_UNINSTALL)
@list='$(include_HEADERS)'; test -n "$(includedir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir)
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
TAGS: $(HEADERS) $(SOURCES) stio-cfg.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
set x; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) stio-cfg.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) stio-cfg.h.in $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
list='$(SOURCES) $(HEADERS) stio-cfg.h.in $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) stio-cfg.h
install-binPROGRAMS: install-libLTLIBRARIES
installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-binPROGRAMS clean-generic clean-libLTLIBRARIES \
clean-libtool mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-hdr distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am: install-includeHEADERS
@$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) install-data-hook
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am: install-binPROGRAMS install-libLTLIBRARIES
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \
uninstall-libLTLIBRARIES
@$(NORMAL_INSTALL)
$(MAKE) $(AM_MAKEFLAGS) uninstall-hook
.MAKE: all install-am install-data-am install-strip uninstall-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic clean-libLTLIBRARIES clean-libtool ctags \
distclean distclean-compile distclean-generic distclean-hdr \
distclean-libtool distclean-tags distdir dvi dvi-am html \
html-am info info-am install install-am install-binPROGRAMS \
install-data install-data-am install-data-hook install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-includeHEADERS install-info \
install-info-am install-libLTLIBRARIES install-man install-pdf \
install-pdf-am install-ps install-ps-am install-strip \
installcheck installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-compile \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-binPROGRAMS \
uninstall-hook uninstall-includeHEADERS \
uninstall-libLTLIBRARIES
install-data-hook:
@echo "#ifndef _STIO_CFG_H_" > "$(DESTDIR)$(includedir)/stio-cfg.h"
@echo "#define _STIO_CFG_H_" >> "$(DESTDIR)$(includedir)/stio-cfg.h"
@$(EGREP) "#define[ ]+STIO_" "$(abs_builddir)/stio-cfg.h" >> "$(DESTDIR)$(includedir)/stio-cfg.h"
@echo "#endif" >> "$(DESTDIR)$(includedir)/stio-cfg.h"
@$(RM) "$(DESTDIR)$(includedir)/stio-cfg.h.in"
@$(SED) 's|/\*#define STIO_HAVE_CFG_H\*/|#define STIO_HAVE_CFG_H|' "$(srcdir)/stio-cmn.h" > "$(DESTDIR)$(includedir)/stio-cmn.h"
uninstall-hook:
@$(RM) "$(DESTDIR)$(includedir)/stio-cfg.h"
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

755
mio/lib/main.c Normal file
View File

@ -0,0 +1,755 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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 <stio.h>
#include <stio-sck.h>
#include <stio-pro.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#include <net/if.h>
#include <assert.h>
#if defined(HAVE_OPENSSL_SSL_H) && defined(HAVE_SSL)
# include <openssl/ssl.h>
# if defined(HAVE_OPENSSL_ERR_H)
# include <openssl/err.h>
# endif
# if defined(HAVE_OPENSSL_ENGINE_H)
# include <openssl/engine.h>
# endif
# define USE_SSL
#endif
/* ========================================================================= */
struct mmgr_stat_t
{
stio_size_t total_count;
};
typedef struct mmgr_stat_t mmgr_stat_t;
static mmgr_stat_t mmgr_stat;
static void* mmgr_alloc (stio_mmgr_t* mmgr, stio_size_t size)
{
void* x;
if (((mmgr_stat_t*)mmgr->ctx)->total_count > 300)
{
printf ("CRITICAL ERROR ---> too many heap chunks...\n");
return STIO_NULL;
}
x = malloc (size);
if (x) ((mmgr_stat_t*)mmgr->ctx)->total_count++;
return x;
}
static void* mmgr_realloc (stio_mmgr_t* mmgr, void* ptr, stio_size_t size)
{
return realloc (ptr, size);
}
static void mmgr_free (stio_mmgr_t* mmgr, void* ptr)
{
((mmgr_stat_t*)mmgr->ctx)->total_count--;
return free (ptr);
}
static stio_mmgr_t mmgr =
{
mmgr_alloc,
mmgr_realloc,
mmgr_free,
&mmgr_stat
};
/* ========================================================================= */
#if defined(USE_SSL)
static void cleanup_openssl ()
{
/* ERR_remove_state() should be called for each thread if the application is thread */
ERR_remove_state (0);
#if defined(HAVE_ENGINE_CLEANUP)
ENGINE_cleanup ();
#endif
ERR_free_strings ();
EVP_cleanup ();
#if defined(HAVE_CRYPTO_CLEANUP_ALL_EX_DATA)
CRYPTO_cleanup_all_ex_data ();
#endif
}
#endif
struct tcp_server_t
{
int tally;
};
typedef struct tcp_server_t tcp_server_t;
static void tcp_sck_on_disconnect (stio_dev_sck_t* tcp)
{
switch (STIO_DEV_SCK_GET_PROGRESS(tcp))
{
case STIO_DEV_SCK_CONNECTING:
printf ("OUTGOING SESSION DISCONNECTED - FAILED TO CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck);
break;
case STIO_DEV_SCK_CONNECTING_SSL:
printf ("OUTGOING SESSION DISCONNECTED - FAILED TO SSL-CONNECT (%d) TO REMOTE SERVER\n", (int)tcp->sck);
break;
case STIO_DEV_SCK_LISTENING:
printf ("SHUTTING DOWN THE SERVER SOCKET(%d)...\n", (int)tcp->sck);
break;
case STIO_DEV_SCK_CONNECTED:
printf ("OUTGOING CLIENT CONNECTION GOT TORN DOWN(%d).......\n", (int)tcp->sck);
break;
case STIO_DEV_SCK_ACCEPTING_SSL:
printf ("INCOMING SSL-ACCEPT GOT DISCONNECTED(%d) ....\n", (int)tcp->sck);
break;
case STIO_DEV_SCK_ACCEPTED:
printf ("INCOMING CLIENT BEING SERVED GOT DISCONNECTED(%d).......\n", (int)tcp->sck);
break;
default:
printf ("SOCKET DEVICE DISCONNECTED (%d - %x)\n", (int)tcp->sck, (unsigned int)tcp->state);
break;
}
}
static int tcp_sck_on_connect (stio_dev_sck_t* tcp)
{
stio_sckfam_t fam;
stio_scklen_t len;
stio_mchar_t buf1[128], buf2[128];
memset (buf1, 0, STIO_SIZEOF(buf1));
memset (buf2, 0, STIO_SIZEOF(buf2));
stio_getsckaddrinfo (tcp->stio, &tcp->localaddr, &len, &fam);
inet_ntop (fam, tcp->localaddr.data, buf1, STIO_COUNTOF(buf1));
stio_getsckaddrinfo (tcp->stio, &tcp->remoteaddr, &len, &fam);
inet_ntop (fam, tcp->remoteaddr.data, buf2, STIO_COUNTOF(buf2));
if (tcp->state & STIO_DEV_SCK_CONNECTED)
{
printf ("device connected to a remote server... LOCAL %s:%d REMOTE %s:%d.", buf1, stio_getsckaddrport(&tcp->localaddr), buf2, stio_getsckaddrport(&tcp->remoteaddr));
}
else if (tcp->state & STIO_DEV_SCK_ACCEPTED)
{
printf ("device accepted client device... .LOCAL %s:%d REMOTE %s:%d\n", buf1, stio_getsckaddrport(&tcp->localaddr), buf2, stio_getsckaddrport(&tcp->remoteaddr));
}
return stio_dev_sck_write (tcp, "hello", 5, STIO_NULL, STIO_NULL);
}
static int tcp_sck_on_write (stio_dev_sck_t* tcp, stio_iolen_t wrlen, void* wrctx, const stio_sckaddr_t* dstaddr)
{
tcp_server_t* ts;
if (wrlen <= -1)
{
printf ("SEDING TIMED OUT...........\n");
stio_dev_sck_halt(tcp);
}
else
{
ts = (tcp_server_t*)(tcp + 1);
printf (">>> SENT MESSAGE %d of length %ld\n", ts->tally, (long int)wrlen);
ts->tally++;
// if (ts->tally >= 2) stio_dev_sck_halt (tcp);
printf ("ENABLING READING..............................\n");
stio_dev_sck_read (tcp, 1);
//stio_dev_sck_timedread (tcp, 1, 1000);
}
return 0;
}
static int tcp_sck_on_read (stio_dev_sck_t* tcp, const void* buf, stio_iolen_t len, const stio_sckaddr_t* srcaddr)
{
int n;
if (len <= 0)
{
printf ("STREAM DEVICE: EOF RECEIVED...\n");
/* no outstanding request. but EOF */
stio_dev_sck_halt (tcp);
return 0;
}
printf ("on read %d\n", (int)len);
{
stio_ntime_t tmout;
static char a ='A';
char* xxx = malloc (1000000);
memset (xxx, a++ ,1000000);
//return stio_dev_sck_write (tcp, "HELLO", 5, STIO_NULL);
stio_inittime (&tmout, 5, 0);
n = stio_dev_sck_timedwrite (tcp, xxx, 1000000, &tmout, STIO_NULL, STIO_NULL);
free (xxx);
if (n <= -1) return -1;
}
printf ("DISABLING READING..............................\n");
stio_dev_sck_read (tcp, 0);
/* post the write finisher */
n = stio_dev_sck_write (tcp, STIO_NULL, 0, STIO_NULL, STIO_NULL);
if (n <= -1) return -1;
return 0;
/* return 1; let the main loop to read more greedily without consulting the multiplexer */
}
/* ========================================================================= */
static void pro_on_close (stio_dev_pro_t* dev, stio_dev_pro_sid_t sid)
{
printf (">>>>>>>>>>>>> ON CLOSE OF SLAVE %d.\n", sid);
}
static int pro_on_read (stio_dev_pro_t* dev, const void* data, stio_iolen_t dlen, stio_dev_pro_sid_t sid)
{
printf ("PROCESS READ DATA on SLAVE[%d]... [%.*s]\n", (int)sid, (int)dlen, (char*)data);
return 0;
}
static int pro_on_write (stio_dev_pro_t* dev, stio_iolen_t wrlen, void* wrctx)
{
printf ("PROCESS WROTE DATA...\n");
return 0;
}
/* ========================================================================= */
static int arp_sck_on_read (stio_dev_sck_t* dev, const void* data, stio_iolen_t dlen, const stio_sckaddr_t* srcaddr)
{
stio_etharp_pkt_t* eap;
if (dlen < STIO_SIZEOF(*eap)) return 0; /* drop */
eap = (stio_etharp_pkt_t*)data;
printf ("ARP ON IFINDEX %d OPCODE: %d", stio_getsckaddrifindex(srcaddr), ntohs(eap->arphdr.opcode));
printf (" SHA: %02X:%02X:%02X:%02X:%02X:%02X", eap->arppld.sha[0], eap->arppld.sha[1], eap->arppld.sha[2], eap->arppld.sha[3], eap->arppld.sha[4], eap->arppld.sha[5]);
printf (" SPA: %d.%d.%d.%d", eap->arppld.spa[0], eap->arppld.spa[1], eap->arppld.spa[2], eap->arppld.spa[3]);
printf (" THA: %02X:%02X:%02X:%02X:%02X:%02X", eap->arppld.tha[0], eap->arppld.tha[1], eap->arppld.tha[2], eap->arppld.tha[3], eap->arppld.tha[4], eap->arppld.tha[5]);
printf (" TPA: %d.%d.%d.%d", eap->arppld.tpa[0], eap->arppld.tpa[1], eap->arppld.tpa[2], eap->arppld.tpa[3]);
printf ("\n");
return 0;
}
static int arp_sck_on_write (stio_dev_sck_t* dev, stio_iolen_t wrlen, void* wrctx, const stio_sckaddr_t* dstaddr)
{
return 0;
}
static void arp_sck_on_disconnect (stio_dev_sck_t* dev)
{
printf ("SHUTTING DOWN ARP SOCKET %d...\n", dev->sck);
}
static int setup_arp_tester (stio_t* stio)
{
stio_sckaddr_t ethdst;
stio_etharp_pkt_t etharp;
stio_dev_sck_make_t sck_make;
stio_dev_sck_t* sck;
memset (&sck_make, 0, STIO_SIZEOF(sck_make));
sck_make.type = STIO_DEV_SCK_ARP;
//sck_make.type = STIO_DEV_SCK_ARP_DGRAM;
sck_make.on_write = arp_sck_on_write;
sck_make.on_read = arp_sck_on_read;
sck_make.on_disconnect = arp_sck_on_disconnect;
sck = stio_dev_sck_make (stio, 0, &sck_make);
if (!sck)
{
printf ("Cannot make socket device\n");
return -1;
}
//stio_sckaddr_initforeth (&ethdst, if_nametoindex("enp0s25.3"), (stio_ethaddr_t*)"\xFF\xFF\xFF\xFF\xFF\xFF");
stio_sckaddr_initforeth (&ethdst, if_nametoindex("enp0s25.3"), (stio_ethaddr_t*)"\xAA\xBB\xFF\xCC\xDD\xFF");
memset (&etharp, 0, sizeof(etharp));
memcpy (etharp.ethhdr.source, "\xB8\x6B\x23\x9C\x10\x76", STIO_ETHADDR_LEN);
//memcpy (etharp.ethhdr.dest, "\xFF\xFF\xFF\xFF\xFF\xFF", STIO_ETHADDR_LEN);
memcpy (etharp.ethhdr.dest, "\xAA\xBB\xFF\xCC\xDD\xFF", STIO_ETHADDR_LEN);
etharp.ethhdr.proto = STIO_CONST_HTON16(STIO_ETHHDR_PROTO_ARP);
etharp.arphdr.htype = STIO_CONST_HTON16(STIO_ARPHDR_HTYPE_ETH);
etharp.arphdr.ptype = STIO_CONST_HTON16(STIO_ARPHDR_PTYPE_IP4);
etharp.arphdr.hlen = STIO_ETHADDR_LEN;
etharp.arphdr.plen = STIO_IP4ADDR_LEN;
etharp.arphdr.opcode = STIO_CONST_HTON16(STIO_ARPHDR_OPCODE_REQUEST);
memcpy (etharp.arppld.sha, "\xB8\x6B\x23\x9C\x10\x76", STIO_ETHADDR_LEN);
if (stio_dev_sck_write (sck, &etharp, sizeof(etharp), NULL, &ethdst) <= -1)
//if (stio_dev_sck_write (sck, &etharp.arphdr, sizeof(etharp) - sizeof(etharp.ethhdr), NULL, &ethaddr) <= -1)
{
printf ("CANNOT WRITE ARP...\n");
}
return 0;
}
/* ========================================================================= */
struct icmpxtn_t
{
stio_uint16_t icmp_seq;
stio_tmridx_t tmout_jobidx;
int reply_received;
};
typedef struct icmpxtn_t icmpxtn_t;
static int schedule_icmp_wait (stio_dev_sck_t* dev);
static void send_icmp (stio_dev_sck_t* dev, stio_uint16_t seq)
{
stio_sckaddr_t dstaddr;
stio_ip4addr_t ia;
stio_icmphdr_t* icmphdr;
stio_uint8_t buf[512];
inet_pton (AF_INET, "192.168.1.131", &ia);
stio_sckaddr_initforip4 (&dstaddr, 0, &ia);
memset(buf, 0, STIO_SIZEOF(buf));
icmphdr = (stio_icmphdr_t*)buf;
icmphdr->type = STIO_ICMP_ECHO_REQUEST;
icmphdr->u.echo.id = STIO_CONST_HTON16(100);
icmphdr->u.echo.seq = stio_hton16(seq);
memset (&buf[STIO_SIZEOF(*icmphdr)], 'A', STIO_SIZEOF(buf) - STIO_SIZEOF(*icmphdr));
icmphdr->checksum = stio_checksumip (icmphdr, STIO_SIZEOF(buf));
if (stio_dev_sck_write (dev, buf, STIO_SIZEOF(buf), NULL, &dstaddr) <= -1)
{
printf ("CANNOT WRITE ICMP...\n");
stio_dev_sck_halt (dev);
}
if (schedule_icmp_wait (dev) <= -1)
{
printf ("CANNOT SCHEDULE ICMP WAIT...\n");
stio_dev_sck_halt (dev);
}
}
static void on_icmp_due (stio_t* stio, const stio_ntime_t* now, stio_tmrjob_t* tmrjob)
{
stio_dev_sck_t* dev;
icmpxtn_t* icmpxtn;
dev = tmrjob->ctx;
icmpxtn = (icmpxtn_t*)(dev + 1);
if (icmpxtn->reply_received)
icmpxtn->reply_received = 0;
else
printf ("NO ICMP REPLY RECEIVED....\n");
send_icmp (dev, ++icmpxtn->icmp_seq);
}
static int schedule_icmp_wait (stio_dev_sck_t* dev)
{
icmpxtn_t* icmpxtn;
stio_tmrjob_t tmrjob;
stio_ntime_t fire_after;
icmpxtn = (icmpxtn_t*)(dev + 1);
stio_inittime (&fire_after, 2, 0);
memset (&tmrjob, 0, STIO_SIZEOF(tmrjob));
tmrjob.ctx = dev;
stio_gettime (&tmrjob.when);
stio_addtime (&tmrjob.when, &fire_after, &tmrjob.when);
tmrjob.handler = on_icmp_due;
tmrjob.idxptr = &icmpxtn->tmout_jobidx;
assert (icmpxtn->tmout_jobidx == STIO_TMRIDX_INVALID);
return (stio_instmrjob (dev->stio, &tmrjob) == STIO_TMRIDX_INVALID)? -1: 0;
}
static int icmp_sck_on_read (stio_dev_sck_t* dev, const void* data, stio_iolen_t dlen, const stio_sckaddr_t* srcaddr)
{
icmpxtn_t* icmpxtn;
stio_iphdr_t* iphdr;
stio_icmphdr_t* icmphdr;
/* when received, the data contains the IP header.. */
icmpxtn = (icmpxtn_t*)(dev + 1);
if (dlen < STIO_SIZEOF(*iphdr) + STIO_SIZEOF(*icmphdr))
{
printf ("INVALID ICMP PACKET.. TOO SHORT...%d\n", (int)dlen);
}
else
{
/* TODO: consider IP options... */
iphdr = (stio_iphdr_t*)data;
if (iphdr->ihl * 4 + STIO_SIZEOF(*icmphdr) > dlen)
{
printf ("INVALID ICMP PACKET.. WRONG IHL...%d\n", (int)iphdr->ihl * 4);
}
else
{
icmphdr = (stio_icmphdr_t*)((stio_uint8_t*)data + (iphdr->ihl * 4));
/* TODO: check srcaddr against target */
if (icmphdr->type == STIO_ICMP_ECHO_REPLY &&
stio_ntoh16(icmphdr->u.echo.seq) == icmpxtn->icmp_seq) /* TODO: more check.. echo.id.. */
{
icmpxtn->reply_received = 1;
printf ("ICMP REPLY RECEIVED...ID %d SEQ %d\n", (int)stio_ntoh16(icmphdr->u.echo.id), (int)stio_ntoh16(icmphdr->u.echo.seq));
}
else
{
printf ("GARBAGE ICMP PACKET...LEN %d SEQ %d,%d\n", (int)dlen, (int)icmpxtn->icmp_seq, (int)stio_ntoh16(icmphdr->u.echo.seq));
}
}
}
return 0;
}
static int icmp_sck_on_write (stio_dev_sck_t* dev, stio_iolen_t wrlen, void* wrctx, const stio_sckaddr_t* dstaddr)
{
/*icmpxtn_t* icmpxtn;
icmpxtn = (icmpxtn_t*)(dev + 1); */
return 0;
}
static void icmp_sck_on_disconnect (stio_dev_sck_t* dev)
{
icmpxtn_t* icmpxtn;
icmpxtn = (icmpxtn_t*)(dev + 1);
printf ("SHUTTING DOWN ICMP SOCKET %d...\n", dev->sck);
if (icmpxtn->tmout_jobidx != STIO_TMRIDX_INVALID)
{
stio_deltmrjob (dev->stio, icmpxtn->tmout_jobidx);
icmpxtn->tmout_jobidx = STIO_TMRIDX_INVALID;
}
}
static int setup_ping4_tester (stio_t* stio)
{
stio_dev_sck_make_t sck_make;
stio_dev_sck_t* sck;
icmpxtn_t* icmpxtn;
memset (&sck_make, 0, STIO_SIZEOF(sck_make));
sck_make.type = STIO_DEV_SCK_ICMP4;
sck_make.on_write = icmp_sck_on_write;
sck_make.on_read = icmp_sck_on_read;
sck_make.on_disconnect = icmp_sck_on_disconnect;
sck = stio_dev_sck_make (stio, STIO_SIZEOF(icmpxtn_t), &sck_make);
if (!sck)
{
printf ("Cannot make ICMP4 socket device\n");
return -1;
}
icmpxtn = (icmpxtn_t*)(sck + 1);
icmpxtn->tmout_jobidx = STIO_TMRIDX_INVALID;
icmpxtn->icmp_seq = 0;
/*TODO: stio_dev_sck_setbroadcast (sck, 1);*/
send_icmp (sck, ++icmpxtn->icmp_seq);
return 0;
}
/* ========================================================================= */
static stio_t* g_stio;
static void handle_signal (int sig)
{
if (g_stio) stio_stop (g_stio, STIO_STOPREQ_TERMINATION);
}
int main ()
{
int i;
stio_t* stio;
stio_dev_sck_t* tcp[3];
struct sigaction sigact;
stio_dev_sck_connect_t tcp_conn;
stio_dev_sck_listen_t tcp_lstn;
stio_dev_sck_bind_t tcp_bind;
stio_dev_sck_make_t tcp_make;
tcp_server_t* ts;
#if defined(USE_SSL)
SSL_load_error_strings ();
SSL_library_init ();
#endif
stio = stio_open (&mmgr, 0, 512, STIO_NULL);
if (!stio)
{
printf ("Cannot open stio\n");
return -1;
}
g_stio = stio;
memset (&sigact, 0, STIO_SIZEOF(sigact));
sigact.sa_flags = SA_RESTART;
sigact.sa_handler = handle_signal;
sigaction (SIGINT, &sigact, STIO_NULL);
memset (&sigact, 0, STIO_SIZEOF(sigact));
sigact.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sigact, STIO_NULL);
/*
memset (&sigact, 0, STIO_SIZEOF(sigact));
sigact.sa_handler = SIG_IGN;
sigaction (SIGCHLD, &sigact, STIO_NULL);
*/
/*memset (&sin, 0, STIO_SIZEOF(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(1234); */
/*
udp = (stio_dev_udp_t*)stio_makedev (stio, STIO_SIZEOF(*udp), &udp_mth, &udp_evcb, &sin);
if (!udp)
{
printf ("Cannot make udp\n");
goto oops;
}
*/
memset (&tcp_make, 0, STIO_SIZEOF(&tcp_make));
tcp_make.type = STIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read;
tcp_make.on_disconnect = tcp_sck_on_disconnect;
tcp[0] = stio_dev_sck_make (stio, STIO_SIZEOF(tcp_server_t), &tcp_make);
if (!tcp[0])
{
printf ("Cannot make tcp\n");
goto oops;
}
ts = (tcp_server_t*)(tcp[0] + 1);
ts->tally = 0;
memset (&tcp_conn, 0, STIO_SIZEOF(tcp_conn));
{
in_addr_t ia = inet_addr("192.168.1.119");
stio_sckaddr_initforip4 (&tcp_conn.remoteaddr, 9999, (stio_ip4addr_t*)&ia);
}
stio_inittime (&tcp_conn.connect_tmout, 5, 0);
tcp_conn.on_connect = tcp_sck_on_connect;
tcp_conn.options = STIO_DEV_SCK_CONNECT_SSL;
if (stio_dev_sck_connect (tcp[0], &tcp_conn) <= -1)
{
printf ("stio_dev_sck_connect() failed....\n");
/* carry on regardless of failure */
}
/* -------------------------------------------------------------- */
memset (&tcp_make, 0, STIO_SIZEOF(&tcp_make));
tcp_make.type = STIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read;
tcp_make.on_disconnect = tcp_sck_on_disconnect;
tcp[1] = stio_dev_sck_make (stio, STIO_SIZEOF(tcp_server_t), &tcp_make);
if (!tcp[1])
{
printf ("Cannot make tcp\n");
goto oops;
}
ts = (tcp_server_t*)(tcp[1] + 1);
ts->tally = 0;
memset (&tcp_bind, 0, STIO_SIZEOF(tcp_bind));
stio_sckaddr_initforip4 (&tcp_bind.localaddr, 1234, STIO_NULL);
tcp_bind.options = STIO_DEV_SCK_BIND_REUSEADDR;
if (stio_dev_sck_bind (tcp[1],&tcp_bind) <= -1)
{
printf ("stio_dev_sck_bind() failed....\n");
goto oops;
}
tcp_lstn.backlogs = 100;
tcp_lstn.on_connect = tcp_sck_on_connect;
if (stio_dev_sck_listen (tcp[1], &tcp_lstn) <= -1)
{
printf ("stio_dev_sck_listen() failed....\n");
goto oops;
}
/* -------------------------------------------------------------- */
memset (&tcp_make, 0, STIO_SIZEOF(&tcp_make));
tcp_make.type = STIO_DEV_SCK_TCP4;
tcp_make.on_write = tcp_sck_on_write;
tcp_make.on_read = tcp_sck_on_read;
tcp_make.on_disconnect = tcp_sck_on_disconnect;
tcp[2] = stio_dev_sck_make (stio, STIO_SIZEOF(tcp_server_t), &tcp_make);
if (!tcp[2])
{
printf ("Cannot make tcp\n");
goto oops;
}
ts = (tcp_server_t*)(tcp[2] + 1);
ts->tally = 0;
memset (&tcp_bind, 0, STIO_SIZEOF(tcp_bind));
stio_sckaddr_initforip4 (&tcp_bind.localaddr, 1235, STIO_NULL);
tcp_bind.options = STIO_DEV_SCK_BIND_REUSEADDR | /*STIO_DEV_SCK_BIND_REUSEPORT |*/ STIO_DEV_SCK_BIND_SSL;
tcp_bind.ssl_certfile = STIO_MT("localhost.crt");
tcp_bind.ssl_keyfile = STIO_MT("localhost.key");
stio_inittime (&tcp_bind.accept_tmout, 5, 1);
if (stio_dev_sck_bind (tcp[2],&tcp_bind) <= -1)
{
printf ("stio_dev_sck_bind() failed....\n");
goto oops;
}
tcp_lstn.backlogs = 100;
tcp_lstn.on_connect = tcp_sck_on_connect;
if (stio_dev_sck_listen (tcp[2], &tcp_lstn) <= -1)
{
printf ("stio_dev_sck_listen() failed....\n");
goto oops;
}
//stio_dev_sck_sendfile (tcp[2], fd, offset, count);
if (setup_arp_tester(stio) <= -1) goto oops;
if (setup_ping4_tester(stio) <= -1) goto oops;
for (i = 0; i < 5; i++)
{
stio_dev_pro_t* pro;
stio_dev_pro_make_t pro_make;
memset (&pro_make, 0, STIO_SIZEOF(pro_make));
pro_make.flags = STIO_DEV_PRO_READOUT | STIO_DEV_PRO_READERR | STIO_DEV_PRO_WRITEIN /*| STIO_DEV_PRO_FORGET_CHILD*/;
//pro_make.cmd = "/bin/ls -laF /usr/bin";
//pro_make.cmd = "/bin/ls -laF";
pro_make.cmd = "./a";
pro_make.on_read = pro_on_read;
pro_make.on_write = pro_on_write;
pro_make.on_close = pro_on_close;
pro = stio_dev_pro_make (stio, 0, &pro_make);
if (!pro)
{
printf ("CANNOT CREATE PROCESS PIPE\n");
goto oops;
}
stio_dev_pro_write (pro, "MY STIO LIBRARY\n", 16, STIO_NULL);
//stio_dev_pro_killchild (pro);
//stio_dev_pro_close (pro, STIO_DEV_PRO_IN);
//stio_dev_pro_close (pro, STIO_DEV_PRO_OUT);
//stio_dev_pro_close (pro, STIO_DEV_PRO_ERR);
}
stio_loop (stio);
g_stio = STIO_NULL;
stio_close (stio);
#if defined(USE_SSL)
cleanup_openssl ();
#endif
return 0;
oops:
g_stio = STIO_NULL;
stio_close (stio);
#if defined(USE_SSL)
cleanup_openssl ();
#endif
return -1;
}

959
mio/lib/stio-cfg.h.in Normal file
View File

@ -0,0 +1,959 @@
/* lib/stio-cfg.h.in. Generated from configure.ac by autoheader. */
/* Define if building universal (internal helper macro) */
#undef AC_APPLE_UNIVERSAL_BUILD
/* Define to 1 if you have the `acos' function. */
#undef HAVE_ACOS
/* Define to 1 if you have the `acosf' function. */
#undef HAVE_ACOSF
/* Define to 1 if you have the `acosl' function. */
#undef HAVE_ACOSL
/* Define to 1 if you have the `acosq' function. */
#undef HAVE_ACOSQ
/* Define to 1 if you have the `asin' function. */
#undef HAVE_ASIN
/* Define to 1 if you have the `asinf' function. */
#undef HAVE_ASINF
/* Define to 1 if you have the `asinl' function. */
#undef HAVE_ASINL
/* Define to 1 if you have the `asinq' function. */
#undef HAVE_ASINQ
/* Define to 1 if you have the `atan' function. */
#undef HAVE_ATAN
/* Define to 1 if you have the `atan2' function. */
#undef HAVE_ATAN2
/* Define to 1 if you have the `atan2f' function. */
#undef HAVE_ATAN2F
/* Define to 1 if you have the `atan2l' function. */
#undef HAVE_ATAN2L
/* Define to 1 if you have the `atan2q' function. */
#undef HAVE_ATAN2Q
/* Define to 1 if you have the `atanf' function. */
#undef HAVE_ATANF
/* Define to 1 if you have the `atanl' function. */
#undef HAVE_ATANL
/* Define to 1 if you have the `atanq' function. */
#undef HAVE_ATANQ
/* Define to 1 if you have the `backtrace' function. */
#undef HAVE_BACKTRACE
/* Define to 1 if you have the `backtrace_symbols' function. */
#undef HAVE_BACKTRACE_SYMBOLS
/* Define to 1 if you have the `ceil' function. */
#undef HAVE_CEIL
/* Define to 1 if you have the `ceilf' function. */
#undef HAVE_CEILF
/* Define to 1 if you have the `ceill' function. */
#undef HAVE_CEILL
/* Define to 1 if you have the `ceilq' function. */
#undef HAVE_CEILQ
/* Define to 1 if you have the `clock_gettime' function. */
#undef HAVE_CLOCK_GETTIME
/* Define to 1 if you have the `clock_settime' function. */
#undef HAVE_CLOCK_SETTIME
/* Define to 1 if you have the `connect' function. */
#undef HAVE_CONNECT
/* Define to 1 if you have the `cos' function. */
#undef HAVE_COS
/* Define to 1 if you have the `cosf' function. */
#undef HAVE_COSF
/* Define to 1 if you have the `cosh' function. */
#undef HAVE_COSH
/* Define to 1 if you have the `coshf' function. */
#undef HAVE_COSHF
/* Define to 1 if you have the `coshl' function. */
#undef HAVE_COSHL
/* Define to 1 if you have the `coshq' function. */
#undef HAVE_COSHQ
/* Define to 1 if you have the `cosl' function. */
#undef HAVE_COSL
/* Define to 1 if you have the `cosq' function. */
#undef HAVE_COSQ
/* Define to 1 if you have the <crt_externs.h> header file. */
#undef HAVE_CRT_EXTERNS_H
/* Define to 1 if you have the `CRYPTO_cleanup_all_ex_data' function. */
#undef HAVE_CRYPTO_CLEANUP_ALL_EX_DATA
/* Define if c++ supports namespace std. */
#undef HAVE_CXX_NAMESPACE_STD
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the `dirfd' function. */
#undef HAVE_DIRFD
/* Define to 1 if `dd_fd' is a member of `DIR'. */
#undef HAVE_DIR_DD_FD
/* Define to 1 if `d_fd' is a member of `DIR'. */
#undef HAVE_DIR_D_FD
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the `ENGINE_cleanup' function. */
#undef HAVE_ENGINE_CLEANUP
/* epoll support */
#undef HAVE_EPOLL
/* Define to 1 if you have the `epoll_create' function. */
#undef HAVE_EPOLL_CREATE
/* Define to 1 if you have the `epoll_create1' function. */
#undef HAVE_EPOLL_CREATE1
/* Define to 1 if you have the <errno.h> header file. */
#undef HAVE_ERRNO_H
/* Define to 1 if you have the <execinfo.h> header file. */
#undef HAVE_EXECINFO_H
/* Define to 1 if you have the `exp' function. */
#undef HAVE_EXP
/* Define to 1 if you have the `expf' function. */
#undef HAVE_EXPF
/* Define to 1 if you have the `expl' function. */
#undef HAVE_EXPL
/* Define to 1 if you have the `expq' function. */
#undef HAVE_EXPQ
/* Define to 1 if you have the `fchmod' function. */
#undef HAVE_FCHMOD
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define to 1 if you have the `fdopendir' function. */
#undef HAVE_FDOPENDIR
/* Define to 1 if you have the `floor' function. */
#undef HAVE_FLOOR
/* Define to 1 if you have the `floorf' function. */
#undef HAVE_FLOORF
/* Define to 1 if you have the `floorl' function. */
#undef HAVE_FLOORL
/* Define to 1 if you have the `floorq' function. */
#undef HAVE_FLOORQ
/* Define to 1 if you have the `fmod' function. */
#undef HAVE_FMOD
/* Define to 1 if you have the `fmodf' function. */
#undef HAVE_FMODF
/* Define to 1 if you have the `fmodl' function. */
#undef HAVE_FMODL
/* Define to 1 if you have the `fmodq' function. */
#undef HAVE_FMODQ
/* Define to 1 if you have the `fork' function. */
#undef HAVE_FORK
/* Define to 1 if you have the `fstat64' function. */
#undef HAVE_FSTAT64
/* Define to 1 if you have the `fsync' function. */
#undef HAVE_FSYNC
/* Define to 1 if you have the `ftruncate' function. */
#undef HAVE_FTRUNCATE
/* Define to 1 if you have the `ftruncate64' function. */
#undef HAVE_FTRUNCATE64
/* Define to 1 if you have the `futimens' function. */
#undef HAVE_FUTIMENS
/* Define to 1 if you have the `futimes' function. */
#undef HAVE_FUTIMES
/* Define to 1 if you have the `getcontext' function. */
#undef HAVE_GETCONTEXT
/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME
/* Define to 1 if you have the `getifaddrs' function. */
#undef HAVE_GETIFADDRS
/* Define to 1 if you have the `getpgid' function. */
#undef HAVE_GETPGID
/* Define to 1 if you have the `getpgrp' function. */
#undef HAVE_GETPGRP
/* Define to 1 if you have the `getrlimit' function. */
#undef HAVE_GETRLIMIT
/* Define to 1 if you have the `gettid' function. */
#undef HAVE_GETTID
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the <ifaddrs.h> header file. */
#undef HAVE_IFADDRS_H
/* Define to 1 if you have the `if_indextoname' function. */
#undef HAVE_IF_INDEXTONAME
/* Define to 1 if you have the `if_nametoindex' function. */
#undef HAVE_IF_NAMETOINDEX
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `isblank' function. */
#undef HAVE_ISBLANK
/* Define to 1 if you have the `iswblank' function. */
#undef HAVE_ISWBLANK
/* Define to 1 if you have the `iswctype' function. */
#undef HAVE_ISWCTYPE
/* Define to 1 if you have the `kevent' function. */
#undef HAVE_KEVENT
/* Define to 1 if you have the `kqueue' function. */
#undef HAVE_KQUEUE
/* Define to 1 if you have the `kqueue1' function. */
#undef HAVE_KQUEUE1
/* Define to 1 if you have the <linux/ethtool.h> header file. */
#undef HAVE_LINUX_ETHTOOL_H
/* Define to 1 if you have the <linux/netfilter_ipv4.h> header file. */
#undef HAVE_LINUX_NETFILTER_IPV4_H
/* Define to 1 if you have the <linux/sockios.h> header file. */
#undef HAVE_LINUX_SOCKIOS_H
/* Define to 1 if you have the `localtime_r' function. */
#undef HAVE_LOCALTIME_R
/* Define to 1 if you have the `log' function. */
#undef HAVE_LOG
/* Define to 1 if you have the `log10' function. */
#undef HAVE_LOG10
/* Define to 1 if you have the `log10f' function. */
#undef HAVE_LOG10F
/* Define to 1 if you have the `log10l' function. */
#undef HAVE_LOG10L
/* Define to 1 if you have the `log10q' function. */
#undef HAVE_LOG10Q
/* Define to 1 if you have the `logf' function. */
#undef HAVE_LOGF
/* Define to 1 if you have the `logl' function. */
#undef HAVE_LOGL
/* Define to 1 if you have the `logq' function. */
#undef HAVE_LOGQ
/* Define to 1 if you have the `lseek64' function. */
#undef HAVE_LSEEK64
/* Define to 1 if you have the `lstat' function. */
#undef HAVE_LSTAT
/* Define to 1 if you have the `lstat64' function. */
#undef HAVE_LSTAT64
/* Define to 1 if you have the `lutimes' function. */
#undef HAVE_LUTIMES
/* Define to 1 if you have the `makecontext' function. */
#undef HAVE_MAKECONTEXT
/* Define to 1 if you have the `mbrlen' function. */
#undef HAVE_MBRLEN
/* Define to 1 if you have the `mbrtowc' function. */
#undef HAVE_MBRTOWC
/* Define to 1 if you have the `mbsnrtowcs' function. */
#undef HAVE_MBSNRTOWCS
/* Define to 1 if you have the `mbsrtowcs' function. */
#undef HAVE_MBSRTOWCS
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the <netinet/sctp.h> header file. */
#undef HAVE_NETINET_SCTP_H
/* Define to 1 if you have the <netpacket/packet.h> header file. */
#undef HAVE_NETPACKET_PACKET_H
/* Define to 1 if you have the <net/if_dl.h> header file. */
#undef HAVE_NET_IF_DL_H
/* Define to 1 if you have the <net/if.h> header file. */
#undef HAVE_NET_IF_H
/* Define to 1 if you have the <openssl/engine.h> header file. */
#undef HAVE_OPENSSL_ENGINE_H
/* Define to 1 if you have the <openssl/err.h> header file. */
#undef HAVE_OPENSSL_ERR_H
/* Define to 1 if you have the <openssl/ssl.h> header file. */
#undef HAVE_OPENSSL_SSL_H
/* Define to 1 if you have the `posix_spawn' function. */
#undef HAVE_POSIX_SPAWN
/* Define to 1 if you have the `pow' function. */
#undef HAVE_POW
/* Define to 1 if you have the `powf' function. */
#undef HAVE_POWF
/* Define to 1 if you have the `powl' function. */
#undef HAVE_POWL
/* Define to 1 if you have the `powq' function. */
#undef HAVE_POWQ
/* Define to 1 if you have the `prctl' function. */
#undef HAVE_PRCTL
/* Define to 1 if you have the <quadmath.h> header file. */
#undef HAVE_QUADMATH_H
/* Define to 1 if you have the `quadmath_snprintf' function. */
#undef HAVE_QUADMATH_SNPRINTF
/* Define to 1 if you have the `readdir64' function. */
#undef HAVE_READDIR64
/* Define to 1 if you have the `round' function. */
#undef HAVE_ROUND
/* Define to 1 if you have the `roundf' function. */
#undef HAVE_ROUNDF
/* Define to 1 if you have the `roundl' function. */
#undef HAVE_ROUNDL
/* Define to 1 if you have the `roundq' function. */
#undef HAVE_ROUNDQ
/* Define to 1 if you have the `select' function. */
#undef HAVE_SELECT
/* Define to 1 if you have the `sendfile' function. */
#undef HAVE_SENDFILE
/* Define to 1 if you have the `sendfile64' function. */
#undef HAVE_SENDFILE64
/* Define to 1 if you have the `sendfilev' function. */
#undef HAVE_SENDFILEV
/* Define to 1 if you have the `sendfilev64' function. */
#undef HAVE_SENDFILEV64
/* Define to 1 if you have the `setcontext' function. */
#undef HAVE_SETCONTEXT
/* Define to 1 if you have the `setrlimit' function. */
#undef HAVE_SETRLIMIT
/* Define to 1 if you have the `settimeofday' function. */
#undef HAVE_SETTIMEOFDAY
/* Define to 1 if you have the <signal.h> header file. */
#undef HAVE_SIGNAL_H
/* Define to 1 if you have the `sin' function. */
#undef HAVE_SIN
/* Define to 1 if you have the `sinf' function. */
#undef HAVE_SINF
/* Define to 1 if you have the `sinh' function. */
#undef HAVE_SINH
/* Define to 1 if you have the `sinhf' function. */
#undef HAVE_SINHF
/* Define to 1 if you have the `sinhl' function. */
#undef HAVE_SINHL
/* Define to 1 if you have the `sinhq' function. */
#undef HAVE_SINHQ
/* Define to 1 if you have the `sinl' function. */
#undef HAVE_SINL
/* Define to 1 if you have the `sinq' function. */
#undef HAVE_SINQ
/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF
/* Define to 1 if you have the <spawn.h> header file. */
#undef HAVE_SPAWN_H
/* Define to 1 if you have the `sqrt' function. */
#undef HAVE_SQRT
/* Define to 1 if you have the `sqrtf' function. */
#undef HAVE_SQRTF
/* Define to 1 if you have the `sqrtl' function. */
#undef HAVE_SQRTL
/* Define to 1 if you have the `sqrtq' function. */
#undef HAVE_SQRTQ
/* ssl support */
#undef HAVE_SSL
/* Define to 1 if you have the `SSL_library_init' function. */
#undef HAVE_SSL_LIBRARY_INIT
/* Define to 1 if you have the `stat64' function. */
#undef HAVE_STAT64
/* Define to 1 if you have the <stddef.h> header file. */
#undef HAVE_STDDEF_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the `strtoflt128' function. */
#undef HAVE_STRTOFLT128
/* Define to 1 if `d_type' is a member of `struct dirent'. */
#undef HAVE_STRUCT_DIRENT_D_TYPE
/* Define to 1 if `ifr_ifindex' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_IFINDEX
/* Define to 1 if `ifr_mtu' is a member of `struct ifreq'. */
#undef HAVE_STRUCT_IFREQ_IFR_MTU
/* Define to 1 if the system has the type `struct if_laddrreq'. */
#undef HAVE_STRUCT_IF_LADDRREQ
/* Define to 1 if the system has the type `struct lifconf'. */
#undef HAVE_STRUCT_LIFCONF
/* Define to 1 if the system has the type `struct lifreq'. */
#undef HAVE_STRUCT_LIFREQ
/* Define to 1 if `sin6_scope_id' is a member of `struct sockaddr_in6'. */
#undef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID
/* Define to 1 if `st_birthtime' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIME
/* Define to 1 if `st_birthtimespec.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
/* Define to 1 if `st_birthtim.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_BIRTHTIM_TV_NSEC
/* Define to 1 if `st_mtimespec.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
/* Define to 1 if `st_mtim.tv_nsec' is a member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
/* Define to 1 if the system has the type `struct timespec'. */
#undef HAVE_STRUCT_TIMESPEC
/* Define to 1 if you have the `swapcontext' function. */
#undef HAVE_SWAPCONTEXT
/* Define to 1 if you have the `sysconf' function. */
#undef HAVE_SYSCONF
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the <sys/epoll.h> header file. */
#undef HAVE_SYS_EPOLL_H
/* Define to 1 if you have the <sys/event.h> header file. */
#undef HAVE_SYS_EVENT_H
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/macstat.h> header file. */
#undef HAVE_SYS_MACSTAT_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to 1 if you have the <sys/poll.h> header file. */
#undef HAVE_SYS_POLL_H
/* Define to 1 if you have the <sys/prctl.h> header file. */
#undef HAVE_SYS_PRCTL_H
/* Define to 1 if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H
/* Define to 1 if you have the <sys/sendfile.h> header file. */
#undef HAVE_SYS_SENDFILE_H
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
/* Define to 1 if you have the <sys/sockio.h> header file. */
#undef HAVE_SYS_SOCKIO_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/stropts.h> header file. */
#undef HAVE_SYS_STROPTS_H
/* Define to 1 if you have the <sys/syscall.h> header file. */
#undef HAVE_SYS_SYSCALL_H
/* Define to 1 if you have the <sys/sysctl.h> header file. */
#undef HAVE_SYS_SYSCTL_H
/* Define to 1 if you have the <sys/time.h> header file. */
#undef HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <sys/un.h> header file. */
#undef HAVE_SYS_UN_H
/* Define to 1 if you have the <sys/wait.h> header file. */
#undef HAVE_SYS_WAIT_H
/* Define to 1 if you have the `tan' function. */
#undef HAVE_TAN
/* Define to 1 if you have the `tanf' function. */
#undef HAVE_TANF
/* Define to 1 if you have the `tanh' function. */
#undef HAVE_TANH
/* Define to 1 if you have the `tanhf' function. */
#undef HAVE_TANHF
/* Define to 1 if you have the `tanhl' function. */
#undef HAVE_TANHL
/* Define to 1 if you have the `tanhq' function. */
#undef HAVE_TANHQ
/* Define to 1 if you have the `tanl' function. */
#undef HAVE_TANL
/* Define to 1 if you have the `tanq' function. */
#undef HAVE_TANQ
/* Define to 1 if you have the `timegm' function. */
#undef HAVE_TIMEGM
/* Define to 1 if you have the `timelocal' function. */
#undef HAVE_TIMELOCAL
/* Define to 1 if you have the <time.h> header file. */
#undef HAVE_TIME_H
/* Define to 1 if you have the <tiuser.h> header file. */
#undef HAVE_TIUSER_H
/* Define to 1 if you have the `towctrans' function. */
#undef HAVE_TOWCTRANS
/* Define to 1 if you have the `t_connect' function. */
#undef HAVE_T_CONNECT
/* Define to 1 if you have the <ucontext.h> header file. */
#undef HAVE_UCONTEXT_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `uselocale' function. */
#undef HAVE_USELOCALE
/* Define to 1 if you have the `utime' function. */
#undef HAVE_UTIME
/* Define to 1 if you have the `utimes' function. */
#undef HAVE_UTIMES
/* Define to 1 if you have the <utime.h> header file. */
#undef HAVE_UTIME_H
/* va_copy is available */
#undef HAVE_VA_COPY
/* Define to 1 if you have the `vfork' function. */
#undef HAVE_VFORK
/* Define to 1 if you have the <wchar.h> header file. */
#undef HAVE_WCHAR_H
/* Define to 1 if you have the `wcrtomb' function. */
#undef HAVE_WCRTOMB
/* Define to 1 if you have the `wcsnrtombs' function. */
#undef HAVE_WCSNRTOMBS
/* Define to 1 if you have the `wcsrtombs' function. */
#undef HAVE_WCSRTOMBS
/* Define to 1 if you have the `wctrans' function. */
#undef HAVE_WCTRANS
/* Define to 1 if you have the `wctype' function. */
#undef HAVE_WCTYPE
/* Define to 1 if you have the <wctype.h> header file. */
#undef HAVE_WCTYPE_H
/* Define to 1 if you have the `_vsnprintf' function. */
#undef HAVE__VSNPRINTF
/* Define to 1 if you have the `_vsnwprintf' function. */
#undef HAVE__VSNWPRINTF
/* __builtin_memcmp */
#undef HAVE___BUILTIN_MEMCMP
/* __builtin_memcpy */
#undef HAVE___BUILTIN_MEMCPY
/* __builtin_memmove */
#undef HAVE___BUILTIN_MEMMOVE
/* __builtin_memset */
#undef HAVE___BUILTIN_MEMSET
/* __va_copy is available */
#undef HAVE___VA_COPY
/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
#undef LT_OBJDIR
/* The size of `MB_LEN_MAX', as computed by valueof. */
#undef NUMVALOF_MB_LEN_MAX
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `char', as computed by sizeof. */
#undef SIZEOF_CHAR
/* The size of `double', as computed by sizeof. */
#undef SIZEOF_DOUBLE
/* The size of `float', as computed by sizeof. */
#undef SIZEOF_FLOAT
/* The size of `int', as computed by sizeof. */
#undef SIZEOF_INT
/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG
/* The size of `long double', as computed by sizeof. */
#undef SIZEOF_LONG_DOUBLE
/* The size of `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
/* The size of `mbstate_t', as computed by sizeof. */
#undef SIZEOF_MBSTATE_T
/* The size of `off64_t', as computed by sizeof. */
#undef SIZEOF_OFF64_T
/* The size of `off_t', as computed by sizeof. */
#undef SIZEOF_OFF_T
/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* The size of `socklen_t', as computed by sizeof. */
#undef SIZEOF_SOCKLEN_T
/* The size of `struct sockaddr_dl', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_DL
/* The size of `struct sockaddr_in', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_IN
/* The size of `struct sockaddr_in6', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_IN6
/* The size of `struct sockaddr_ll', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_LL
/* The size of `struct sockaddr_un', as computed by sizeof. */
#undef SIZEOF_STRUCT_SOCKADDR_UN
/* The size of `void *', as computed by sizeof. */
#undef SIZEOF_VOID_P
/* The size of `wchar_t', as computed by sizeof. */
#undef SIZEOF_WCHAR_T
/* The size of `__float128', as computed by sizeof. */
#undef SIZEOF___FLOAT128
/* The size of `__int128', as computed by sizeof. */
#undef SIZEOF___INT128
/* The size of `__int128_t', as computed by sizeof. */
#undef SIZEOF___INT128_T
/* The size of `__int16', as computed by sizeof. */
#undef SIZEOF___INT16
/* The size of `__int16_t', as computed by sizeof. */
#undef SIZEOF___INT16_T
/* The size of `__int32', as computed by sizeof. */
#undef SIZEOF___INT32
/* The size of `__int32_t', as computed by sizeof. */
#undef SIZEOF___INT32_T
/* The size of `__int64', as computed by sizeof. */
#undef SIZEOF___INT64
/* The size of `__int64_t', as computed by sizeof. */
#undef SIZEOF___INT64_T
/* The size of `__int8', as computed by sizeof. */
#undef SIZEOF___INT8
/* The size of `__int8_t', as computed by sizeof. */
#undef SIZEOF___INT8_T
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Big Endian */
#undef STIO_ENDIAN_BIG
/* Little Endian */
#undef STIO_ENDIAN_LITTLE
/* Unknown Endian */
#undef STIO_ENDIAN_UNKNOWN
/* MB_LEN_MAX */
#undef STIO_MBLEN_MAX
/* Author */
#undef STIO_PACKAGE_AUTHOR
/* package name */
#undef STIO_PACKAGE_NAME
/* Project URL */
#undef STIO_PACKAGE_URL
/* Package version */
#undef STIO_PACKAGE_VERSION
/* Major version number */
#undef STIO_PACKAGE_VERSION_MAJOR
/* Minor version number */
#undef STIO_PACKAGE_VERSION_MINOR
/* Patch level */
#undef STIO_PACKAGE_VERSION_PATCH
/* sizeof(char) */
#undef STIO_SIZEOF_CHAR
/* sizeof(double) */
#undef STIO_SIZEOF_DOUBLE
/* sizeof(float) */
#undef STIO_SIZEOF_FLOAT
/* sizeof(int) */
#undef STIO_SIZEOF_INT
/* sizeof(long) */
#undef STIO_SIZEOF_LONG
/* sizeof(long double) */
#undef STIO_SIZEOF_LONG_DOUBLE
/* sizeof(long long) */
#undef STIO_SIZEOF_LONG_LONG
/* sizeof(mbstate_t) */
#undef STIO_SIZEOF_MBSTATE_T
/* sizeof(off64_t) */
#undef STIO_SIZEOF_OFF64_T
/* sizeof(off_t) */
#undef STIO_SIZEOF_OFF_T
/* sizeof(short) */
#undef STIO_SIZEOF_SHORT
/* sizeof(socklen_t) */
#undef STIO_SIZEOF_SOCKLEN_T
/* sizeof(struct sockaddr_dl) */
#undef STIO_SIZEOF_STRUCT_SOCKADDR_DL
/* sizeof(struct sockaddr_in) */
#undef STIO_SIZEOF_STRUCT_SOCKADDR_IN
/* sizeof(struct sockaddr_in6) */
#undef STIO_SIZEOF_STRUCT_SOCKADDR_IN6
/* sizeof(struct sockaddr_ll) */
#undef STIO_SIZEOF_STRUCT_SOCKADDR_LL
/* sizeof(struct sockaddr_un) */
#undef STIO_SIZEOF_STRUCT_SOCKADDR_UN
/* sizeof(void*) */
#undef STIO_SIZEOF_VOID_P
/* sizeof(wchar_t) */
#undef STIO_SIZEOF_WCHAR_T
/* sizeof(__float128) */
#undef STIO_SIZEOF___FLOAT128
/* sizeof(__int128) */
#undef STIO_SIZEOF___INT128
/* sizeof(__int128_t) */
#undef STIO_SIZEOF___INT128_T
/* sizeof(__int16) */
#undef STIO_SIZEOF___INT16
/* sizeof(__int32) */
#undef STIO_SIZEOF___INT32
/* sizeof(__int64) */
#undef STIO_SIZEOF___INT64
/* sizeof(__int8) */
#undef STIO_SIZEOF___INT8
/* Define if socklen_t is signed */
#undef STIO_SOCKLEN_T_IS_SIGNED
/* Version number of package */
#undef VERSION
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
# undef WORDS_BIGENDIAN
# endif
#endif

569
mio/lib/stio-cmn.h Normal file
View File

@ -0,0 +1,569 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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 WARRANTIES
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.
*/
#ifndef _STIO_CMN_H_
#define _STIO_CMN_H_
/* WARNING: NEVER CHANGE/DELETE THE FOLLOWING STIO_HAVE_CFG_H DEFINITION.
* IT IS USED FOR DEPLOYMENT BY MAKEFILE.AM */
/*#define STIO_HAVE_CFG_H*/
#if defined(STIO_HAVE_CFG_H)
# include "stio-cfg.h"
#elif defined(_WIN32)
# include "stio-msw.h"
#elif defined(__OS2__)
# include "stio-os2.h"
#elif defined(__MSDOS__)
# include "stio-dos.h"
#elif defined(macintosh)
# include "stio-mac.h" /* class mac os */
#else
# error UNSUPPORTED SYSTEM
#endif
#if defined(EMSCRIPTEN)
# if defined(STIO_SIZEOF___INT128)
# undef STIO_SIZEOF___INT128
# define STIO_SIZEOF___INT128 0
# endif
# if defined(STIO_SIZEOF_LONG) && defined(STIO_SIZEOF_INT) && (STIO_SIZEOF_LONG > STIO_SIZEOF_INT)
/* autoconf doesn't seem to match actual emscripten */
# undef STIO_SIZEOF_LONG
# define STIO_SIZEOF_LONG STIO_SIZEOF_INT
# endif
#endif
/* =========================================================================
* PRIMITIVE TYPE DEFINTIONS
* ========================================================================= */
/* stio_int8_t */
#if defined(STIO_SIZEOF_CHAR) && (STIO_SIZEOF_CHAR == 1)
# define STIO_HAVE_UINT8_T
# define STIO_HAVE_INT8_T
typedef unsigned char stio_uint8_t;
typedef signed char stio_int8_t;
#elif defined(STIO_SIZEOF___INT8) && (STIO_SIZEOF___INT8 == 1)
# define STIO_HAVE_UINT8_T
# define STIO_HAVE_INT8_T
typedef unsigned __int8 stio_uint8_t;
typedef signed __int8 stio_int8_t;
#elif defined(STIO_SIZEOF___INT8_T) && (STIO_SIZEOF___INT8_T == 1)
# define STIO_HAVE_UINT8_T
# define STIO_HAVE_INT8_T
typedef unsigned __int8_t stio_uint8_t;
typedef signed __int8_t stio_int8_t;
#else
# define STIO_HAVE_UINT8_T
# define STIO_HAVE_INT8_T
typedef unsigned char stio_uint8_t;
typedef signed char stio_int8_t;
#endif
/* stio_int16_t */
#if defined(STIO_SIZEOF_SHORT) && (STIO_SIZEOF_SHORT == 2)
# define STIO_HAVE_UINT16_T
# define STIO_HAVE_INT16_T
typedef unsigned short int stio_uint16_t;
typedef signed short int stio_int16_t;
#elif defined(STIO_SIZEOF___INT16) && (STIO_SIZEOF___INT16 == 2)
# define STIO_HAVE_UINT16_T
# define STIO_HAVE_INT16_T
typedef unsigned __int16 stio_uint16_t;
typedef signed __int16 stio_int16_t;
#elif defined(STIO_SIZEOF___INT16_T) && (STIO_SIZEOF___INT16_T == 2)
# define STIO_HAVE_UINT16_T
# define STIO_HAVE_INT16_T
typedef unsigned __int16_t stio_uint16_t;
typedef signed __int16_t stio_int16_t;
#else
# define STIO_HAVE_UINT16_T
# define STIO_HAVE_INT16_T
typedef unsigned short int stio_uint16_t;
typedef signed short int stio_int16_t;
#endif
/* stio_int32_t */
#if defined(STIO_SIZEOF_INT) && (STIO_SIZEOF_INT == 4)
# define STIO_HAVE_UINT32_T
# define STIO_HAVE_INT32_T
typedef unsigned int stio_uint32_t;
typedef signed int stio_int32_t;
#elif defined(STIO_SIZEOF_LONG) && (STIO_SIZEOF_LONG == 4)
# define STIO_HAVE_UINT32_T
# define STIO_HAVE_INT32_T
typedef unsigned long stio_uint32_t;
typedef signed long stio_int32_t;
#elif defined(STIO_SIZEOF___INT32) && (STIO_SIZEOF___INT32 == 4)
# define STIO_HAVE_UINT32_T
# define STIO_HAVE_INT32_T
typedef unsigned __int32 stio_uint32_t;
typedef signed __int32 stio_int32_t;
#elif defined(STIO_SIZEOF___INT32_T) && (STIO_SIZEOF___INT32_T == 4)
# define STIO_HAVE_UINT32_T
# define STIO_HAVE_INT32_T
typedef unsigned __int32_t stio_uint32_t;
typedef signed __int32_t stio_int32_t;
#elif defined(__MSDOS__)
# define STIO_HAVE_UINT32_T
# define STIO_HAVE_INT32_T
typedef unsigned long int stio_uint32_t;
typedef signed long int stio_int32_t;
#else
# define STIO_HAVE_UINT32_T
# define STIO_HAVE_INT32_T
typedef unsigned int stio_uint32_t;
typedef signed int stio_int32_t;
#endif
/* stio_int64_t */
#if defined(STIO_SIZEOF_INT) && (STIO_SIZEOF_INT == 8)
# define STIO_HAVE_UINT64_T
# define STIO_HAVE_INT64_T
typedef unsigned int stio_uint64_t;
typedef signed int stio_int64_t;
#elif defined(STIO_SIZEOF_LONG) && (STIO_SIZEOF_LONG == 8)
# define STIO_HAVE_UINT64_T
# define STIO_HAVE_INT64_T
typedef unsigned long stio_uint64_t;
typedef signed long stio_int64_t;
#elif defined(STIO_SIZEOF_LONG_LONG) && (STIO_SIZEOF_LONG_LONG == 8)
# define STIO_HAVE_UINT64_T
# define STIO_HAVE_INT64_T
typedef unsigned long long stio_uint64_t;
typedef signed long long stio_int64_t;
#elif defined(STIO_SIZEOF___INT64) && (STIO_SIZEOF___INT64 == 8)
# define STIO_HAVE_UINT64_T
# define STIO_HAVE_INT64_T
typedef unsigned __int64 stio_uint64_t;
typedef signed __int64 stio_int64_t;
#elif defined(STIO_SIZEOF___INT64_T) && (STIO_SIZEOF___INT64_T == 8)
# define STIO_HAVE_UINT64_T
# define STIO_HAVE_INT64_T
typedef unsigned __int64_t stio_uint64_t;
typedef signed __int64_t stio_int64_t;
#elif defined(_WIN64) || defined(_WIN32)
# define STIO_HAVE_UINT64_T
# define STIO_HAVE_INT64_T
typedef unsigned __int64 stio_uint64_t;
typedef signed __int64 stio_int64_t;
#else
/* no 64-bit integer */
#endif
/* stio_int128_t */
#if defined(STIO_SIZEOF_INT) && (STIO_SIZEOF_INT == 16)
# define STIO_HAVE_UINT128_T
# define STIO_HAVE_INT128_T
typedef unsigned int stio_uint128_t;
typedef signed int stio_int128_t;
#elif defined(STIO_SIZEOF_LONG) && (STIO_SIZEOF_LONG == 16)
# define STIO_HAVE_UINT128_T
# define STIO_HAVE_INT128_T
typedef unsigned long stio_uint128_t;
typedef signed long stio_int128_t;
#elif defined(STIO_SIZEOF_LONG_LONG) && (STIO_SIZEOF_LONG_LONG == 16)
# define STIO_HAVE_UINT128_T
# define STIO_HAVE_INT128_T
typedef unsigned long long stio_uint128_t;
typedef signed long long stio_int128_t;
#elif defined(STIO_SIZEOF___INT128) && (STIO_SIZEOF___INT128 == 16)
# define STIO_HAVE_UINT128_T
# define STIO_HAVE_INT128_T
typedef unsigned __int128 stio_uint128_t;
typedef signed __int128 stio_int128_t;
#elif defined(STIO_SIZEOF___INT128_T) && (STIO_SIZEOF___INT128_T == 16)
# define STIO_HAVE_UINT128_T
# define STIO_HAVE_INT128_T
#if defined(__clang__)
typedef __uint128_t stio_uint128_t;
typedef __int128_t stio_int128_t;
#else
typedef unsigned __int128_t stio_uint128_t;
typedef signed __int128_t stio_int128_t;
#endif
#else
/* no 128-bit integer */
#endif
#if defined(STIO_HAVE_UINT8_T) && (STIO_SIZEOF_VOID_P == 1)
# error UNSUPPORTED POINTER SIZE
#elif defined(STIO_HAVE_UINT16_T) && (STIO_SIZEOF_VOID_P == 2)
typedef stio_uint16_t stio_uintptr_t;
typedef stio_int16_t stio_intptr_t;
typedef stio_uint8_t stio_ushortptr_t;
typedef stio_int8_t stio_shortptr_t;
#elif defined(STIO_HAVE_UINT32_T) && (STIO_SIZEOF_VOID_P == 4)
typedef stio_uint32_t stio_uintptr_t;
typedef stio_int32_t stio_intptr_t;
typedef stio_uint16_t stio_ushortptr_t;
typedef stio_int16_t stio_shortptr_t;
#elif defined(STIO_HAVE_UINT64_T) && (STIO_SIZEOF_VOID_P == 8)
typedef stio_uint64_t stio_uintptr_t;
typedef stio_int64_t stio_intptr_t;
typedef stio_uint32_t stio_ushortptr_t;
typedef stio_int32_t stio_shortptr_t;
#elif defined(STIO_HAVE_UINT128_T) && (STIO_SIZEOF_VOID_P == 16)
typedef stio_uint128_t stio_uintptr_t;
typedef stio_int128_t stio_intptr_t;
typedef stio_uint64_t stio_ushortptr_t;
typedef stio_int64_t stio_shortptr_t;
#else
# error UNKNOWN POINTER SIZE
#endif
#define STIO_SIZEOF_INTPTR_T STIO_SIZEOF_VOID_P
#define STIO_SIZEOF_UINTPTR_T STIO_SIZEOF_VOID_P
#define STIO_SIZEOF_SHORTPTR_T (STIO_SIZEOF_VOID_P / 2)
#define STIO_SIZEOF_USHORTPTR_T (STIO_SIZEOF_VOID_P / 2)
#if defined(STIO_HAVE_INT128_T)
# define STIO_SIZEOF_INTMAX_T 16
# define STIO_SIZEOF_UINTMAX_T 16
typedef stio_int128_t stio_intmax_t;
typedef stio_uint128_t stio_uintmax_t;
#elif defined(STIO_HAVE_INT64_T)
# define STIO_SIZEOF_INTMAX_T 8
# define STIO_SIZEOF_UINTMAX_T 8
typedef stio_int64_t stio_intmax_t;
typedef stio_uint64_t stio_uintmax_t;
#elif defined(STIO_HAVE_INT32_T)
# define STIO_SIZEOF_INTMAX_T 4
# define STIO_SIZEOF_UINTMAX_T 4
typedef stio_int32_t stio_intmax_t;
typedef stio_uint32_t stio_uintmax_t;
#elif defined(STIO_HAVE_INT16_T)
# define STIO_SIZEOF_INTMAX_T 2
# define STIO_SIZEOF_UINTMAX_T 2
typedef stio_int16_t stio_intmax_t;
typedef stio_uint16_t stio_uintmax_t;
#elif defined(STIO_HAVE_INT8_T)
# define STIO_SIZEOF_INTMAX_T 1
# define STIO_SIZEOF_UINTMAX_T 1
typedef stio_int8_t stio_intmax_t;
typedef stio_uint8_t stio_uintmax_t;
#else
# error UNKNOWN INTMAX SIZE
#endif
/* =========================================================================
* BASIC STIO TYPES
* =========================================================================*/
typedef stio_uint8_t stio_byte_t;
typedef stio_uintptr_t stio_size_t;
typedef char stio_mchar_t;
typedef int stio_mcint_t;
#define STIO_MT(x) (x)
/* =========================================================================
* PRIMITIVE MACROS
* ========================================================================= */
#define STIO_SIZEOF(x) (sizeof(x))
#define STIO_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
/**
* The STIO_OFFSETOF() macro returns the offset of a field from the beginning
* of a structure.
*/
#define STIO_OFFSETOF(type,member) ((stio_uintptr_t)&((type*)0)->member)
/**
* The STIO_ALIGNOF() macro returns the alignment size of a structure.
* Note that this macro may not work reliably depending on the type given.
*/
#define STIO_ALIGNOF(type) STIO_OFFSETOF(struct { stio_uint8_t d1; type d2; }, d2)
/*(sizeof(struct { stio_uint8_t d1; type d2; }) - sizeof(type))*/
/**
* Round up a positive integer to the nearest multiple of 'align'
*/
#define STIO_ALIGNTO(num,align) ((((num) + (align) - 1) / (align)) * (align))
#if 0
/**
* Round up a number, both positive and negative, to the nearest multiple of 'align'
*/
#define STIO_ALIGNTO(num,align) ((((num) + (num >= 0? 1: -1) * (align) - 1) / (align)) * (align))
#endif
/**
* Round up a positive integer to to the nearest multiple of 'align' which
* should be a multiple of a power of 2
*/
#define STIO_ALIGNTO_POW2(num,align) ((((num) + (align) - 1)) & ~((align) - 1))
#if defined(__cplusplus)
# if (__cplusplus >= 201103L) /* C++11 */
# define STIO_NULL nullptr
# else
# define STIO_NULL (0)
# endif
#else
# define STIO_NULL ((void*)0)
#endif
/* make a bit mask that can mask off low n bits */
#define STIO_LBMASK(type,n) (~(~((type)0) << (n)))
#define STIO_LBMASK_SAFE(type,n) (((n) < STIO_SIZEOF(type) * 8)? STIO_LBMASK(type,n): ~(type)0)
/* make a bit mask that can mask off hig n bits */
#define STIO_HBMASK(type,n) (~(~((type)0) >> (n)))
#define STIO_HBMASK_SAFE(type,n) (((n) < STIO_SIZEOF(type) * 8)? STIO_HBMASK(type,n): ~(type)0)
/* get 'length' bits starting from the bit at the 'offset' */
#define STIO_GETBITS(type,value,offset,length) \
((((type)(value)) >> (offset)) & STIO_LBMASK(type,length))
#define STIO_SETBITS(type,value,offset,length,bits) \
(value = (((type)(value)) | (((bits) & STIO_LBMASK(type,length)) << (offset))))
/**
* The STIO_BITS_MAX() macros calculates the maximum value that the 'nbits'
* bits of an unsigned integer of the given 'type' can hold.
* \code
* printf ("%u", STIO_BITS_MAX(unsigned int, 5));
* \endcode
*/
/*#define STIO_BITS_MAX(type,nbits) ((((type)1) << (nbits)) - 1)*/
#define STIO_BITS_MAX(type,nbits) ((~(type)0) >> (STIO_SIZEOF(type) * 8 - (nbits)))
/* =========================================================================
* MMGR
* ========================================================================= */
typedef struct stio_mmgr_t stio_mmgr_t;
/**
* allocate a memory chunk of the size \a n.
* \return pointer to a memory chunk on success, #STIO_NULL on failure.
*/
typedef void* (*stio_mmgr_alloc_t) (stio_mmgr_t* mmgr, stio_size_t n);
/**
* resize a memory chunk pointed to by \a ptr to the size \a n.
* \return pointer to a memory chunk on success, #STIO_NULL on failure.
*/
typedef void* (*stio_mmgr_realloc_t) (stio_mmgr_t* mmgr, void* ptr, stio_size_t n);
/**
* free a memory chunk pointed to by \a ptr.
*/
typedef void (*stio_mmgr_free_t) (stio_mmgr_t* mmgr, void* ptr);
/**
* The stio_mmgr_t type defines the memory management interface.
* As the type is merely a structure, it is just used as a single container
* for memory management functions with a pointer to user-defined data.
* The user-defined data pointer \a ctx is passed to each memory management
* function whenever it is called. You can allocate, reallocate, and free
* a memory chunk.
*
* For example, a stio_xxx_open() function accepts a pointer of the stio_mmgr_t
* type and the xxx object uses it to manage dynamic data within the object.
*/
struct stio_mmgr_t
{
stio_mmgr_alloc_t alloc; /**< allocation function */
stio_mmgr_realloc_t realloc; /**< resizing function */
stio_mmgr_free_t free; /**< disposal function */
void* ctx; /**< user-defined data pointer */
};
/**
* The STIO_MMGR_ALLOC() macro allocates a memory block of the \a size bytes
* using the \a mmgr memory manager.
*/
#define STIO_MMGR_ALLOC(mmgr,size) ((mmgr)->alloc(mmgr,size))
/**
* The STIO_MMGR_REALLOC() macro resizes a memory block pointed to by \a ptr
* to the \a size bytes using the \a mmgr memory manager.
*/
#define STIO_MMGR_REALLOC(mmgr,ptr,size) ((mmgr)->realloc(mmgr,ptr,size))
/**
* The STIO_MMGR_FREE() macro deallocates the memory block pointed to by \a ptr.
*/
#define STIO_MMGR_FREE(mmgr,ptr) ((mmgr)->free(mmgr,ptr))
/* =========================================================================
* MACROS THAT CHANGES THE BEHAVIORS OF THE C COMPILER/LINKER
* =========================================================================*/
#if defined(_WIN32) || (defined(__WATCOMC__) && !defined(__WINDOWS_386__))
# define STIO_IMPORT __declspec(dllimport)
# define STIO_EXPORT __declspec(dllexport)
# define STIO_PRIVATE
#elif defined(__GNUC__) && (__GNUC__>=4)
# define STIO_IMPORT __attribute__((visibility("default")))
# define STIO_EXPORT __attribute__((visibility("default")))
# define STIO_PRIVATE __attribute__((visibility("hidden")))
/*# define STIO_PRIVATE __attribute__((visibility("internal")))*/
#else
# define STIO_IMPORT
# define STIO_EXPORT
# define STIO_PRIVATE
#endif
#if defined(__STDC_VERSION__) && (__STDC_VERSION__>=199901L)
# define STIO_INLINE inline
# define STIO_HAVE_INLINE
#elif defined(__GNUC__) && defined(__GNUC_GNU_INLINE__)
/* gcc disables inline when -std=c89 or -ansi is used.
* so use __inline__ supported by gcc regardless of the options */
# define STIO_INLINE /*extern*/ __inline__
# define STIO_HAVE_INLINE
#else
# define STIO_INLINE
# undef STIO_HAVE_INLINE
#endif
/**
* The STIO_TYPE_IS_SIGNED() macro determines if a type is signed.
* \code
* printf ("%d\n", (int)STIO_TYPE_IS_SIGNED(int));
* printf ("%d\n", (int)STIO_TYPE_IS_SIGNED(unsigned int));
* \endcode
*/
#define STIO_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1))
/**
* The STIO_TYPE_IS_SIGNED() macro determines if a type is unsigned.
* \code
* printf ("%d\n", STIO_TYPE_IS_UNSIGNED(int));
* printf ("%d\n", STIO_TYPE_IS_UNSIGNED(unsigned int));
* \endcode
*/
#define STIO_TYPE_IS_UNSIGNED(type) (((type)0) < ((type)-1))
#define STIO_TYPE_SIGNED_MAX(type) \
((type)~((type)1 << ((type)STIO_SIZEOF(type) * 8 - 1)))
#define STIO_TYPE_UNSIGNED_MAX(type) ((type)(~(type)0))
#define STIO_TYPE_SIGNED_MIN(type) \
((type)((type)1 << ((type)STIO_SIZEOF(type) * 8 - 1)))
#define STIO_TYPE_UNSIGNED_MIN(type) ((type)0)
#define STIO_TYPE_MAX(type) \
((STIO_TYPE_IS_SIGNED(type)? STIO_TYPE_SIGNED_MAX(type): STIO_TYPE_UNSIGNED_MAX(type)))
#define STIO_TYPE_MIN(type) \
((STIO_TYPE_IS_SIGNED(type)? STIO_TYPE_SIGNED_MIN(type): STIO_TYPE_UNSIGNED_MIN(type)))
/* =========================================================================
* COMPILER FEATURE TEST MACROS
* =========================================================================*/
#if defined(__has_builtin)
#if __has_builtin(__builtin_ctz)
#define STIO_HAVE_BUILTIN_CTZ
#endif
#if __has_builtin(__builtin_uadd_overflow)
#define STIO_HAVE_BUILTIN_UADD_OVERFLOW
#endif
#if __has_builtin(__builtin_uaddl_overflow)
#define STIO_HAVE_BUILTIN_UADDL_OVERFLOW
#endif
#if __has_builtin(__builtin_uaddll_overflow)
#define STIO_HAVE_BUILTIN_UADDLL_OVERFLOW
#endif
#if __has_builtin(__builtin_umul_overflow)
#define STIO_HAVE_BUILTIN_UMUL_OVERFLOW
#endif
#if __has_builtin(__builtin_umull_overflow)
#define STIO_HAVE_BUILTIN_UMULL_OVERFLOW
#endif
#if __has_builtin(__builtin_umulll_overflow)
#define STIO_HAVE_BUILTIN_UMULLL_OVERFLOW
#endif
#if __has_builtin(__builtin_sadd_overflow)
#define STIO_HAVE_BUILTIN_SADD_OVERFLOW
#endif
#if __has_builtin(__builtin_saddl_overflow)
#define STIO_HAVE_BUILTIN_SADDL_OVERFLOW
#endif
#if __has_builtin(__builtin_saddll_overflow)
#define STIO_HAVE_BUILTIN_SADDLL_OVERFLOW
#endif
#if __has_builtin(__builtin_smul_overflow)
#define STIO_HAVE_BUILTIN_SMUL_OVERFLOW
#endif
#if __has_builtin(__builtin_smull_overflow)
#define STIO_HAVE_BUILTIN_SMULL_OVERFLOW
#endif
#if __has_builtin(__builtin_smulll_overflow)
#define STIO_HAVE_BUILTIN_SMULLL_OVERFLOW
#endif
#elif defined(__GNUC__) && defined(__GNUC_MINOR__)
#if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define STIO_HAVE_BUILTIN_CTZ
#endif
#if (__GNUC__ >= 5)
#define STIO_HAVE_BUILTIN_UADD_OVERFLOW
#define STIO_HAVE_BUILTIN_UADDL_OVERFLOW
#define STIO_HAVE_BUILTIN_UADDLL_OVERFLOW
#define STIO_HAVE_BUILTIN_UMUL_OVERFLOW
#define STIO_HAVE_BUILTIN_UMULL_OVERFLOW
#define STIO_HAVE_BUILTIN_UMULLL_OVERFLOW
#define STIO_HAVE_BUILTIN_SADD_OVERFLOW
#define STIO_HAVE_BUILTIN_SADDL_OVERFLOW
#define STIO_HAVE_BUILTIN_SADDLL_OVERFLOW
#define STIO_HAVE_BUILTIN_SMUL_OVERFLOW
#define STIO_HAVE_BUILTIN_SMULL_OVERFLOW
#define STIO_HAVE_BUILTIN_SMULLL_OVERFLOW
#endif
#endif
/*
#if !defined(__has_builtin)
#define __has_builtin(x) 0
#endif
#if !defined(__is_identifier)
#define __is_identifier(x) 0
#endif
#if !defined(__has_attribute)
#define __has_attribute(x) 0
#endif
*/
#endif

846
mio/lib/stio-pro.c Normal file
View File

@ -0,0 +1,846 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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 "stio-pro.h"
#include "stio-prv.h"
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/wait.h>
/* ========================================================================= */
struct slave_info_t
{
stio_dev_pro_make_t* mi;
stio_syshnd_t pfd;
int dev_capa;
stio_dev_pro_sid_t id;
};
typedef struct slave_info_t slave_info_t;
static stio_dev_pro_slave_t* make_slave (stio_t* stio, slave_info_t* si);
/* ========================================================================= */
struct param_t
{
stio_mchar_t* mcmd;
stio_mchar_t* fixed_argv[4];
stio_mchar_t** argv;
};
typedef struct param_t param_t;
static void free_param (stio_t* stio, param_t* param)
{
if (param->argv && param->argv != param->fixed_argv)
STIO_MMGR_FREE (stio->mmgr, param->argv);
if (param->mcmd) STIO_MMGR_FREE (stio->mmgr, param->mcmd);
STIO_MEMSET (param, 0, STIO_SIZEOF(*param));
}
static int make_param (stio_t* stio, const stio_mchar_t* cmd, int flags, param_t* param)
{
int fcnt = 0;
stio_mchar_t* mcmd = STIO_NULL;
STIO_MEMSET (param, 0, STIO_SIZEOF(*param));
if (flags & STIO_DEV_PRO_SHELL)
{
mcmd = (stio_mchar_t*)cmd;
param->argv = param->fixed_argv;
param->argv[0] = STIO_MT("/bin/sh");
param->argv[1] = STIO_MT("-c");
param->argv[2] = mcmd;
param->argv[3] = STIO_NULL;
}
else
{
int i;
stio_mchar_t** argv;
stio_mchar_t* mcmdptr;
mcmd = stio_mbsdup (stio, cmd);
if (!mcmd) goto oops;
fcnt = stio_mbsspl (mcmd, STIO_MT(""), STIO_MT('\"'), STIO_MT('\"'), STIO_MT('\\'));
if (fcnt <= 0)
{
/* no field or an error */
stio->errnum = STIO_EINVAL;
goto oops;
}
if (fcnt < STIO_COUNTOF(param->fixed_argv))
{
param->argv = param->fixed_argv;
}
else
{
param->argv = STIO_MMGR_ALLOC (stio->mmgr, (fcnt + 1) * STIO_SIZEOF(argv[0]));
if (param->argv == STIO_NULL)
{
stio->errnum = STIO_ENOMEM;
goto oops;
}
}
mcmdptr = mcmd;
for (i = 0; i < fcnt; i++)
{
param->argv[i] = mcmdptr;
while (*mcmdptr != STIO_MT('\0')) mcmdptr++;
mcmdptr++;
}
param->argv[i] = STIO_NULL;
}
if (mcmd && mcmd != (stio_mchar_t*)cmd) param->mcmd = mcmd;
return 0;
oops:
if (mcmd && mcmd != cmd) STIO_MMGR_FREE (stio->mmgr, mcmd);
return -1;
}
static pid_t standard_fork_and_exec (stio_t* stio, int pfds[], int flags, param_t* param)
{
pid_t pid;
pid = fork ();
if (pid == -1)
{
stio->errnum = stio_syserrtoerrnum(errno);
return -1;
}
if (pid == 0)
{
/* slave process */
stio_syshnd_t devnull = STIO_SYSHND_INVALID;
/* TODO: close all uneeded fds */
if (flags & STIO_DEV_PRO_WRITEIN)
{
/* slave should read */
close (pfds[1]);
pfds[1] = STIO_SYSHND_INVALID;
/* let the pipe be standard input */
if (dup2 (pfds[0], 0) <= -1) goto slave_oops;
close (pfds[0]);
pfds[0] = STIO_SYSHND_INVALID;
}
if (flags & STIO_DEV_PRO_READOUT)
{
/* slave should write */
close (pfds[2]);
pfds[2] = STIO_SYSHND_INVALID;
if (dup2(pfds[3], 1) == -1) goto slave_oops;
if (flags & STIO_DEV_PRO_ERRTOOUT)
{
if (dup2(pfds[3], 2) == -1) goto slave_oops;
}
close (pfds[3]);
pfds[3] = STIO_SYSHND_INVALID;
}
if (flags & STIO_DEV_PRO_READERR)
{
close (pfds[4]);
pfds[4] = STIO_SYSHND_INVALID;
if (dup2(pfds[5], 2) == -1) goto slave_oops;
if (flags & STIO_DEV_PRO_OUTTOERR)
{
if (dup2(pfds[5], 1) == -1) goto slave_oops;
}
close (pfds[5]);
pfds[5] = STIO_SYSHND_INVALID;
}
if ((flags & STIO_DEV_PRO_INTONUL) ||
(flags & STIO_DEV_PRO_OUTTONUL) ||
(flags & STIO_DEV_PRO_ERRTONUL))
{
#if defined(O_LARGEFILE)
devnull = open (STIO_MT("/dev/null"), O_RDWR | O_LARGEFILE, 0);
#else
devnull = open (STIO_MT("/dev/null"), O_RDWR, 0);
#endif
if (devnull == STIO_SYSHND_INVALID) goto slave_oops;
}
execv (param->argv[0], param->argv);
/* if exec fails, free 'param' parameter which is an inherited pointer */
free_param (stio, param);
slave_oops:
if (devnull != STIO_SYSHND_INVALID) close(devnull);
_exit (128);
}
/* parent process */
return pid;
}
static int dev_pro_make_master (stio_dev_t* dev, void* ctx)
{
stio_dev_pro_t* rdev = (stio_dev_pro_t*)dev;
stio_dev_pro_make_t* info = (stio_dev_pro_make_t*)ctx;
stio_syshnd_t pfds[6];
int i, minidx = -1, maxidx = -1;
param_t param;
pid_t pid;
if (info->flags & STIO_DEV_PRO_WRITEIN)
{
if (pipe(&pfds[0]) == -1)
{
dev->stio->errnum = stio_syserrtoerrnum(errno);
goto oops;
}
minidx = 0; maxidx = 1;
}
if (info->flags & STIO_DEV_PRO_READOUT)
{
if (pipe(&pfds[2]) == -1)
{
dev->stio->errnum = stio_syserrtoerrnum(errno);
goto oops;
}
if (minidx == -1) minidx = 2;
maxidx = 3;
}
if (info->flags & STIO_DEV_PRO_READERR)
{
if (pipe(&pfds[4]) == -1)
{
dev->stio->errnum = stio_syserrtoerrnum(errno);
goto oops;
}
if (minidx == -1) minidx = 4;
maxidx = 5;
}
if (maxidx == -1)
{
dev->stio->errnum = STIO_EINVAL;
goto oops;
}
if (make_param (rdev->stio, info->cmd, info->flags, &param) <= -1) goto oops;
/* TODO: more advanced fork and exec .. */
pid = standard_fork_and_exec (rdev->stio, pfds, info->flags, &param);
if (pid <= -1)
{
free_param (rdev->stio, &param);
goto oops;
}
free_param (rdev->stio, &param);
rdev->child_pid = pid;
/* this is the parent process */
if (info->flags & STIO_DEV_PRO_WRITEIN)
{
/*
* 012345
* rw----
* X
* WRITE => 1
*/
close (pfds[0]);
pfds[0] = STIO_SYSHND_INVALID;
if (stio_makesyshndasync (dev->stio, pfds[1]) <= -1) goto oops;
}
if (info->flags & STIO_DEV_PRO_READOUT)
{
/*
* 012345
* --rw--
* X
* READ => 2
*/
close (pfds[3]);
pfds[3] = STIO_SYSHND_INVALID;
if (stio_makesyshndasync (dev->stio, pfds[2]) <= -1) goto oops;
}
if (info->flags & STIO_DEV_PRO_READERR)
{
/*
* 012345
* ----rw
* X
* READ => 4
*/
close (pfds[5]);
pfds[5] = STIO_SYSHND_INVALID;
if (stio_makesyshndasync (dev->stio, pfds[4]) <= -1) goto oops;
}
if (pfds[1] != STIO_SYSHND_INVALID)
{
/* hand over pfds[2] to the first slave device */
slave_info_t si;
si.mi = info;
si.pfd = pfds[1];
si.dev_capa = STIO_DEV_CAPA_OUT | STIO_DEV_CAPA_OUT_QUEUED | STIO_DEV_CAPA_STREAM;
si.id = STIO_DEV_PRO_IN;
rdev->slave[STIO_DEV_PRO_IN] = make_slave (dev->stio, &si);
if (!rdev->slave[STIO_DEV_PRO_IN]) goto oops;
pfds[1] = STIO_SYSHND_INVALID;
rdev->slave_count++;
}
if (pfds[2] != STIO_SYSHND_INVALID)
{
/* hand over pfds[2] to the first slave device */
slave_info_t si;
si.mi = info;
si.pfd = pfds[2];
si.dev_capa = STIO_DEV_CAPA_IN | STIO_DEV_CAPA_STREAM;
si.id = STIO_DEV_PRO_OUT;
rdev->slave[STIO_DEV_PRO_OUT] = make_slave (dev->stio, &si);
if (!rdev->slave[STIO_DEV_PRO_OUT]) goto oops;
pfds[2] = STIO_SYSHND_INVALID;
rdev->slave_count++;
}
if (pfds[4] != STIO_SYSHND_INVALID)
{
/* hand over pfds[4] to the second slave device */
slave_info_t si;
si.mi = info;
si.pfd = pfds[4];
si.dev_capa = STIO_DEV_CAPA_IN | STIO_DEV_CAPA_STREAM;
si.id = STIO_DEV_PRO_ERR;
rdev->slave[STIO_DEV_PRO_ERR] = make_slave (dev->stio, &si);
if (!rdev->slave[STIO_DEV_PRO_ERR]) goto oops;
pfds[4] = STIO_SYSHND_INVALID;
rdev->slave_count++;
}
for (i = 0; i < STIO_COUNTOF(rdev->slave); i++)
{
if (rdev->slave[i]) rdev->slave[i]->master = rdev;
}
rdev->dev_capa = STIO_DEV_CAPA_VIRTUAL; /* the master device doesn't perform I/O */
rdev->flags = info->flags;
rdev->on_read = info->on_read;
rdev->on_write = info->on_write;
rdev->on_close = info->on_close;
return 0;
oops:
for (i = minidx; i < maxidx; i++)
{
if (pfds[i] != STIO_SYSHND_INVALID) close (pfds[i]);
}
if (rdev->mcmd)
{
STIO_MMGR_FREE (rdev->stio->mmgr, rdev->mcmd);
free_param (rdev->stio, &param);
}
for (i = STIO_COUNTOF(rdev->slave); i > 0; )
{
i--;
if (rdev->slave[i])
{
stio_killdev (rdev->stio, (stio_dev_t*)rdev->slave[i]);
rdev->slave[i] = STIO_NULL;
}
}
rdev->slave_count = 0;
return -1;
}
static int dev_pro_make_slave (stio_dev_t* dev, void* ctx)
{
stio_dev_pro_slave_t* rdev = (stio_dev_pro_slave_t*)dev;
slave_info_t* si = (slave_info_t*)ctx;
rdev->dev_capa = si->dev_capa;
rdev->id = si->id;
rdev->pfd = si->pfd;
/* keep rdev->master to STIO_NULL. it's set to the right master
* device in dev_pro_make() */
return 0;
}
static int dev_pro_kill_master (stio_dev_t* dev, int force)
{
stio_dev_pro_t* rdev = (stio_dev_pro_t*)dev;
int i, status;
pid_t wpid;
if (rdev->slave_count > 0)
{
for (i = 0; i < STIO_COUNTOF(rdev->slave); i++)
{
if (rdev->slave[i])
{
stio_dev_pro_slave_t* sdev = rdev->slave[i];
/* nullify the pointer to the slave device
* before calling stio_killdev() on the slave device.
* the slave device can check this pointer to tell from
* self-initiated termination or master-driven termination */
rdev->slave[i] = STIO_NULL;
stio_killdev (rdev->stio, (stio_dev_t*)sdev);
}
}
}
if (rdev->child_pid >= 0)
{
if (!(rdev->flags & STIO_DEV_PRO_FORGET_CHILD))
{
int killed = 0;
await_child:
wpid = waitpid (rdev->child_pid, &status, WNOHANG);
if (wpid == 0)
{
if (force && !killed)
{
if (!(rdev->flags & STIO_DEV_PRO_FORGET_DIEHARD_CHILD))
{
kill (rdev->child_pid, SIGKILL);
killed = 1;
goto await_child;
}
}
else
{
/* child process is still alive */
rdev->stio->errnum = STIO_EAGAIN;
return -1; /* call me again */
}
}
/* wpid == rdev->child_pid => full success
* wpid == -1 && errno == ECHILD => no such process. it's waitpid()'ed by some other part of the program?
* other cases ==> can't really handle properly. forget it by returning success
* no need not worry about EINTR because errno can't have the value when WNOHANG is set.
*/
}
printf (">>>>>>>>>>>>>>>>>>> REAPED CHILD %d\n", (int)rdev->child_pid);
rdev->child_pid = -1;
}
if (rdev->on_close) rdev->on_close (rdev, STIO_DEV_PRO_MASTER);
return 0;
}
static int dev_pro_kill_slave (stio_dev_t* dev, int force)
{
stio_dev_pro_slave_t* rdev = (stio_dev_pro_slave_t*)dev;
if (rdev->master)
{
stio_dev_pro_t* master;
master = rdev->master;
rdev->master = STIO_NULL;
/* indicate EOF */
if (master->on_close) master->on_close (master, rdev->id);
STIO_ASSERT (master->slave_count > 0);
master->slave_count--;
if (master->slave[rdev->id])
{
/* this call is started by the slave device itself.
* if this is the last slave, kill the master also */
if (master->slave_count <= 0)
{
stio_killdev (rdev->stio, (stio_dev_t*)master);
/* the master pointer is not valid from this point onwards
* as the actual master device object is freed in stio_killdev() */
}
}
else
{
/* this call is initiated by this slave device itself.
* if it were by the master device, it would be STIO_NULL as
* nullified by the dev_pro_kill() */
master->slave[rdev->id] = STIO_NULL;
}
}
if (rdev->pfd != STIO_SYSHND_INVALID)
{
close (rdev->pfd);
rdev->pfd = STIO_SYSHND_INVALID;
}
return 0;
}
static int dev_pro_read_slave (stio_dev_t* dev, void* buf, stio_iolen_t* len, stio_devaddr_t* srcaddr)
{
stio_dev_pro_slave_t* pro = (stio_dev_pro_slave_t*)dev;
ssize_t x;
x = read (pro->pfd, buf, *len);
if (x <= -1)
{
if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data available */
if (errno == EINTR) return 0;
pro->stio->errnum = stio_syserrtoerrnum(errno);
return -1;
}
*len = x;
return 1;
}
static int dev_pro_write_slave (stio_dev_t* dev, const void* data, stio_iolen_t* len, const stio_devaddr_t* dstaddr)
{
stio_dev_pro_slave_t* pro = (stio_dev_pro_slave_t*)dev;
ssize_t x;
x = write (pro->pfd, data, *len);
if (x <= -1)
{
if (errno == EINPROGRESS || errno == EWOULDBLOCK || errno == EAGAIN) return 0; /* no data can be written */
if (errno == EINTR) return 0;
pro->stio->errnum = stio_syserrtoerrnum(errno);
return -1;
}
*len = x;
return 1;
}
static stio_syshnd_t dev_pro_getsyshnd (stio_dev_t* dev)
{
return STIO_SYSHND_INVALID;
}
static stio_syshnd_t dev_pro_getsyshnd_slave (stio_dev_t* dev)
{
stio_dev_pro_slave_t* pro = (stio_dev_pro_slave_t*)dev;
return (stio_syshnd_t)pro->pfd;
}
static int dev_pro_ioctl (stio_dev_t* dev, int cmd, void* arg)
{
stio_dev_pro_t* rdev = (stio_dev_pro_t*)dev;
switch (cmd)
{
case STIO_DEV_PRO_CLOSE:
{
stio_dev_pro_sid_t sid = *(stio_dev_pro_sid_t*)arg;
if (sid < STIO_DEV_PRO_IN || sid > STIO_DEV_PRO_ERR)
{
rdev->stio->errnum = STIO_EINVAL;
return -1;
}
if (rdev->slave[sid])
{
/* unlike dev_pro_kill_master(), i don't nullify rdev->slave[sid].
* so i treat the closing ioctl as if it's a kill request
* initiated by the slave device itself. */
stio_killdev (rdev->stio, (stio_dev_t*)rdev->slave[sid]);
}
return 0;
}
case STIO_DEV_PRO_KILL_CHILD:
if (rdev->child_pid >= 0)
{
if (kill (rdev->child_pid, SIGKILL) == -1)
{
rdev->stio->errnum = stio_syserrtoerrnum(errno);
return -1;
}
}
return 0;
default:
dev->stio->errnum = STIO_EINVAL;
return -1;
}
}
static stio_dev_mth_t dev_pro_methods =
{
dev_pro_make_master,
dev_pro_kill_master,
dev_pro_getsyshnd,
STIO_NULL,
STIO_NULL,
dev_pro_ioctl
};
static stio_dev_mth_t dev_pro_methods_slave =
{
dev_pro_make_slave,
dev_pro_kill_slave,
dev_pro_getsyshnd_slave,
dev_pro_read_slave,
dev_pro_write_slave,
dev_pro_ioctl
};
/* ========================================================================= */
static int pro_ready (stio_dev_t* dev, int events)
{
/* virtual device. no I/O */
dev->stio->errnum = STIO_EINTERN;
return -1;
}
static int pro_on_read (stio_dev_t* dev, const void* data, stio_iolen_t len, const stio_devaddr_t* srcaddr)
{
/* virtual device. no I/O */
dev->stio->errnum = STIO_EINTERN;
return -1;
}
static int pro_on_write (stio_dev_t* dev, stio_iolen_t wrlen, void* wrctx, const stio_devaddr_t* dstaddr)
{
/* virtual device. no I/O */
dev->stio->errnum = STIO_EINTERN;
return -1;
}
static stio_dev_evcb_t dev_pro_event_callbacks =
{
pro_ready,
pro_on_read,
pro_on_write
};
/* ========================================================================= */
static int pro_ready_slave (stio_dev_t* dev, int events)
{
stio_dev_pro_t* pro = (stio_dev_pro_t*)dev;
if (events & STIO_DEV_EVENT_ERR)
{
pro->stio->errnum = STIO_EDEVERR;
return -1;
}
if (events & STIO_DEV_EVENT_HUP)
{
if (events & (STIO_DEV_EVENT_PRI | STIO_DEV_EVENT_IN | STIO_DEV_EVENT_OUT))
{
/* probably half-open? */
return 1;
}
pro->stio->errnum = STIO_EDEVHUP;
return -1;
}
return 1; /* the device is ok. carry on reading or writing */
}
static int pro_on_read_slave_out (stio_dev_t* dev, const void* data, stio_iolen_t len, const stio_devaddr_t* srcaddr)
{
stio_dev_pro_slave_t* pro = (stio_dev_pro_slave_t*)dev;
return pro->master->on_read (pro->master, data, len, STIO_DEV_PRO_OUT);
}
static int pro_on_read_slave_err (stio_dev_t* dev, const void* data, stio_iolen_t len, const stio_devaddr_t* srcaddr)
{
stio_dev_pro_slave_t* pro = (stio_dev_pro_slave_t*)dev;
return pro->master->on_read (pro->master, data, len, STIO_DEV_PRO_ERR);
}
static int pro_on_write_slave (stio_dev_t* dev, stio_iolen_t wrlen, void* wrctx, const stio_devaddr_t* dstaddr)
{
stio_dev_pro_slave_t* pro = (stio_dev_pro_slave_t*)dev;
return pro->master->on_write (pro->master, wrlen, wrctx);
}
static stio_dev_evcb_t dev_pro_event_callbacks_slave_in =
{
pro_ready_slave,
STIO_NULL,
pro_on_write_slave
};
static stio_dev_evcb_t dev_pro_event_callbacks_slave_out =
{
pro_ready_slave,
pro_on_read_slave_out,
STIO_NULL
};
static stio_dev_evcb_t dev_pro_event_callbacks_slave_err =
{
pro_ready_slave,
pro_on_read_slave_err,
STIO_NULL
};
/* ========================================================================= */
static stio_dev_pro_slave_t* make_slave (stio_t* stio, slave_info_t* si)
{
switch (si->id)
{
case STIO_DEV_PRO_IN:
return (stio_dev_pro_slave_t*)stio_makedev (
stio, STIO_SIZEOF(stio_dev_pro_t),
&dev_pro_methods_slave, &dev_pro_event_callbacks_slave_in, si);
case STIO_DEV_PRO_OUT:
return (stio_dev_pro_slave_t*)stio_makedev (
stio, STIO_SIZEOF(stio_dev_pro_t),
&dev_pro_methods_slave, &dev_pro_event_callbacks_slave_out, si);
case STIO_DEV_PRO_ERR:
return (stio_dev_pro_slave_t*)stio_makedev (
stio, STIO_SIZEOF(stio_dev_pro_t),
&dev_pro_methods_slave, &dev_pro_event_callbacks_slave_err, si);
default:
stio->errnum = STIO_EINVAL;
return STIO_NULL;
}
}
stio_dev_pro_t* stio_dev_pro_make (stio_t* stio, stio_size_t xtnsize, const stio_dev_pro_make_t* info)
{
return (stio_dev_pro_t*)stio_makedev (
stio, STIO_SIZEOF(stio_dev_pro_t) + xtnsize,
&dev_pro_methods, &dev_pro_event_callbacks, (void*)info);
}
void stio_dev_pro_kill (stio_dev_pro_t* dev)
{
stio_killdev (dev->stio, (stio_dev_t*)dev);
}
int stio_dev_pro_write (stio_dev_pro_t* dev, const void* data, stio_iolen_t dlen, void* wrctx)
{
if (dev->slave[0])
{
return stio_dev_write ((stio_dev_t*)dev->slave[0], data, dlen, wrctx, STIO_NULL);
}
else
{
dev->stio->errnum = STIO_ENOCAPA; /* TODO: is it the right error number? */
return -1;
}
}
int stio_dev_pro_timedwrite (stio_dev_pro_t* dev, const void* data, stio_iolen_t dlen, const stio_ntime_t* tmout, void* wrctx)
{
if (dev->slave[0])
{
return stio_dev_timedwrite ((stio_dev_t*)dev->slave[0], data, dlen, tmout, wrctx, STIO_NULL);
}
else
{
dev->stio->errnum = STIO_ENOCAPA; /* TODO: is it the right error number? */
return -1;
}
}
int stio_dev_pro_close (stio_dev_pro_t* dev, stio_dev_pro_sid_t sid)
{
return stio_dev_ioctl ((stio_dev_t*)dev, STIO_DEV_PRO_CLOSE, &sid);
}
int stio_dev_pro_killchild (stio_dev_pro_t* dev)
{
return stio_dev_ioctl ((stio_dev_t*)dev, STIO_DEV_PRO_KILL_CHILD, STIO_NULL);
}
#if 0
stio_dev_pro_t* stio_dev_pro_getdev (stio_dev_pro_t* pro, stio_dev_pro_sid_t sid)
{
switch (type)
{
case STIO_DEV_PRO_IN:
return XXX;
case STIO_DEV_PRO_OUT:
return XXX;
case STIO_DEV_PRO_ERR:
return XXX;
}
pro->dev->stio = STIO_EINVAL;
return STIO_NULL;
}
#endif

164
mio/lib/stio-pro.h Normal file
View File

@ -0,0 +1,164 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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.
*/
#ifndef _STIO_PRO_H_
#define _STIO_PRO_H_
#include <stio.h>
enum stio_dev_pro_sid_t
{
STIO_DEV_PRO_MASTER = -1,
STIO_DEV_PRO_IN = 0,
STIO_DEV_PRO_OUT = 1,
STIO_DEV_PRO_ERR = 2
};
typedef enum stio_dev_pro_sid_t stio_dev_pro_sid_t;
typedef struct stio_dev_pro_t stio_dev_pro_t;
typedef struct stio_dev_pro_slave_t stio_dev_pro_slave_t;
typedef int (*stio_dev_pro_on_read_t) (stio_dev_pro_t* dev, const void* data, stio_iolen_t len, stio_dev_pro_sid_t sid);
typedef int (*stio_dev_pro_on_write_t) (stio_dev_pro_t* dev, stio_iolen_t wrlen, void* wrctx);
typedef void (*stio_dev_pro_on_close_t) (stio_dev_pro_t* dev, stio_dev_pro_sid_t sid);
struct stio_dev_pro_t
{
STIO_DEV_HEADERS;
int flags;
stio_intptr_t child_pid;
stio_dev_pro_slave_t* slave[3];
int slave_count;
stio_dev_pro_on_read_t on_read;
stio_dev_pro_on_write_t on_write;
stio_dev_pro_on_close_t on_close;
stio_mchar_t* mcmd;
};
struct stio_dev_pro_slave_t
{
STIO_DEV_HEADERS;
stio_dev_pro_sid_t id;
stio_syshnd_t pfd;
stio_dev_pro_t* master; /* parent device */
};
enum stio_dev_pro_make_flag_t
{
STIO_DEV_PRO_WRITEIN = (1 << 0),
STIO_DEV_PRO_READOUT = (1 << 1),
STIO_DEV_PRO_READERR = (1 << 2),
STIO_DEV_PRO_ERRTOOUT = (1 << 3),
STIO_DEV_PRO_OUTTOERR = (1 << 4),
STIO_DEV_PRO_INTONUL = (1 << 5),
STIO_DEV_PRO_OUTTONUL = (1 << 6),
STIO_DEV_PRO_ERRTONUL = (1 << 7),
STUO_DEV_PRO_DROPIN = (1 << 8),
STUO_DEV_PRO_DROPOUT = (1 << 9),
STUO_DEV_PRO_DROPERR = (1 << 10),
STIO_DEV_PRO_SHELL = (1 << 13),
/* perform no waitpid() on a child process upon device destruction.
* you should set this flag if your application has automatic child
* process reaping enabled. for instance, SIGCHLD is set to SIG_IGN
* on POSIX.1-2001 compliant systems */
STIO_DEV_PRO_FORGET_CHILD = (1 << 14),
STIO_DEV_PRO_FORGET_DIEHARD_CHILD = (1 << 15)
};
typedef enum stio_dev_pro_make_flag_t stio_dev_pro_make_flag_t;
typedef struct stio_dev_pro_make_t stio_dev_pro_make_t;
struct stio_dev_pro_make_t
{
int flags; /**< bitwise-ORed of stio_dev_pro_make_flag_t enumerators */
const void* cmd;
stio_dev_pro_on_write_t on_write; /* mandatory */
stio_dev_pro_on_read_t on_read; /* mandatory */
stio_dev_pro_on_close_t on_close; /* optional */
};
enum stio_dev_pro_ioctl_cmd_t
{
STIO_DEV_PRO_CLOSE,
STIO_DEV_PRO_KILL_CHILD
};
typedef enum stio_dev_pro_ioctl_cmd_t stio_dev_pro_ioctl_cmd_t;
#ifdef __cplusplus
extern "C" {
#endif
STIO_EXPORT stio_dev_pro_t* stio_dev_pro_make (
stio_t* stio,
stio_size_t xtnsize,
const stio_dev_pro_make_t* data
);
STIO_EXPORT void stio_dev_pro_kill (
stio_dev_pro_t* pro
);
STIO_EXPORT int stio_dev_pro_write (
stio_dev_pro_t* pro,
const void* data,
stio_iolen_t len,
void* wrctx
);
STIO_EXPORT int stio_dev_pro_timedwrite (
stio_dev_pro_t* pro,
const void* data,
stio_iolen_t len,
const stio_ntime_t* tmout,
void* wrctx
);
STIO_EXPORT int stio_dev_pro_close (
stio_dev_pro_t* pro,
stio_dev_pro_sid_t sid
);
STIO_EXPORT int stio_dev_pro_killchild (
stio_dev_pro_t* pro
);
#ifdef __cplusplus
}
#endif
#endif

204
mio/lib/stio-prv.h Normal file
View File

@ -0,0 +1,204 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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.
*/
#ifndef _STIO_PRV_H_
#define _STIO_PRV_H_
#include "stio.h"
/*TODO: redefine and remove these */
#include <assert.h>
#include <string.h>
#include <stdio.h>
/*TODO: redefine these */
#define STIO_MEMSET(dst,byte,count) memset(dst,byte,count)
#define STIO_MEMCPY(dst,src,count) memcpy(dst,src,count)
#define STIO_MEMMOVE(dst,src,count) memmove(dst,src,count)
#define STIO_MEMCMP(dst,src,count) memcmp(dst,src,count)
#define STIO_ASSERT assert
typedef struct stio_mux_t stio_mux_t;
struct stio_t
{
stio_mmgr_t* mmgr;
stio_errnum_t errnum;
stio_stopreq_t stopreq; /* stop request to abort stio_loop() */
struct
{
stio_dev_t* head;
stio_dev_t* tail;
} actdev; /* active devices */
struct
{
stio_dev_t* head;
stio_dev_t* tail;
} hltdev; /* halted devices */
struct
{
stio_dev_t* head;
stio_dev_t* tail;
} zmbdev; /* zombie devices */
stio_uint8_t bigbuf[65535]; /* TODO: make this dynamic depending on devices added. device may indicate a buffer size required??? */
unsigned int renew_watch: 1;
unsigned int in_exec: 1;
struct
{
stio_size_t capa;
stio_size_t size;
stio_tmrjob_t* jobs;
} tmr;
/* platform specific fields below */
#if defined(_WIN32)
HANDLE iocp;
#else
stio_mux_t* mux;
#endif
};
#define STIO_EPOCH_YEAR (1970)
#define STIO_EPOCH_MON (1)
#define STIO_EPOCH_DAY (1)
#define STIO_EPOCH_WDAY (4)
/* windows specific epoch time */
#define STIO_EPOCH_YEAR_WIN (1601)
#define STIO_EPOCH_MON_WIN (1)
#define STIO_EPOCH_DAY_WIN (1)
#define STIO_DAYS_PER_WEEK (7)
#define STIO_MONS_PER_YEAR (12)
#define STIO_HOURS_PER_DAY (24)
#define STIO_MINS_PER_HOUR (60)
#define STIO_MINS_PER_DAY (STIO_MINS_PER_HOUR*STIO_HOURS_PER_DAY)
#define STIO_SECS_PER_MIN (60)
#define STIO_SECS_PER_HOUR (STIO_SECS_PER_MIN*STIO_MINS_PER_HOUR)
#define STIO_SECS_PER_DAY (STIO_SECS_PER_MIN*STIO_MINS_PER_DAY)
#define STIO_MSECS_PER_SEC (1000)
#define STIO_MSECS_PER_MIN (STIO_MSECS_PER_SEC*STIO_SECS_PER_MIN)
#define STIO_MSECS_PER_HOUR (STIO_MSECS_PER_SEC*STIO_SECS_PER_HOUR)
#define STIO_MSECS_PER_DAY (STIO_MSECS_PER_SEC*STIO_SECS_PER_DAY)
#define STIO_USECS_PER_MSEC (1000)
#define STIO_NSECS_PER_USEC (1000)
#define STIO_NSECS_PER_MSEC (STIO_NSECS_PER_USEC*STIO_USECS_PER_MSEC)
#define STIO_USECS_PER_SEC (STIO_USECS_PER_MSEC*STIO_MSECS_PER_SEC)
#define STIO_NSECS_PER_SEC (STIO_NSECS_PER_USEC*STIO_USECS_PER_MSEC*STIO_MSECS_PER_SEC)
#define STIO_SECNSEC_TO_MSEC(sec,nsec) \
(((stio_intptr_t)(sec) * STIO_MSECS_PER_SEC) + ((stio_intptr_t)(nsec) / STIO_NSECS_PER_MSEC))
#define STIO_SECNSEC_TO_USEC(sec,nsec) \
(((stio_intptr_t)(sec) * STIO_USECS_PER_SEC) + ((stio_intptr_t)(nsec) / STIO_NSECS_PER_USEC))
#define STIO_SEC_TO_MSEC(sec) ((sec) * STIO_MSECS_PER_SEC)
#define STIO_MSEC_TO_SEC(sec) ((sec) / STIO_MSECS_PER_SEC)
#define STIO_USEC_TO_NSEC(usec) ((usec) * STIO_NSECS_PER_USEC)
#define STIO_NSEC_TO_USEC(nsec) ((nsec) / STIO_NSECS_PER_USEC)
#define STIO_MSEC_TO_NSEC(msec) ((msec) * STIO_NSECS_PER_MSEC)
#define STIO_NSEC_TO_MSEC(nsec) ((nsec) / STIO_NSECS_PER_MSEC)
#define STIO_SEC_TO_NSEC(sec) ((sec) * STIO_NSECS_PER_SEC)
#define STIO_NSEC_TO_SEC(nsec) ((nsec) / STIO_NSECS_PER_SEC)
#define STIO_SEC_TO_USEC(sec) ((sec) * STIO_USECS_PER_SEC)
#define STIO_USEC_TO_SEC(usec) ((usec) / STIO_USECS_PER_SEC)
#ifdef __cplusplus
extern "C" {
#endif
int stio_makesyshndasync (
stio_t* stio,
stio_syshnd_t hnd
);
stio_errnum_t stio_syserrtoerrnum (
int no
);
stio_mchar_t* stio_mbsdup (
stio_t* stio,
const stio_mchar_t* src
);
stio_size_t stio_mbscpy (
stio_mchar_t* buf,
const stio_mchar_t* str
);
int stio_mbsspltrn (
stio_mchar_t* s,
const stio_mchar_t* delim,
stio_mchar_t lquote,
stio_mchar_t rquote,
stio_mchar_t escape,
const stio_mchar_t* trset
);
int stio_mbsspl (
stio_mchar_t* s,
const stio_mchar_t* delim,
stio_mchar_t lquote,
stio_mchar_t rquote,
stio_mchar_t escape
);
void stio_cleartmrjobs (
stio_t* stio
);
void stio_firetmrjobs (
stio_t* stio,
const stio_ntime_t* tmbase,
stio_size_t* firecnt
);
int stio_gettmrtmout (
stio_t* stio,
const stio_ntime_t* tmbase,
stio_ntime_t* tmout
);
#ifdef __cplusplus
}
#endif
#endif

1705
mio/lib/stio-sck.c Normal file

File diff suppressed because it is too large Load Diff

600
mio/lib/stio-sck.h Normal file
View File

@ -0,0 +1,600 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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.
*/
#ifndef _STIO_SCK_H_
#define _STIO_SCK_H_
#include <stio.h>
/* ========================================================================= */
/* TOOD: move these to a separte file */
#define STIO_ETHHDR_PROTO_IP4 0x0800
#define STIO_ETHHDR_PROTO_ARP 0x0806
#define STIO_ETHHDR_PROTO_8021Q 0x8100 /* 802.1Q VLAN */
#define STIO_ETHHDR_PROTO_IP6 0x86DD
#define STIO_ARPHDR_OPCODE_REQUEST 1
#define STIO_ARPHDR_OPCODE_REPLY 2
#define STIO_ARPHDR_HTYPE_ETH 0x0001
#define STIO_ARPHDR_PTYPE_IP4 0x0800
#define STIO_ETHADDR_LEN 6
#define STIO_IP4ADDR_LEN 4
#define STIO_IP6ADDR_LEN 16
#if defined(__GNUC__)
# define STIO_PACKED __attribute__((__packed__))
#else
# define STIO_PACKED
# STIO_PACK_PUSH pack(push)
# STIO_PACK_PUSH pack(push)
# STIO_PACK(x) pack(x)
#endif
#if defined(__GNUC__)
/* nothing */
#else
#pragma pack(push)
#pragma pack(1)
#endif
struct STIO_PACKED stio_ethaddr_t
{
stio_uint8_t v[STIO_ETHADDR_LEN];
};
typedef struct stio_ethaddr_t stio_ethaddr_t;
struct STIO_PACKED stio_ip4addr_t
{
stio_uint8_t v[STIO_IP4ADDR_LEN];
};
typedef struct stio_ip4addr_t stio_ip4addr_t;
struct STIO_PACKED stio_ip6addr_t
{
stio_uint8_t v[STIO_IP6ADDR_LEN];
};
typedef struct stio_ip6addr_t stio_ip6addr_t;
struct STIO_PACKED stio_ethhdr_t
{
stio_uint8_t dest[STIO_ETHADDR_LEN];
stio_uint8_t source[STIO_ETHADDR_LEN];
stio_uint16_t proto;
};
typedef struct stio_ethhdr_t stio_ethhdr_t;
struct STIO_PACKED stio_arphdr_t
{
stio_uint16_t htype; /* hardware type (ethernet: 0x0001) */
stio_uint16_t ptype; /* protocol type (ipv4: 0x0800) */
stio_uint8_t hlen; /* hardware address length (ethernet: 6) */
stio_uint8_t plen; /* protocol address length (ipv4 :4) */
stio_uint16_t opcode; /* operation code */
};
typedef struct stio_arphdr_t stio_arphdr_t;
/* arp payload for ipv4 over ethernet */
struct STIO_PACKED stio_etharp_t
{
stio_uint8_t sha[STIO_ETHADDR_LEN]; /* source hardware address */
stio_uint8_t spa[STIO_IP4ADDR_LEN]; /* source protocol address */
stio_uint8_t tha[STIO_ETHADDR_LEN]; /* target hardware address */
stio_uint8_t tpa[STIO_IP4ADDR_LEN]; /* target protocol address */
};
typedef struct stio_etharp_t stio_etharp_t;
struct STIO_PACKED stio_etharp_pkt_t
{
stio_ethhdr_t ethhdr;
stio_arphdr_t arphdr;
stio_etharp_t arppld;
};
typedef struct stio_etharp_pkt_t stio_etharp_pkt_t;
struct stio_iphdr_t
{
#if defined(STIO_ENDIAN_LITTLE)
stio_uint8_t ihl:4;
stio_uint8_t version:4;
#elif defined(STIO_ENDIAN_BIG)
stio_uint8_t version:4;
stio_uint8_t ihl:4;
#else
# UNSUPPORTED ENDIAN
#endif
stio_int8_t tos;
stio_int16_t tot_len;
stio_int16_t id;
stio_int16_t frag_off;
stio_int8_t ttl;
stio_int8_t protocol;
stio_int16_t check;
stio_int32_t saddr;
stio_int32_t daddr;
/*The options start here. */
};
typedef struct stio_iphdr_t stio_iphdr_t;
struct STIO_PACKED stio_icmphdr_t
{
stio_uint8_t type; /* message type */
stio_uint8_t code; /* subcode */
stio_uint16_t checksum;
union
{
struct
{
stio_uint16_t id;
stio_uint16_t seq;
} echo;
stio_uint32_t gateway;
struct
{
stio_uint16_t frag_unused;
stio_uint16_t mtu;
} frag; /* path mut discovery */
} u;
};
typedef struct stio_icmphdr_t stio_icmphdr_t;
#if defined(__GNUC__)
/* nothing */
#else
#pragma pack(pop)
#endif
/* ICMP types */
#define STIO_ICMP_ECHO_REPLY 0
#define STIO_ICMP_UNREACH 3 /* destination unreachable */
#define STIO_ICMP_SOURCE_QUENCE 4
#define STIO_ICMP_REDIRECT 5
#define STIO_ICMP_ECHO_REQUEST 8
#define STIO_ICMP_TIME_EXCEEDED 11
#define STIO_ICMP_PARAM_PROBLEM 12
#define STIO_ICMP_TIMESTAMP_REQUEST 13
#define STIO_ICMP_TIMESTAMP_REPLY 14
#define STIO_ICMP_INFO_REQUEST 15
#define STIO_ICMP_INFO_REPLY 16
#define STIO_ICMP_ADDR_MASK_REQUEST 17
#define STIO_ICMP_ADDR_MASK_REPLY 18
/* Subcode for STIO_ICMP_UNREACH */
#define STIO_ICMP_UNREACH_NET 0
#define STIO_ICMP_UNREACH_HOST 1
#define STIO_ICMP_UNREACH_PROTOCOL 2
#define STIO_ICMP_UNREACH_PORT 3
#define STIO_ICMP_UNREACH_FRAG_NEEDED 4
/* Subcode for STIO_ICMP_REDIRECT */
#define STIO_ICMP_REDIRECT_NET 0
#define STIO_ICMP_REDIRECT_HOST 1
#define STIO_ICMP_REDIRECT_NETTOS 2
#define STIO_ICMP_REDIRECT_HOSTTOS 3
/* Subcode for STIO_ICMP_TIME_EXCEEDED */
#define STIO_ICMP_TIME_EXCEEDED_TTL 0
#define STIO_ICMP_TIME_EXCEEDED_FRAGTIME 1
/* ========================================================================= */
typedef int stio_sckfam_t;
struct stio_sckaddr_t
{
stio_sckfam_t family;
stio_uint8_t data[128]; /* TODO: use the actual sockaddr size */
};
typedef struct stio_sckaddr_t stio_sckaddr_t;
#if (STIO_SIZEOF_SOCKLEN_T == STIO_SIZEOF_INT)
#if defined(STIO_SOCKLEN_T_IS_SIGNED)
typedef int stio_scklen_t;
#else
typedef unsigned int stio_scklen_t;
#endif
#elif (STIO_SIZEOF_SOCKLEN_T == STIO_SIZEOF_LONG)
#if defined(STIO_SOCKLEN_T_IS_SIGNED)
typedef long stio_scklen_t;
#else
typedef unsigned long stio_scklen_t;
#endif
#else
typedef int stio_scklen_t;
#endif
#if defined(_WIN32)
# define STIO_IOCP_KEY 1
/*
typedef HANDLE stio_syshnd_t;
typedef SOCKET stio_sckhnd_t;
# define STIO_SCKHND_INVALID (INVALID_SOCKET)
*/
typedef stio_uintptr_t qse_sckhnd_t;
# define STIO_SCKHND_INVALID (~(qse_sck_hnd_t)0)
#else
typedef int stio_sckhnd_t;
# define STIO_SCKHND_INVALID (-1)
#endif
/* ========================================================================= */
enum stio_dev_sck_ioctl_cmd_t
{
STIO_DEV_SCK_BIND,
STIO_DEV_SCK_CONNECT,
STIO_DEV_SCK_LISTEN
};
typedef enum stio_dev_sck_ioctl_cmd_t stio_dev_sck_ioctl_cmd_t;
#define STIO_DEV_SCK_SET_PROGRESS(dev,bit) do { \
(dev)->state &= ~STIO_DEV_SCK_ALL_PROGRESS_BITS; \
(dev)->state |= (bit); \
} while(0)
#define STIO_DEV_SCK_GET_PROGRESS(dev) ((dev)->state & STIO_DEV_SCK_ALL_PROGRESS_BITS)
enum stio_dev_sck_state_t
{
/* the following items(progress bits) are mutually exclusive */
STIO_DEV_SCK_CONNECTING = (1 << 0),
STIO_DEV_SCK_CONNECTING_SSL = (1 << 1),
STIO_DEV_SCK_CONNECTED = (1 << 2),
STIO_DEV_SCK_LISTENING = (1 << 3),
STIO_DEV_SCK_ACCEPTING_SSL = (1 << 4),
STIO_DEV_SCK_ACCEPTED = (1 << 5),
/* the following items can be bitwise-ORed with an exclusive item above */
STIO_DEV_SCK_INTERCEPTED = (1 << 15),
/* convenience bit masks */
STIO_DEV_SCK_ALL_PROGRESS_BITS = (STIO_DEV_SCK_CONNECTING |
STIO_DEV_SCK_CONNECTING_SSL |
STIO_DEV_SCK_CONNECTED |
STIO_DEV_SCK_LISTENING |
STIO_DEV_SCK_ACCEPTING_SSL |
STIO_DEV_SCK_ACCEPTED)
};
typedef enum stio_dev_sck_state_t stio_dev_sck_state_t;
typedef struct stio_dev_sck_t stio_dev_sck_t;
typedef int (*stio_dev_sck_on_read_t) (
stio_dev_sck_t* dev,
const void* data,
stio_iolen_t dlen,
const stio_sckaddr_t* srcaddr
);
typedef int (*stio_dev_sck_on_write_t) (
stio_dev_sck_t* dev,
stio_iolen_t wrlen,
void* wrctx,
const stio_sckaddr_t* dstaddr
);
typedef void (*stio_dev_sck_on_disconnect_t) (
stio_dev_sck_t* dev
);
typedef int (*stio_dev_sck_on_connect_t) (
stio_dev_sck_t* dev
);
enum stio_dev_sck_type_t
{
STIO_DEV_SCK_TCP4,
STIO_DEV_SCK_TCP6,
STIO_DEV_SCK_UPD4,
STIO_DEV_SCK_UDP6,
/* ARP at the ethernet layer */
STIO_DEV_SCK_ARP,
STIO_DEV_SCK_ARP_DGRAM,
/* ICMP at the IPv4 layer */
STIO_DEV_SCK_ICMP4,
/* ICMP at the IPv6 layer */
STIO_DEV_SCK_ICMP6
#if 0
STIO_DEV_SCK_RAW, /* raw L2-level packet */
#endif
};
typedef enum stio_dev_sck_type_t stio_dev_sck_type_t;
typedef struct stio_dev_sck_make_t stio_dev_sck_make_t;
struct stio_dev_sck_make_t
{
stio_dev_sck_type_t type;
stio_dev_sck_on_write_t on_write;
stio_dev_sck_on_read_t on_read;
stio_dev_sck_on_disconnect_t on_disconnect;
};
enum stio_dev_sck_bind_option_t
{
STIO_DEV_SCK_BIND_BROADCAST = (1 << 0),
STIO_DEV_SCK_BIND_REUSEADDR = (1 << 1),
STIO_DEV_SCK_BIND_REUSEPORT = (1 << 2),
STIO_DEV_SCK_BIND_TRANSPARENT = (1 << 3),
/* TODO: more options --- SO_RCVBUF, SO_SNDBUF, SO_RCVTIMEO, SO_SNDTIMEO, SO_KEEPALIVE */
/* BINDTODEVICE??? */
STIO_DEV_SCK_BIND_SSL = (1 << 15)
};
typedef enum stio_dev_sck_bind_option_t stio_dev_sck_bind_option_t;
typedef struct stio_dev_sck_bind_t stio_dev_sck_bind_t;
struct stio_dev_sck_bind_t
{
int options;
stio_sckaddr_t localaddr;
/* TODO: add device name for BIND_TO_DEVICE */
const stio_mchar_t* ssl_certfile;
const stio_mchar_t* ssl_keyfile;
stio_ntime_t accept_tmout;
};
enum stio_def_sck_connect_option_t
{
STIO_DEV_SCK_CONNECT_SSL = (1 << 15)
};
typedef enum stio_dev_sck_connect_option_t stio_dev_sck_connect_option_t;
typedef struct stio_dev_sck_connect_t stio_dev_sck_connect_t;
struct stio_dev_sck_connect_t
{
int options;
stio_sckaddr_t remoteaddr;
stio_ntime_t connect_tmout;
stio_dev_sck_on_connect_t on_connect;
};
typedef struct stio_dev_sck_listen_t stio_dev_sck_listen_t;
struct stio_dev_sck_listen_t
{
int backlogs;
stio_dev_sck_on_connect_t on_connect; /* optional, but new connections are dropped immediately without this */
};
typedef struct stio_dev_sck_accept_t stio_dev_sck_accept_t;
struct stio_dev_sck_accept_t
{
stio_syshnd_t sck;
/* TODO: add timeout */
stio_sckaddr_t remoteaddr;
};
struct stio_dev_sck_t
{
STIO_DEV_HEADERS;
stio_dev_sck_type_t type;
stio_sckhnd_t sck;
int state;
/* remote peer address for a stateful stream socket. valid if one of the
* followings is set in state:
* STIO_DEV_TCP_ACCEPTING_SSL
* STIO_DEV_TCP_ACCEPTED
* STIO_DEV_TCP_CONNECTED
* STIO_DEV_TCP_CONNECTING
* STIO_DEV_TCP_CONNECTING_SSL
*
* also used as a placeholder to store source address for
* a stateless socket */
stio_sckaddr_t remoteaddr;
/* local socket address */
stio_sckaddr_t localaddr;
/* original destination address */
stio_sckaddr_t orgdstaddr;
stio_dev_sck_on_write_t on_write;
stio_dev_sck_on_read_t on_read;
/* return 0 on succes, -1 on failure.
* called on a new tcp device for an accepted client or
* on a tcp device conntected to a remote server */
stio_dev_sck_on_connect_t on_connect;
stio_dev_sck_on_disconnect_t on_disconnect;
/* timer job index for handling
* - connect() timeout for a connecting socket.
* - SSL_accept() timeout for a socket accepting SSL */
stio_tmridx_t tmrjob_index;
/* connect timeout, ssl-connect timeout, ssl-accept timeout.
* it denotes timeout duration under some circumstances
* or an absolute expiry time under some other circumstances. */
stio_ntime_t tmout;
void* ssl_ctx;
void* ssl;
};
#ifdef __cplusplus
extern "C" {
#endif
STIO_EXPORT stio_sckhnd_t stio_openasyncsck (
stio_t* stio,
int domain,
int type,
int proto
);
STIO_EXPORT void stio_closeasyncsck (
stio_t* stio,
stio_sckhnd_t sck
);
STIO_EXPORT int stio_makesckasync (
stio_t* stio,
stio_sckhnd_t sck
);
STIO_EXPORT int stio_getsckaddrinfo (
stio_t* stio,
const stio_sckaddr_t* addr,
stio_scklen_t* len,
stio_sckfam_t* family
);
/*
* The stio_getsckaddrport() function returns the port number of a socket
* address in the host byte order. If the address doesn't support the port
* number, it returns 0.
*/
STIO_EXPORT stio_uint16_t stio_getsckaddrport (
const stio_sckaddr_t* addr
);
/*
* The stio_getsckaddrifindex() function returns an interface number.
* If the address doesn't support the interface number, it returns 0. */
STIO_EXPORT int stio_getsckaddrifindex (
const stio_sckaddr_t* addr
);
STIO_EXPORT void stio_sckaddr_initforip4 (
stio_sckaddr_t* sckaddr,
stio_uint16_t port,
stio_ip4addr_t* ip4addr
);
STIO_EXPORT void stio_sckaddr_initforip6 (
stio_sckaddr_t* sckaddr,
stio_uint16_t port,
stio_ip6addr_t* ip6addr
);
STIO_EXPORT void stio_sckaddr_initforeth (
stio_sckaddr_t* sckaddr,
int ifindex,
stio_ethaddr_t* ethaddr
);
/* ========================================================================= */
STIO_EXPORT stio_dev_sck_t* stio_dev_sck_make (
stio_t* stio,
stio_size_t xtnsize,
const stio_dev_sck_make_t* info
);
STIO_EXPORT int stio_dev_sck_bind (
stio_dev_sck_t* dev,
stio_dev_sck_bind_t* info
);
STIO_EXPORT int stio_dev_sck_connect (
stio_dev_sck_t* dev,
stio_dev_sck_connect_t* info
);
STIO_EXPORT int stio_dev_sck_listen (
stio_dev_sck_t* dev,
stio_dev_sck_listen_t* info
);
STIO_EXPORT int stio_dev_sck_write (
stio_dev_sck_t* dev,
const void* data,
stio_iolen_t len,
void* wrctx,
const stio_sckaddr_t* dstaddr
);
STIO_EXPORT int stio_dev_sck_timedwrite (
stio_dev_sck_t* dev,
const void* data,
stio_iolen_t len,
const stio_ntime_t* tmout,
void* wrctx,
const stio_sckaddr_t* dstaddr
);
#if defined(STIO_HAVE_INLINE)
static STIO_INLINE void stio_dev_sck_halt (stio_dev_sck_t* sck)
{
stio_dev_halt ((stio_dev_t*)sck);
}
static STIO_INLINE int stio_dev_sck_read (stio_dev_sck_t* sck, int enabled)
{
return stio_dev_read ((stio_dev_t*)sck, enabled);
}
#else
#define stio_dev_sck_halt(sck) stio_dev_halt((stio_dev_t*)sck)
#define stio_dev_sck_read(sck,enabled) stio_dev_read((stio_dev_t*)sck, enabled)
#endif
STIO_EXPORT stio_uint16_t stio_checksumip (
const void* hdr,
stio_size_t len
);
#ifdef __cplusplus
}
#endif
#endif

205
mio/lib/stio-tim.c Normal file
View File

@ -0,0 +1,205 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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 WARRANTIES
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 "stio-prv.h"
#if defined(_WIN32)
# include <windows.h>
# include <time.h>
#elif defined(__OS2__)
# define INCL_DOSDATETIME
# define INCL_DOSERRORS
# include <os2.h>
# include <time.h>
#elif defined(__DOS__)
# include <dos.h>
# include <time.h>
#else
# if defined(HAVE_SYS_TIME_H)
# include <sys/time.h>
# endif
# if defined(HAVE_TIME_H)
# include <time.h>
# endif
# include <errno.h>
#endif
#if defined(_WIN32)
#define EPOCH_DIFF_YEARS (STIO_EPOCH_YEAR-STIO_EPOCH_YEAR_WIN)
#define EPOCH_DIFF_DAYS ((stio_intptr_t)EPOCH_DIFF_YEARS*365+EPOCH_DIFF_YEARS/4-3)
#define EPOCH_DIFF_SECS ((stio_intptr_t)EPOCH_DIFF_DAYS*24*60*60)
#endif
void stio_gettime (stio_ntime_t* t)
{
#if defined(_WIN32)
SYSTEMTIME st;
FILETIME ft;
ULARGE_INTEGER li;
/*
* MSDN: The FILETIME structure is a 64-bit value representing the
* number of 100-nanosecond intervals since January 1, 1601 (UTC).
*/
GetSystemTime (&st);
SystemTimeToFileTime (&st, &ft); /* this must not fail */
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
/* li.QuadPart is in the 100-nanosecond intervals */
t->sec = (li.QuadPart / (STIO_NSECS_PER_SEC / 100)) - EPOCH_DIFF_SECS;
t->nsec = (li.QuadPart % (STIO_NSECS_PER_SEC / 100)) * 100;
#elif defined(__OS2__)
DATETIME dt;
stio_btime_t bt;
/* Can I use DosQuerySysInfo(QSV_TIME_LOW) and
* DosQuerySysInfo(QSV_TIME_HIGH) for this instead?
* Maybe, resolution too low as it returns values
* in seconds. */
DosGetDateTime (&dt);
/* DosGetDateTime() never fails. it always returns NO_ERROR */
bt.year = dt.year - STIO_BTIME_YEAR_BASE;
bt.mon = dt.month - 1;
bt.mday = dt.day;
bt.hour = dt.hours;
bt.min = dt.minutes;
bt.sec = dt.seconds;
/*bt.msec = dt.hundredths * 10;*/
bt.isdst = -1; /* determine dst for me */
if (stio_timelocal (&bt, t) <= -1)
{
t->sec = time (STIO_NULL);
t->nsec = 0;
}
else
{
t->nsec = STIO_MSEC_TO_NSEC(dt.hundredths * 10);
}
return 0;
#elif defined(__DOS__)
struct dostime_t dt;
struct dosdate_t dd;
stio_btime_t bt;
_dos_gettime (&dt);
_dos_getdate (&dd);
bt.year = dd.year - STIO_BTIME_YEAR_BASE;
bt.mon = dd.month - 1;
bt.mday = dd.day;
bt.hour = dt.hour;
bt.min = dt.minute;
bt.sec = dt.second;
/*bt.msec = dt.hsecond * 10; */
bt.isdst = -1; /* determine dst for me */
if (stio_timelocal (&bt, t) <= -1)
{
t->sec = time (STIO_NULL);
t->nsec = 0;
}
else
{
t->nsec = STIO_MSEC_TO_NSEC(dt.hsecond * 10);
}
#elif defined(macintosh)
unsigned long tv;
GetDateTime (&tv);
t->sec = tv;
tv->nsec = 0;
#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME)
struct timespec ts;
if (clock_gettime (CLOCK_REALTIME, &ts) == -1 && errno == EINVAL)
{
#if defined(HAVE_GETTIMEOFDAY)
struct timeval tv;
gettimeofday (&tv, STIO_NULL);
t->sec = tv.tv_sec;
t->nsec = STIO_USEC_TO_NSEC(tv.tv_usec);
#else
t->sec = time (STIO_NULL);
t->nsec = 0;
#endif
}
t->sec = ts.tv_sec;
t->nsec = ts.tv_nsec;
#elif defined(HAVE_GETTIMEOFDAY)
struct timeval tv;
gettimeofday (&tv, STIO_NULL);
t->sec = tv.tv_sec;
t->nsec = STIO_USEC_TO_NSEC(tv.tv_usec);
#else
t->sec = time (STIO_NULL);
t->nsec = 0;
#endif
}
void stio_addtime (const stio_ntime_t* x, const stio_ntime_t* y, stio_ntime_t* z)
{
STIO_ASSERT (x->nsec >= 0 && x->nsec < STIO_NSECS_PER_SEC);
STIO_ASSERT (y->nsec >= 0 && y->nsec < STIO_NSECS_PER_SEC);
z->sec = x->sec + y->sec;
z->nsec = x->nsec + y->nsec;
if (z->nsec >= STIO_NSECS_PER_SEC)
{
z->sec = z->sec + 1;
z->nsec = z->nsec - STIO_NSECS_PER_SEC;
}
}
void stio_subtime (const stio_ntime_t* x, const stio_ntime_t* y, stio_ntime_t* z)
{
STIO_ASSERT (x->nsec >= 0 && x->nsec < STIO_NSECS_PER_SEC);
STIO_ASSERT (y->nsec >= 0 && y->nsec < STIO_NSECS_PER_SEC);
z->sec = x->sec - y->sec;
z->nsec = x->nsec - y->nsec;
if (z->nsec < 0)
{
z->sec = z->sec - 1;
z->nsec = z->nsec + STIO_NSECS_PER_SEC;
}
}

234
mio/lib/stio-tmr.c Normal file
View File

@ -0,0 +1,234 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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 "stio-prv.h"
#define HEAP_PARENT(x) (((x) - 1) / 2)
#define HEAP_LEFT(x) ((x) * 2 + 1)
#define HEAP_RIGHT(x) ((x) * 2 + 2)
#define YOUNGER_THAN(x,y) (stio_cmptime(&(x)->when, &(y)->when) < 0)
void stio_cleartmrjobs (stio_t* stio)
{
while (stio->tmr.size > 0) stio_deltmrjob (stio, 0);
}
static stio_tmridx_t sift_up (stio_t* stio, stio_tmridx_t index, int notify)
{
stio_tmridx_t parent;
parent = HEAP_PARENT(index);
if (index > 0 && YOUNGER_THAN(&stio->tmr.jobs[index], &stio->tmr.jobs[parent]))
{
stio_tmrjob_t item;
item = stio->tmr.jobs[index];
do
{
/* move down the parent to my current position */
stio->tmr.jobs[index] = stio->tmr.jobs[parent];
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
/* traverse up */
index = parent;
parent = HEAP_PARENT(parent);
}
while (index > 0 && YOUNGER_THAN(&item, &stio->tmr.jobs[parent]));
stio->tmr.jobs[index] = item;
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
}
return index;
}
static stio_tmridx_t sift_down (stio_t* stio, stio_tmridx_t index, int notify)
{
stio_size_t base = stio->tmr.size / 2;
if (index < base) /* at least 1 child is under the 'index' position */
{
stio_tmrjob_t item;
item = stio->tmr.jobs[index];
do
{
stio_tmridx_t left, right, younger;
left = HEAP_LEFT(index);
right = HEAP_RIGHT(index);
if (right < stio->tmr.size && YOUNGER_THAN(&stio->tmr.jobs[right], &stio->tmr.jobs[left]))
{
younger = right;
}
else
{
younger = left;
}
if (YOUNGER_THAN(&item, &stio->tmr.jobs[younger])) break;
stio->tmr.jobs[index] = stio->tmr.jobs[younger];
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
index = younger;
}
while (index < base);
stio->tmr.jobs[index] = item;
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
}
return index;
}
void stio_deltmrjob (stio_t* stio, stio_tmridx_t index)
{
stio_tmrjob_t item;
STIO_ASSERT (index < stio->tmr.size);
item = stio->tmr.jobs[index];
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = STIO_TMRIDX_INVALID;
stio->tmr.size = stio->tmr.size - 1;
if (stio->tmr.size > 0 && index != stio->tmr.size)
{
stio->tmr.jobs[index] = stio->tmr.jobs[stio->tmr.size];
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
YOUNGER_THAN(&stio->tmr.jobs[index], &item)? sift_up(stio, index, 1): sift_down(stio, index, 1);
}
}
stio_tmridx_t stio_instmrjob (stio_t* stio, const stio_tmrjob_t* job)
{
stio_tmridx_t index = stio->tmr.size;
if (index >= stio->tmr.capa)
{
stio_tmrjob_t* tmp;
stio_size_t new_capa;
STIO_ASSERT (stio->tmr.capa >= 1);
new_capa = stio->tmr.capa * 2;
tmp = (stio_tmrjob_t*)STIO_MMGR_REALLOC (stio->mmgr, stio->tmr.jobs, new_capa * STIO_SIZEOF(*tmp));
if (tmp == STIO_NULL)
{
stio->errnum = STIO_ENOMEM;
return STIO_TMRIDX_INVALID;
}
stio->tmr.jobs = tmp;
stio->tmr.capa = new_capa;
}
stio->tmr.size = stio->tmr.size + 1;
stio->tmr.jobs[index] = *job;
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
return sift_up (stio, index, 0);
}
stio_tmridx_t stio_updtmrjob (stio_t* stio, stio_tmridx_t index, const stio_tmrjob_t* job)
{
stio_tmrjob_t item;
item = stio->tmr.jobs[index];
stio->tmr.jobs[index] = *job;
if (stio->tmr.jobs[index].idxptr) *stio->tmr.jobs[index].idxptr = index;
return YOUNGER_THAN(job, &item)? sift_up (stio, index, 0): sift_down (stio, index, 0);
}
void stio_firetmrjobs (stio_t* stio, const stio_ntime_t* tm, stio_size_t* firecnt)
{
stio_ntime_t now;
stio_tmrjob_t tmrjob;
stio_size_t count = 0;
/* if the current time is not specified, get it from the system */
if (tm) now = *tm;
else stio_gettime (&now);
while (stio->tmr.size > 0)
{
if (stio_cmptime(&stio->tmr.jobs[0].when, &now) > 0) break;
tmrjob = stio->tmr.jobs[0]; /* copy the scheduled job */
stio_deltmrjob (stio, 0); /* deschedule the job */
count++;
tmrjob.handler (stio, &now, &tmrjob); /* then fire the job */
}
if (firecnt) *firecnt = count;
}
int stio_gettmrtmout (stio_t* stio, const stio_ntime_t* tm, stio_ntime_t* tmout)
{
stio_ntime_t now;
/* time-out can't be calculated when there's no job scheduled */
if (stio->tmr.size <= 0)
{
stio->errnum = STIO_ENOENT;
return -1;
}
/* if the current time is not specified, get it from the system */
if (tm) now = *tm;
else stio_gettime (&now);
stio_subtime (&stio->tmr.jobs[0].when, &now, tmout);
if (tmout->sec < 0) stio_cleartime (tmout);
return 0;
}
stio_tmrjob_t* stio_gettmrjob (stio_t* stio, stio_tmridx_t index)
{
if (index < 0 || index >= stio->tmr.size)
{
stio->errnum = STIO_ENOENT;
return STIO_NULL;
}
return &stio->tmr.jobs[index];
}
int stio_gettmrjobdeadline (stio_t* stio, stio_tmridx_t index, stio_ntime_t* deadline)
{
if (index < 0 || index >= stio->tmr.size)
{
stio->errnum = STIO_ENOENT;
return -1;
}
*deadline = stio->tmr.jobs[index].when;
return 0;
}

524
mio/lib/stio-utl.c Normal file
View File

@ -0,0 +1,524 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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 "stio-prv.h"
/* ========================================================================= */
#if defined(STIO_HAVE_UINT16_T)
stio_uint16_t stio_ntoh16 (stio_uint16_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint16_t)(
((stio_uint16_t)c[0] << 8) |
((stio_uint16_t)c[1] << 0));
#else
# error Unknown endian
#endif
}
stio_uint16_t stio_hton16 (stio_uint16_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint16_t)(
((stio_uint16_t)c[0] << 8) |
((stio_uint16_t)c[1] << 0));
#else
# error Unknown endian
#endif
}
#endif
/* ========================================================================= */
#if defined(STIO_HAVE_UINT32_T)
stio_uint32_t stio_ntoh32 (stio_uint32_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint32_t)(
((stio_uint32_t)c[0] << 24) |
((stio_uint32_t)c[1] << 16) |
((stio_uint32_t)c[2] << 8) |
((stio_uint32_t)c[3] << 0));
#else
# error Unknown endian
#endif
}
stio_uint32_t stio_hton32 (stio_uint32_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint32_t)(
((stio_uint32_t)c[0] << 24) |
((stio_uint32_t)c[1] << 16) |
((stio_uint32_t)c[2] << 8) |
((stio_uint32_t)c[3] << 0));
#else
# error Unknown endian
#endif
}
#endif
/* ========================================================================= */
#if defined(STIO_HAVE_UINT64_T)
stio_uint64_t stio_ntoh64 (stio_uint64_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint64_t)(
((stio_uint64_t)c[0] << 56) |
((stio_uint64_t)c[1] << 48) |
((stio_uint64_t)c[2] << 40) |
((stio_uint64_t)c[3] << 32) |
((stio_uint64_t)c[4] << 24) |
((stio_uint64_t)c[5] << 16) |
((stio_uint64_t)c[6] << 8) |
((stio_uint64_t)c[7] << 0));
#else
# error Unknown endian
#endif
}
stio_uint64_t stio_hton64 (stio_uint64_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint64_t)(
((stio_uint64_t)c[0] << 56) |
((stio_uint64_t)c[1] << 48) |
((stio_uint64_t)c[2] << 40) |
((stio_uint64_t)c[3] << 32) |
((stio_uint64_t)c[4] << 24) |
((stio_uint64_t)c[5] << 16) |
((stio_uint64_t)c[6] << 8) |
((stio_uint64_t)c[7] << 0));
#else
# error Unknown endian
#endif
}
#endif
/* ========================================================================= */
#if defined(STIO_HAVE_UINT128_T)
stio_uint128_t stio_ntoh128 (stio_uint128_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint128_t)(
((stio_uint128_t)c[0] << 120) |
((stio_uint128_t)c[1] << 112) |
((stio_uint128_t)c[2] << 104) |
((stio_uint128_t)c[3] << 96) |
((stio_uint128_t)c[4] << 88) |
((stio_uint128_t)c[5] << 80) |
((stio_uint128_t)c[6] << 72) |
((stio_uint128_t)c[7] << 64) |
((stio_uint128_t)c[8] << 56) |
((stio_uint128_t)c[9] << 48) |
((stio_uint128_t)c[10] << 40) |
((stio_uint128_t)c[11] << 32) |
((stio_uint128_t)c[12] << 24) |
((stio_uint128_t)c[13] << 16) |
((stio_uint128_t)c[14] << 8) |
((stio_uint128_t)c[15] << 0));
#else
# error Unknown endian
#endif
}
stio_uint128_t stio_hton128 (stio_uint128_t x)
{
#if defined(STIO_ENDIAN_BIG)
return x;
#elif defined(STIO_ENDIAN_LITTLE)
stio_uint8_t* c = (stio_uint8_t*)&x;
return (stio_uint128_t)(
((stio_uint128_t)c[0] << 120) |
((stio_uint128_t)c[1] << 112) |
((stio_uint128_t)c[2] << 104) |
((stio_uint128_t)c[3] << 96) |
((stio_uint128_t)c[4] << 88) |
((stio_uint128_t)c[5] << 80) |
((stio_uint128_t)c[6] << 72) |
((stio_uint128_t)c[7] << 64) |
((stio_uint128_t)c[8] << 56) |
((stio_uint128_t)c[9] << 48) |
((stio_uint128_t)c[10] << 40) |
((stio_uint128_t)c[11] << 32) |
((stio_uint128_t)c[12] << 24) |
((stio_uint128_t)c[13] << 16) |
((stio_uint128_t)c[14] << 8) |
((stio_uint128_t)c[15] << 0));
#else
# error Unknown endian
#endif
}
#endif
/* ========================================================================= */
#define IS_MSPACE(x) ((x) == STIO_MT(' ') || (x) == STIO_MT('\t') || (x) == STIO_MT('\n') || (x) == STIO_MT('\r'))
stio_mchar_t* stio_mbsdup (stio_t* stio, const stio_mchar_t* src)
{
stio_mchar_t* dst;
stio_size_t len;
dst = (stio_mchar_t*)src;
while (*dst != STIO_MT('\0')) dst++;
len = dst - src;
dst = STIO_MMGR_ALLOC (stio->mmgr, (len + 1) * STIO_SIZEOF(*src));
if (!dst)
{
stio->errnum = STIO_ENOMEM;
return STIO_NULL;
}
STIO_MEMCPY (dst, src, (len + 1) * STIO_SIZEOF(*src));
return dst;
}
stio_size_t stio_mbscpy (stio_mchar_t* buf, const stio_mchar_t* str)
{
stio_mchar_t* org = buf;
while ((*buf++ = *str++) != STIO_MT('\0'));
return buf - org - 1;
}
int stio_mbsspltrn (
stio_mchar_t* s, const stio_mchar_t* delim,
stio_mchar_t lquote, stio_mchar_t rquote,
stio_mchar_t escape, const stio_mchar_t* trset)
{
stio_mchar_t* p = s, *d;
stio_mchar_t* sp = STIO_NULL, * ep = STIO_NULL;
int delim_mode;
int cnt = 0;
if (delim == STIO_NULL) delim_mode = 0;
else
{
delim_mode = 1;
for (d = (stio_mchar_t*)delim; *d != STIO_MT('\0'); d++)
if (!IS_MSPACE(*d)) delim_mode = 2;
}
if (delim_mode == 0)
{
/* skip preceding space characters */
while (IS_MSPACE(*p)) p++;
/* when 0 is given as "delim", it has an effect of cutting
preceding and trailing space characters off "s". */
if (lquote != STIO_MT('\0') && *p == lquote)
{
stio_mbscpy (p, p + 1);
for (;;)
{
if (*p == STIO_MT('\0')) return -1;
if (escape != STIO_MT('\0') && *p == escape)
{
if (trset != STIO_NULL && p[1] != STIO_MT('\0'))
{
const stio_mchar_t* ep = trset;
while (*ep != STIO_MT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
stio_mbscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
p++;
break;
}
}
if (sp == 0) sp = p;
ep = p;
p++;
}
while (IS_MSPACE(*p)) p++;
if (*p != STIO_MT('\0')) return -1;
if (sp == 0 && ep == 0) s[0] = STIO_MT('\0');
else
{
ep[1] = STIO_MT('\0');
if (s != (stio_mchar_t*)sp) stio_mbscpy (s, sp);
cnt++;
}
}
else
{
while (*p)
{
if (!IS_MSPACE(*p))
{
if (sp == 0) sp = p;
ep = p;
}
p++;
}
if (sp == 0 && ep == 0) s[0] = STIO_MT('\0');
else
{
ep[1] = STIO_MT('\0');
if (s != (stio_mchar_t*)sp) stio_mbscpy (s, sp);
cnt++;
}
}
}
else if (delim_mode == 1)
{
stio_mchar_t* o;
while (*p)
{
o = p;
while (IS_MSPACE(*p)) p++;
if (o != p) { stio_mbscpy (o, p); p = o; }
if (lquote != STIO_MT('\0') && *p == lquote)
{
stio_mbscpy (p, p + 1);
for (;;)
{
if (*p == STIO_MT('\0')) return -1;
if (escape != STIO_MT('\0') && *p == escape)
{
if (trset != STIO_NULL && p[1] != STIO_MT('\0'))
{
const stio_mchar_t* ep = trset;
while (*ep != STIO_MT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
stio_mbscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = STIO_MT('\0');
cnt++;
break;
}
}
p++;
}
}
else
{
o = p;
for (;;)
{
if (*p == STIO_MT('\0'))
{
if (o != p) cnt++;
break;
}
if (IS_MSPACE (*p))
{
*p++ = STIO_MT('\0');
cnt++;
break;
}
p++;
}
}
}
}
else /* if (delim_mode == 2) */
{
stio_mchar_t* o;
int ok;
while (*p != STIO_MT('\0'))
{
o = p;
while (IS_MSPACE(*p)) p++;
if (o != p) { stio_mbscpy (o, p); p = o; }
if (lquote != STIO_MT('\0') && *p == lquote)
{
stio_mbscpy (p, p + 1);
for (;;)
{
if (*p == STIO_MT('\0')) return -1;
if (escape != STIO_MT('\0') && *p == escape)
{
if (trset != STIO_NULL && p[1] != STIO_MT('\0'))
{
const stio_mchar_t* ep = trset;
while (*ep != STIO_MT('\0'))
{
if (p[1] == *ep++)
{
p[1] = *ep;
break;
}
}
}
stio_mbscpy (p, p + 1);
}
else
{
if (*p == rquote)
{
*p++ = STIO_MT('\0');
cnt++;
break;
}
}
p++;
}
ok = 0;
while (IS_MSPACE(*p)) p++;
if (*p == STIO_MT('\0')) ok = 1;
for (d = (stio_mchar_t*)delim; *d != STIO_MT('\0'); d++)
{
if (*p == *d)
{
ok = 1;
stio_mbscpy (p, p + 1);
break;
}
}
if (ok == 0) return -1;
}
else
{
o = p; sp = ep = 0;
for (;;)
{
if (*p == STIO_MT('\0'))
{
if (ep)
{
ep[1] = STIO_MT('\0');
p = &ep[1];
}
cnt++;
break;
}
for (d = (stio_mchar_t*)delim; *d != STIO_MT('\0'); d++)
{
if (*p == *d)
{
if (sp == STIO_NULL)
{
stio_mbscpy (o, p); p = o;
*p++ = STIO_MT('\0');
}
else
{
stio_mbscpy (&ep[1], p);
stio_mbscpy (o, sp);
o[ep - sp + 1] = STIO_MT('\0');
p = &o[ep - sp + 2];
}
cnt++;
/* last empty field after delim */
if (*p == STIO_MT('\0')) cnt++;
goto exit_point;
}
}
if (!IS_MSPACE (*p))
{
if (sp == STIO_NULL) sp = p;
ep = p;
}
p++;
}
exit_point:
;
}
}
}
return cnt;
}
int stio_mbsspl (
stio_mchar_t* s, const stio_mchar_t* delim,
stio_mchar_t lquote, stio_mchar_t rquote, stio_mchar_t escape)
{
return stio_mbsspltrn (s, delim, lquote, rquote, escape, STIO_NULL);
}

1468
mio/lib/stio.c Normal file

File diff suppressed because it is too large Load Diff

554
mio/lib/stio.h Normal file
View File

@ -0,0 +1,554 @@
/*
* $Id$
*
Copyright (c) 2015-2016 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.
*/
#ifndef _STIO_H_
#define _STIO_H_
#include <stio-cmn.h>
/**
* The stio_ntime_t type defines a numeric time type expressed in the
* number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970).
*/
typedef struct stio_ntime_t stio_ntime_t;
struct stio_ntime_t
{
stio_intptr_t sec;
stio_int32_t nsec; /* nanoseconds */
};
#if defined(_WIN32)
typedef stio_uintptr_t qse_syshnd_t;
#define STIO_SYSHND_INVALID (~(stio_uintptr_t)0)
#else
typedef int stio_syshnd_t;
#define STIO_SYSHND_INVALID (-1)
#endif
typedef struct stio_devaddr_t stio_devaddr_t;
struct stio_devaddr_t
{
int len;
void* ptr;
};
#define STIO_CONST_SWAP16(x) \
((stio_uint16_t)((((stio_uint16_t)(x) & (stio_uint16_t)0x00ffU) << 8) | \
(((stio_uint16_t)(x) & (stio_uint16_t)0xff00U) >> 8) ))
#define STIO_CONST_SWAP32(x) \
((stio_uint32_t)((((stio_uint32_t)(x) & (stio_uint32_t)0x000000ffUL) << 24) | \
(((stio_uint32_t)(x) & (stio_uint32_t)0x0000ff00UL) << 8) | \
(((stio_uint32_t)(x) & (stio_uint32_t)0x00ff0000UL) >> 8) | \
(((stio_uint32_t)(x) & (stio_uint32_t)0xff000000UL) >> 24) ))
#if defined(STIO_ENDIAN_LITTLE)
# define STIO_CONST_NTOH16(x) STIO_CONST_SWAP16(x)
# define STIO_CONST_HTON16(x) STIO_CONST_SWAP16(x)
# define STIO_CONST_NTOH32(x) STIO_CONST_SWAP32(x)
# define STIO_CONST_HTON32(x) STIO_CONST_SWAP32(x)
#elif defined(STIO_ENDIAN_BIG)
# define STIO_CONST_NTOH16(x) (x)
# define STIO_CONST_HTON16(x) (x)
# define STIO_CONST_NTOH32(x) (x)
# define STIO_CONST_HTON32(x) (x)
#else
# error UNKNOWN ENDIAN
#endif
/* ========================================================================= */
typedef struct stio_t stio_t;
typedef struct stio_dev_t stio_dev_t;
typedef struct stio_dev_mth_t stio_dev_mth_t;
typedef struct stio_dev_evcb_t stio_dev_evcb_t;
typedef struct stio_wq_t stio_wq_t;
typedef stio_intptr_t stio_iolen_t; /* NOTE: this is a signed type */
enum stio_errnum_t
{
STIO_ENOERR,
STIO_ENOIMPL,
STIO_ESYSERR,
STIO_EINTERN,
STIO_ENOMEM,
STIO_EINVAL,
STIO_EEXIST,
STIO_ENOENT,
STIO_ENOSUP, /* not supported */
STIO_EMFILE, /* too many open files */
STIO_ENFILE,
STIO_EAGAIN,
STIO_ECONRF, /* connection refused */
STIO_ECONRS, /* connection reset */
STIO_ENOCAPA, /* no capability */
STIO_ETMOUT, /* timed out */
STIO_EPERM, /* operation not permitted */
STIO_EDEVMAKE,
STIO_EDEVERR,
STIO_EDEVHUP
};
typedef enum stio_errnum_t stio_errnum_t;
enum stio_stopreq_t
{
STIO_STOPREQ_NONE = 0,
STIO_STOPREQ_TERMINATION,
STIO_STOPREQ_WATCHER_ERROR
};
typedef enum stio_stopreq_t stio_stopreq_t;
/* ========================================================================= */
#define STIO_TMRIDX_INVALID ((stio_tmridx_t)-1)
typedef stio_size_t stio_tmridx_t;
typedef struct stio_tmrjob_t stio_tmrjob_t;
typedef void (*stio_tmrjob_handler_t) (
stio_t* stio,
const stio_ntime_t* now,
stio_tmrjob_t* tmrjob
);
struct stio_tmrjob_t
{
void* ctx;
stio_ntime_t when;
stio_tmrjob_handler_t handler;
stio_tmridx_t* idxptr; /* pointer to the index holder */
};
/* ========================================================================= */
struct stio_dev_mth_t
{
/* ------------------------------------------------------------------ */
/* mandatory. called in stio_makedev() */
int (*make) (stio_dev_t* dev, void* ctx);
/* ------------------------------------------------------------------ */
/* mandatory. called in stio_killdev(). also called in stio_makedev() upon
* failure after make() success.
*
* when 'force' is 0, the return value of -1 causes the device to be a
* zombie. the kill method is called periodically on a zombie device
* until the method returns 0.
*
* when 'force' is 1, the called should not return -1. If it does, the
* method is called once more only with the 'force' value of 2.
*
* when 'force' is 2, the device is destroyed regardless of the return value.
*/
int (*kill) (stio_dev_t* dev, int force);
/* ------------------------------------------------------------------ */
stio_syshnd_t (*getsyshnd) (stio_dev_t* dev); /* mandatory. called in stio_makedev() after successful make() */
/* ------------------------------------------------------------------ */
/* return -1 on failure, 0 if no data is availble, 1 otherwise.
* when returning 1, *len must be sent to the length of data read.
* if *len is set to 0, it's treated as EOF. */
int (*read) (stio_dev_t* dev, void* data, stio_iolen_t* len, stio_devaddr_t* srcaddr);
/* ------------------------------------------------------------------ */
int (*write) (stio_dev_t* dev, const void* data, stio_iolen_t* len, const stio_devaddr_t* dstaddr);
/* ------------------------------------------------------------------ */
int (*ioctl) (stio_dev_t* dev, int cmd, void* arg);
};
struct stio_dev_evcb_t
{
/* return -1 on failure. 0 or 1 on success.
* when 0 is returned, it doesn't attempt to perform actual I/O.
* when 1 is returned, it attempts to perform actual I/O. */
int (*ready) (stio_dev_t* dev, int events);
/* return -1 on failure, 0 or 1 on success.
* when 0 is returned, the main loop stops the attempt to read more data.
* when 1 is returned, the main loop attempts to read more data without*/
int (*on_read) (stio_dev_t* dev, const void* data, stio_iolen_t len, const stio_devaddr_t* srcaddr);
/* return -1 on failure, 0 on success.
* wrlen is the length of data written. it is the length of the originally
* posted writing request for a stream device. For a non stream device, it
* may be shorter than the originally posted length. */
int (*on_write) (stio_dev_t* dev, stio_iolen_t wrlen, void* wrctx, const stio_devaddr_t* dstaddr);
};
struct stio_wq_t
{
stio_wq_t* next;
stio_wq_t* prev;
stio_iolen_t olen; /* original data length */
stio_uint8_t* ptr; /* pointer to data */
stio_iolen_t len; /* remaining data length */
void* ctx;
stio_dev_t* dev; /* back-pointer to the device */
stio_tmridx_t tmridx;
stio_devaddr_t dstaddr;
};
#define STIO_WQ_INIT(wq) ((wq)->next = (wq)->prev = (wq))
#define STIO_WQ_TAIL(wq) ((wq)->prev)
#define STIO_WQ_HEAD(wq) ((wq)->next)
#define STIO_WQ_ISEMPTY(wq) (STIO_WQ_HEAD(wq) == (wq))
#define STIO_WQ_ISNODE(wq,x) ((wq) != (x))
#define STIO_WQ_ISHEAD(wq,x) (STIO_WQ_HEAD(wq) == (x))
#define STIO_WQ_ISTAIL(wq,x) (STIO_WQ_TAIL(wq) == (x))
#define STIO_WQ_NEXT(x) ((x)->next)
#define STIO_WQ_PREV(x) ((x)->prev)
#define STIO_WQ_LINK(p,x,n) do { \
stio_wq_t* pp = (p), * nn = (n); \
(x)->prev = (p); \
(x)->next = (n); \
nn->prev = (x); \
pp->next = (x); \
} while (0)
#define STIO_WQ_UNLINK(x) do { \
stio_wq_t* pp = (x)->prev, * nn = (x)->next; \
nn->prev = pp; pp->next = nn; \
} while (0)
#define STIO_WQ_REPL(o,n) do { \
stio_wq_t* oo = (o), * nn = (n); \
nn->next = oo->next; \
nn->next->prev = nn; \
nn->prev = oo->prev; \
nn->prev->next = nn; \
} while (0)
/* insert an item at the back of the queue */
/*#define STIO_WQ_ENQ(wq,x) STIO_WQ_LINK(STIO_WQ_TAIL(wq), x, STIO_WQ_TAIL(wq)->next)*/
#define STIO_WQ_ENQ(wq,x) STIO_WQ_LINK(STIO_WQ_TAIL(wq), x, wq)
/* remove an item in the front from the queue */
#define STIO_WQ_DEQ(wq) STIO_WQ_UNLINK(STIO_WQ_HEAD(wq))
#define STIO_DEV_HEADERS \
stio_t* stio; \
stio_size_t dev_size; \
int dev_capa; \
stio_dev_mth_t* dev_mth; \
stio_dev_evcb_t* dev_evcb; \
stio_wq_t wq; \
stio_dev_t* dev_prev; \
stio_dev_t* dev_next
struct stio_dev_t
{
STIO_DEV_HEADERS;
};
enum stio_dev_capa_t
{
STIO_DEV_CAPA_VIRTUAL = (1 << 0),
STIO_DEV_CAPA_IN = (1 << 1),
STIO_DEV_CAPA_OUT = (1 << 2),
/* #STIO_DEV_CAPA_PRI is meaningful only if #STIO_DEV_CAPA_IN is set */
STIO_DEV_CAPA_PRI = (1 << 3),
STIO_DEV_CAPA_STREAM = (1 << 4),
STIO_DEV_CAPA_OUT_QUEUED = (1 << 5),
/* internal use only. never set this bit to the dev_capa field */
STIO_DEV_CAPA_IN_DISABLED = (1 << 9),
STIO_DEV_CAPA_IN_CLOSED = (1 << 10),
STIO_DEV_CAPA_OUT_CLOSED = (1 << 11),
STIO_DEV_CAPA_IN_WATCHED = (1 << 12),
STIO_DEV_CAPA_OUT_WATCHED = (1 << 13),
STIO_DEV_CAPA_PRI_WATCHED = (1 << 14), /**< can be set only if STIO_DEV_CAPA_IN_WATCHED is set */
STIO_DEV_CAPA_ACTIVE = (1 << 15),
STIO_DEV_CAPA_HALTED = (1 << 16),
STIO_DEV_CAPA_ZOMBIE = (1 << 17)
};
typedef enum stio_dev_capa_t stio_dev_capa_t;
enum stio_dev_watch_cmd_t
{
STIO_DEV_WATCH_START,
STIO_DEV_WATCH_UPDATE,
STIO_DEV_WATCH_RENEW, /* automatic update */
STIO_DEV_WATCH_STOP
};
typedef enum stio_dev_watch_cmd_t stio_dev_watch_cmd_t;
enum stio_dev_event_t
{
STIO_DEV_EVENT_IN = (1 << 0),
STIO_DEV_EVENT_OUT = (1 << 1),
STIO_DEV_EVENT_PRI = (1 << 2),
STIO_DEV_EVENT_HUP = (1 << 3),
STIO_DEV_EVENT_ERR = (1 << 4)
};
typedef enum stio_dev_event_t stio_dev_event_t;
/* ========================================================================= */
#ifdef __cplusplus
extern "C" {
#endif
STIO_EXPORT stio_t* stio_open (
stio_mmgr_t* mmgr,
stio_size_t xtnsize,
stio_size_t tmrcapa, /**< initial timer capacity */
stio_errnum_t* errnum
);
STIO_EXPORT void stio_close (
stio_t* stio
);
STIO_EXPORT int stio_init (
stio_t* stio,
stio_mmgr_t* mmgr,
stio_size_t tmrcapa
);
STIO_EXPORT void stio_fini (
stio_t* stio
);
STIO_EXPORT int stio_exec (
stio_t* stio
);
STIO_EXPORT int stio_loop (
stio_t* stio
);
STIO_EXPORT void stio_stop (
stio_t* stio,
stio_stopreq_t stopreq
);
STIO_EXPORT stio_dev_t* stio_makedev (
stio_t* stio,
stio_size_t dev_size,
stio_dev_mth_t* dev_mth,
stio_dev_evcb_t* dev_evcb,
void* make_ctx
);
STIO_EXPORT void stio_killdev (
stio_t* stio,
stio_dev_t* dev
);
STIO_EXPORT int stio_dev_ioctl (
stio_dev_t* dev,
int cmd,
void* arg
);
STIO_EXPORT int stio_dev_watch (
stio_dev_t* dev,
stio_dev_watch_cmd_t cmd,
/** 0 or bitwise-ORed of #STIO_DEV_EVENT_IN and #STIO_DEV_EVENT_OUT */
int events
);
STIO_EXPORT int stio_dev_read (
stio_dev_t* dev,
int enabled
);
/**
* The stio_dev_write() function posts a writing request.
* It attempts to write data immediately if there is no pending requests.
* If writing fails, it returns -1. If writing succeeds, it calls the
* on_write callback. If the callback fails, it returns -1. If the callback
* succeeds, it returns 1. If no immediate writing is possible, the request
* is enqueued to a pending request list. If enqueing gets successful,
* it returns 0. otherwise it returns -1.
*/
STIO_EXPORT int stio_dev_write (
stio_dev_t* dev,
const void* data,
stio_iolen_t len,
void* wrctx,
const stio_devaddr_t* dstaddr
);
STIO_EXPORT int stio_dev_timedwrite (
stio_dev_t* dev,
const void* data,
stio_iolen_t len,
const stio_ntime_t* tmout,
void* wrctx,
const stio_devaddr_t* dstaddr
);
STIO_EXPORT void stio_dev_halt (
stio_dev_t* dev
);
/* ========================================================================= */
#define stio_inittime(x,s,ns) (((x)->sec = (s)), ((x)->nsec = (ns)))
#define stio_cleartime(x) stio_inittime(x,0,0)
#define stio_cmptime(x,y) \
(((x)->sec == (y)->sec)? ((x)->nsec - (y)->nsec): \
((x)->sec - (y)->sec))
/* if time has been normalized properly, nsec must be equal to or
* greater than 0. */
#define stio_isnegtime(x) ((x)->sec < 0)
#define stio_ispostime(x) ((x)->sec > 0 || ((x)->sec == 0 && (x)->nsec > 0))
#define stio_iszerotime(x) ((x)->sec == 0 && (x)->nsec == 0)
/**
* The stio_gettime() function gets the current time.
*/
STIO_EXPORT void stio_gettime (
stio_ntime_t* nt
);
/**
* The stio_addtime() function adds x and y and stores the result in z
*/
STIO_EXPORT void stio_addtime (
const stio_ntime_t* x,
const stio_ntime_t* y,
stio_ntime_t* z
);
/**
* The stio_subtime() function subtract y from x and stores the result in z.
*/
STIO_EXPORT void stio_subtime (
const stio_ntime_t* x,
const stio_ntime_t* y,
stio_ntime_t* z
);
/**
* The stio_instmrjob() function schedules a new event.
*
* \return #STIO_TMRIDX_INVALID on failure, valid index on success.
*/
STIO_EXPORT stio_tmridx_t stio_instmrjob (
stio_t* stio,
const stio_tmrjob_t* job
);
STIO_EXPORT stio_tmridx_t stio_updtmrjob (
stio_t* stio,
stio_tmridx_t index,
const stio_tmrjob_t* job
);
STIO_EXPORT void stio_deltmrjob (
stio_t* stio,
stio_tmridx_t index
);
/**
* The stio_gettmrjob() function returns the
* pointer to the registered event at the given index.
*/
STIO_EXPORT stio_tmrjob_t* stio_gettmrjob (
stio_t* stio,
stio_tmridx_t index
);
STIO_EXPORT int stio_gettmrjobdeadline (
stio_t* stio,
stio_tmridx_t index,
stio_ntime_t* deadline
);
/* ========================================================================= */
#if defined(STIO_HAVE_UINT16_T)
STIO_EXPORT stio_uint16_t stio_ntoh16 (
stio_uint16_t x
);
STIO_EXPORT stio_uint16_t stio_hton16 (
stio_uint16_t x
);
#endif
#if defined(STIO_HAVE_UINT32_T)
STIO_EXPORT stio_uint32_t stio_ntoh32 (
stio_uint32_t x
);
STIO_EXPORT stio_uint32_t stio_hton32 (
stio_uint32_t x
);
#endif
#if defined(STIO_HAVE_UINT64_T)
STIO_EXPORT stio_uint64_t stio_ntoh64 (
stio_uint64_t x
);
STIO_EXPORT stio_uint64_t stio_hton64 (
stio_uint64_t x
);
#endif
#if defined(STIO_HAVE_UINT128_T)
STIO_EXPORT stio_uint128_t stio_ntoh128 (
stio_uint128_t x
);
STIO_EXPORT stio_uint128_t stio_hton128 (
stio_uint128_t x
);
#endif
/* ========================================================================= */
#ifdef __cplusplus
}
#endif
#endif