diff options
Diffstat (limited to 'lib/fdbuf')
-rw-r--r-- | lib/fdbuf/ChangeLog | 161 | ||||
-rw-r--r-- | lib/fdbuf/Makefile.am | 29 | ||||
-rw-r--r-- | lib/fdbuf/Makefile.in | 587 | ||||
-rw-r--r-- | lib/fdbuf/fdbuf.cc | 107 | ||||
-rw-r--r-- | lib/fdbuf/fdbuf.h | 83 | ||||
-rw-r--r-- | lib/fdbuf/fdbuf_copy.cc | 38 | ||||
-rw-r--r-- | lib/fdbuf/fdibuf.cc | 197 | ||||
-rw-r--r-- | lib/fdbuf/fdibuf.h | 53 | ||||
-rw-r--r-- | lib/fdbuf/fdibuf_mystring.cc | 52 | ||||
-rw-r--r-- | lib/fdbuf/fdibuf_netstring.cc | 41 | ||||
-rw-r--r-- | lib/fdbuf/fdobuf.cc | 214 | ||||
-rw-r--r-- | lib/fdbuf/fdobuf.h | 92 | ||||
-rw-r--r-- | lib/fdbuf/fdobuf_chownmod.cc | 34 | ||||
-rw-r--r-- | lib/fdbuf/fdobuf_seek.cc | 48 | ||||
-rw-r--r-- | lib/fdbuf/fdobuf_signed.cc | 38 | ||||
-rw-r--r-- | lib/fdbuf/fdobuf_unsigned.cc | 34 | ||||
-rw-r--r-- | lib/fdbuf/tlsibuf.cc | 31 | ||||
-rw-r--r-- | lib/fdbuf/tlsibuf.h | 32 | ||||
-rw-r--r-- | lib/fdbuf/tlsobuf.cc | 31 | ||||
-rw-r--r-- | lib/fdbuf/tlsobuf.h | 32 |
20 files changed, 1934 insertions, 0 deletions
diff --git a/lib/fdbuf/ChangeLog b/lib/fdbuf/ChangeLog new file mode 100644 index 0000000..ba96ad5 --- /dev/null +++ b/lib/fdbuf/ChangeLog @@ -0,0 +1,161 @@ +2000-08-22 Bruce Guenter <bruce@bruce-guenter.dyndns.org> + + * Added the missing accessor for the internal "errnum" data member + to the fdibuf and fdobuf classes. + +2000-08-10 Bruce Guenter <bruce@bruce-guenter.dyndns.org> + + * fdibuf.cc (read_large): Fixed a bug in the increment of data. + + * fdibuf_mystring.cc (getline): Reduced some of the expressions + into variables. + +2000-04-08 Bruce Guenter <bguenter@bguenter.pointsnorth.com> + + * fdibuf.cc (read_large): Fixed bug: count needed to be + incremented after reading data in. + +2000-04-07 Bruce Guenter <bguenter@bguenter.pointsnorth.com> + + * fdobuf_signed.cc (operator<<): Immediately output a '-' for + negative numbers rather than storing a negative flag for later. + + * fdobuf_unsigned.cc (operator<<): Moved the integer versions of + this operator into their own modules. + + * fdobuf_seek.cc (seek): Moved this routine out of fdobuf.cc + + * fdibuf.cc (read_large): Added this routine to read in a chunk of + data larger than the size of the buffer. + +2000-04-06 Bruce Guenter <bguenter@bguenter.pointsnorth.com> + + * fdibuf_netstring.cc (getnetstring): Moved this routine into its + own source file. + + * fdobuf.cc (write_large): Added this routine to write out a chunk + of data larger than the size of the buffer, to avoid doing extra + copies. + (write): Removed an extraneous code segment. + + * fdobuf.h: Moved the fdobuf declarations here. + + * fdibuf.h: Moved the fdibuf declarations here. + + * fdbuf.h: Removed extraneous fdobuf declaration. + +1999-07-08 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf.cc (write): Optimized this routine better for the case + where the amount of data to be written will fit inside the buffer. + +1999-07-05 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdbuf.h (fdobuf,fdibuf): Made some of the routines here virtual + in order to extend it properly. + Added "tell()" operations to both fdibuf and fdobuf to indicate + the current logical read/write point. + +1999-07-04 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf_chownmod.cc: Added two new routines chown and chmod, + which operate directly on the open fd. + +1999-06-30 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdibuf_mystring.cc (getline): Make this routine return the + number of bytes actually read, including the delimiter, even + though the delimiter is not added to the returned string. + +1999-06-29 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdibuf.cc (fdibuf): Added a 'seekfwd' function to seek forwards + "o" bytes. + + * fdibuf_mystring.cc (getline): Added locking and set the count + properly. + +1999-06-28 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdibuf.cc (get): Make sure count is set for get. + +1999-06-06 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdbuf.cc (fdbuf): Fixed long-standing bug -- I forgot to delete + the buffer in the destructor. + (close): Modified the code to ensure that the fd is not closed + twice (as would happen when destructing the fdbuf). + +1999-05-31 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf.cc: Redefined flush as nflush; added sync code to nflush; + made flush and sync call nflush; added mutex lock calls to all + public methods. + + * fdibuf.cc: Added mutex lock calls to all public methods. + + * fdbuf.cc: Added debugging implementations of lock() and unlock() + mutex operators (to be removed before real use). + +1999-05-28 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf.cc (fdobuf): Fixed missing initialization of bufpos in + one of the two constructors. + +1999-05-01 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf.cc (fdobuf): Added an optional "mode" parameter which + defaults to 0666, which is the permissions for the new file. + (sync): Wrote this function to fsync the file descriptor. + +1999-04-27 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdbuf.h (fdobuf): Removed definition for sync and nonblock mode, + as they won't be handled correctly in the writing code. + +1999-04-03 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf.cc (operator<<): Wrote an operator for signed and + unsigned longs, with overloaded functions for ints and shorts that + promote the parameters to longs. + (write): Wrote a write routine specifically for a single + character. + +1999-04-01 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf.cc: Fixed handling of seek by adding a "bufpos" indicator + that points to the current position in the buffer at which writes + should go. buflength is effectively the maximum value of bufpos + between flushes. + + * fdibuf.cc (get): Renamed getchar to get (to be potentially + overloaded with other types). + + * fdbuf.h (fdbuf): Removed a bunch of write methods and replaced + them with "operator<<", with similar capability to iostreams + methods of the same names. + + * fdobuf.cc (endl): Wrote this manipulator to write an end-of-line + and flush the buffer. + +1999-03-31 Bruce Guenter <bguenter@mikhail.qcc.sk.ca> + + * fdobuf_mystring.cc: Moved all the mystring-specific code from + fdobuf.cc into this module to lessen link problems. + + * fdibuf_mystring.cc: Moved all the mystring-specific code from + fdibuf.cc into this module to lessen link problems. + + * fdobuf.cc (seek): Wrote this seek routine to allow movement in + an output file buffer. + + * fdibuf.cc (seek): Generalized the rewind routine to allow + arbitrary seeks. It also checks to see if the seek point is + within the current buffer and if so just repositions its + pointers. + + * fdbuf.h: If BUFSIZE is not defined, set it here to 4096. + (class fdbuf ): Rename length, start, and size to buflength, + bufstart, and bufsize. Add a new field "offset" to indicate the + current file seek offset. + diff --git a/lib/fdbuf/Makefile.am b/lib/fdbuf/Makefile.am new file mode 100644 index 0000000..152d634 --- /dev/null +++ b/lib/fdbuf/Makefile.am @@ -0,0 +1,29 @@ +noinst_LIBRARIES = libfdbuf.a +AM_CPPFLAGS = -I$(top_srcdir)/lib + +if FDBUF_NO_MYSTRING +mystring_sources = +else +mystring_sources = fdibuf_mystring.cc fdibuf_netstring.cc +endif + +if TLS +tls_sources = tlsibuf.h tlsibuf.cc tlsobuf.h tlsobuf.cc +else +tls_sources = +endif + +libfdbuf_a_SOURCES = \ + fdbuf.h \ + fdbuf.cc \ + fdbuf_copy.cc \ + fdibuf.h \ + fdibuf.cc \ + fdobuf.h \ + fdobuf.cc \ + fdobuf_chownmod.cc \ + fdobuf_seek.cc \ + fdobuf_signed.cc \ + fdobuf_unsigned.cc \ + $(tls_sources) \ + $(mystring_sources) diff --git a/lib/fdbuf/Makefile.in b/lib/fdbuf/Makefile.in new file mode 100644 index 0000000..8c84ce0 --- /dev/null +++ b/lib/fdbuf/Makefile.in @@ -0,0 +1,587 @@ +# Makefile.in generated by automake 1.15 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2014 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__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +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 = : +subdir = lib/fdbuf +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +AR = ar +ARFLAGS = cru +AM_V_AR = $(am__v_AR_@AM_V@) +am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libfdbuf_a_AR = $(AR) $(ARFLAGS) +libfdbuf_a_LIBADD = +am__libfdbuf_a_SOURCES_DIST = fdbuf.h fdbuf.cc fdbuf_copy.cc fdibuf.h \ + fdibuf.cc fdobuf.h fdobuf.cc fdobuf_chownmod.cc fdobuf_seek.cc \ + fdobuf_signed.cc fdobuf_unsigned.cc tlsibuf.h tlsibuf.cc \ + tlsobuf.h tlsobuf.cc fdibuf_mystring.cc fdibuf_netstring.cc +@TLS_TRUE@am__objects_1 = tlsibuf.$(OBJEXT) tlsobuf.$(OBJEXT) +@FDBUF_NO_MYSTRING_FALSE@am__objects_2 = fdibuf_mystring.$(OBJEXT) \ +@FDBUF_NO_MYSTRING_FALSE@ fdibuf_netstring.$(OBJEXT) +am_libfdbuf_a_OBJECTS = fdbuf.$(OBJEXT) fdbuf_copy.$(OBJEXT) \ + fdibuf.$(OBJEXT) fdobuf.$(OBJEXT) fdobuf_chownmod.$(OBJEXT) \ + fdobuf_seek.$(OBJEXT) fdobuf_signed.$(OBJEXT) \ + fdobuf_unsigned.$(OBJEXT) $(am__objects_1) $(am__objects_2) +libfdbuf_a_OBJECTS = $(am_libfdbuf_a_OBJECTS) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +am__mv = mv -f +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_@AM_V@) +am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@) +am__v_CXX_0 = @echo " CXX " $@; +am__v_CXX_1 = +CXXLD = $(CXX) +CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ + -o $@ +AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) +am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) +am__v_CXXLD_0 = @echo " CXXLD " $@; +am__v_CXXLD_1 = +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_CC_1 = +CCLD = $(CC) +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_CCLD_1 = +SOURCES = $(libfdbuf_a_SOURCES) +DIST_SOURCES = $(am__libfdbuf_a_SOURCES_DIST) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ + ChangeLog +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +GREP = @GREP@ +HAVE_GETADDRINFO = @HAVE_GETADDRINFO@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LDFLAGS = @LDFLAGS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR = @MKDIR@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +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@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +RANLIB = @RANLIB@ +RM = @RM@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +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_alias = @build_alias@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host_alias = @host_alias@ +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@ +noinst_LIBRARIES = libfdbuf.a +AM_CPPFLAGS = -I$(top_srcdir)/lib +@FDBUF_NO_MYSTRING_FALSE@mystring_sources = fdibuf_mystring.cc fdibuf_netstring.cc +@FDBUF_NO_MYSTRING_TRUE@mystring_sources = +@TLS_FALSE@tls_sources = +@TLS_TRUE@tls_sources = tlsibuf.h tlsibuf.cc tlsobuf.h tlsobuf.cc +libfdbuf_a_SOURCES = \ + fdbuf.h \ + fdbuf.cc \ + fdbuf_copy.cc \ + fdibuf.h \ + fdibuf.cc \ + fdobuf.h \ + fdobuf.cc \ + fdobuf_chownmod.cc \ + fdobuf_seek.cc \ + fdobuf_signed.cc \ + fdobuf_unsigned.cc \ + $(tls_sources) \ + $(mystring_sources) + +all: all-am + +.SUFFIXES: +.SUFFIXES: .cc .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) --gnu lib/fdbuf/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu lib/fdbuf/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): + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libfdbuf.a: $(libfdbuf_a_OBJECTS) $(libfdbuf_a_DEPENDENCIES) $(EXTRA_libfdbuf_a_DEPENDENCIES) + $(AM_V_at)-rm -f libfdbuf.a + $(AM_V_AR)$(libfdbuf_a_AR) libfdbuf.a $(libfdbuf_a_OBJECTS) $(libfdbuf_a_LIBADD) + $(AM_V_at)$(RANLIB) libfdbuf.a + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdbuf.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdbuf_copy.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdibuf.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdibuf_mystring.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdibuf_netstring.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdobuf.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdobuf_chownmod.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdobuf_seek.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdobuf_signed.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fdobuf_unsigned.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tlsibuf.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tlsobuf.Po@am__quote@ + +.cc.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $< + +.cc.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + 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-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + 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" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +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 $(LIBRARIES) +installdirs: +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-generic clean-noinstLIBRARIES mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +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 + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am 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 pdf pdf-am ps ps-am tags tags-am uninstall \ + uninstall-am + +.PRECIOUS: Makefile + + +# 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: diff --git a/lib/fdbuf/fdbuf.cc b/lib/fdbuf/fdbuf.cc new file mode 100644 index 0000000..2b3d65a --- /dev/null +++ b/lib/fdbuf/fdbuf.cc @@ -0,0 +1,107 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> + +/////////////////////////////////////////////////////////////////////////////// +// Class fdbuf +/////////////////////////////////////////////////////////////////////////////// +fdbuf::fdbuf(int fdesc, bool dc, unsigned bufsz) + : buf(new char[bufsz]), + buflength(0), + bufstart(0), + offset(0), + errnum(0), + flags(0), + bufsize(bufsz), + fd(fdesc), + do_close(dc) +{ + if(!buf) { + flags = flag_error; + errnum = errno; + } + if(fdesc < 0) + flags |= flag_closed; +#ifdef _REENTRANT + pthread_mutex_t tmp = PTHREAD_MUTEX_INITIALIZER; + mutex = tmp; + pthread_mutex_init(&mutex, 0); +#else +#ifdef FDBUF_MUTEX_DEBUG + mutex_count = 0; +#endif +#endif +} + +fdbuf::~fdbuf() +{ + close(); +#ifdef _REENTRANT + pthread_mutex_destroy(&mutex); +#endif + delete buf; +} + +bool fdbuf::error() const +{ + return flags & flag_error; +} + +bool fdbuf::closed() const +{ + return flags & flag_closed; +} + +bool fdbuf::close() +{ + if(do_close && fd >= 0 && !(flags & flag_closed)) { + if(::close(fd) == -1) { + errnum = errno; + flags |= flag_error; + return false; + } + flags |= flag_closed; + } + return true; +} + +#if defined(FDBUF_MUTEX_DEBUG) && !defined(_REENTRANT) +{ + int* null = 0; + (*null)++; + kill(getpid(), 9); +} + +// Debugging code +void fdbuf::lock() +{ + if(mutex) + abort(); + ++mutex; +} + +void fdbuf::unlock() +{ + if(mutex != 1) + abort(); + --mutex; +} +#endif diff --git a/lib/fdbuf/fdbuf.h b/lib/fdbuf/fdbuf.h new file mode 100644 index 0000000..d11682f --- /dev/null +++ b/lib/fdbuf/fdbuf.h @@ -0,0 +1,83 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#ifndef FDBUF__H__ +#define FDBUF__H__ + +#include "config.h" +#include <string.h> +#include <fcntl.h> +#include <unistd.h> + +#ifdef _REENTRANT +#include <pthread.h> +#endif + +#ifndef FDBUF_SIZE +#define FDBUF_SIZE 4096 +#endif + +class mystring; + +class fdbuf +{ +public: + enum flagbits { flag_eof=1, flag_error=2, flag_closed=4 }; + + fdbuf(int fdesc, bool dc, unsigned bufsz = FDBUF_SIZE); + ~fdbuf(); + bool error() const; + bool closed() const; + bool close(); +#ifdef _REENTRANT + void lock() { pthread_mutex_lock(&mutex); } + void unlock() { pthread_mutex_unlock(&mutex); } +#else +#ifdef FDBUF_MUTEX_DEBUG + void lock(); + void unlock(); +#else + void lock() { } + void unlock() { } +#endif +#endif +protected: + char* const buf; + unsigned buflength; // Length of the data in the buffer + unsigned bufstart; // Start of the data in the buffer + unsigned offset; // Current file read/write offset + int errnum; // Saved error flag + unsigned flags; // Status flags + + const unsigned bufsize; // Total buffer size + const int fd; + const bool do_close; // True to close on destructor + +#ifdef _REENTRANT + pthread_mutex_t mutex; +#else +#ifdef FDBUF_MUTEX_DEBUG + unsigned mutex; +#endif +#endif +}; + +bool fdbuf_copy(class fdibuf&, class fdobuf&, bool noflush = false); + +#include "fdbuf/fdibuf.h" +#include "fdbuf/fdobuf.h" + +#endif // FDBUF__H__ diff --git a/lib/fdbuf/fdbuf_copy.cc b/lib/fdbuf/fdbuf_copy.cc new file mode 100644 index 0000000..a31ab0b --- /dev/null +++ b/lib/fdbuf/fdbuf_copy.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" + +/////////////////////////////////////////////////////////////////////////////// +// Other routines +/////////////////////////////////////////////////////////////////////////////// +bool fdbuf_copy(fdibuf& in, fdobuf& out, bool noflush) +{ + if(in.eof()) + return true; + if(!in || !out) + return false; + do { + char buf[FDBUF_SIZE]; + if(!in.read(buf, FDBUF_SIZE) && in.last_count() == 0) + break; + if(!out.write(buf, in.last_count()) && out.last_count() < in.last_count()) + return false; + } while(!in.eof()); + if(!noflush && !out.flush()) + return false; + return in.eof(); +} diff --git a/lib/fdbuf/fdibuf.cc b/lib/fdbuf/fdibuf.cc new file mode 100644 index 0000000..205d63c --- /dev/null +++ b/lib/fdbuf/fdibuf.cc @@ -0,0 +1,197 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> + +/////////////////////////////////////////////////////////////////////////////// +// Class fdibuf +/////////////////////////////////////////////////////////////////////////////// +fdibuf::fdibuf(int fdesc, bool dc, unsigned bufsz) + : fdbuf(fdesc, dc, bufsz) +{ +} + +fdibuf::fdibuf(const char* filename, unsigned bufsz) + : fdbuf(open(filename, O_RDONLY), true, bufsz) +{ + if(fd == -1) { + flags = flag_error; + errnum = errno; + } +} + +fdibuf::~fdibuf() +{ +} + +bool fdibuf::eof() const +{ + return (flags & flag_eof) && (bufstart >= buflength); +} + +bool fdibuf::operator!() const +{ + return eof() || error() || closed(); +} + +// refill is protected -- no locking +bool fdibuf::refill() +{ + if(flags) + return false; + if(bufstart != 0) { + if(bufstart < buflength) { + buflength -= bufstart; + memcpy(buf, buf+bufstart, buflength); + } else + buflength = 0; + bufstart = 0; + } + unsigned oldbuflength = buflength; + if(buflength < bufsize) { + ssize_t red = _read(buf+buflength, bufsize-buflength); + if(red < 0) { + errnum = errno; + flags |= flag_error; + } + else if(red == 0) + flags |= flag_eof; + else { + buflength += red; + offset += red; + } + } + return buflength > oldbuflength; +} + +bool fdibuf::get(char& ch) +{ + lock(); + count = 0; + if(bufstart >= buflength) + refill(); + bool r = true; + if(eof() || error()) + r = false; + else { + ch = buf[bufstart++]; + count = 1; + } + unlock(); + return r; +} + +bool fdibuf::read_large(char* data, unsigned datalen) +{ + lock(); + count = 0; + + // If there's any content in the buffer, memcpy it out first. + unsigned len = buflength - bufstart; + if(len > datalen) + len = datalen; + memcpy(data, buf+bufstart, len); + data += len; + datalen -= len; + bufstart += len; + count += len; + + // After the buffer is empty and there's still data to read, + // read it straight from the fd instead of copying it through the buffer. + while(datalen > 0) { + ssize_t red = _read(data, datalen); + if(red < 0) { + errnum = errno; + flags |= flag_error; + break; + } + else if(red == 0) { + flags |= flag_eof; + break; + } + data += red; + datalen -= red; + offset += red; + count += red; + } + unlock(); + return datalen == 0; +} + +bool fdibuf::read(char* data, unsigned datalen) +{ + if(datalen >= bufsize) + return read_large(data, datalen); + lock(); + count = 0; + char* ptr = data; + while(datalen && !eof()) { + if(bufstart >= buflength) + refill(); + unsigned len = buflength-bufstart; + if(len > datalen) + len = datalen; + memcpy(ptr, buf+bufstart, len); + bufstart += len; + datalen -= len; + ptr += len; + count += len; + } + unlock(); + return !datalen; +} + +bool fdibuf::seek(unsigned o) +{ + lock(); + unsigned buf_start = offset - buflength; + if(o >= buf_start && o < offset) { + bufstart = o - buf_start; + } + else { + if(lseek(fd, o, SEEK_SET) != (off_t)o) { + errnum = errno; + flags |= flag_error; + unlock(); + return false; + } + offset = o; + buflength = bufstart = 0; + } + count = 0; + flags &= ~flag_eof; + unlock(); + return true; +} + +bool fdibuf::seekfwd(unsigned o) +{ + return seek(tell() + o); +} + +ssize_t fdibuf::_read(char* buf, ssize_t len) +{ + return ::read(fd, buf, len); +} + +/////////////////////////////////////////////////////////////////////////////// +// Globals +/////////////////////////////////////////////////////////////////////////////// +fdibuf fin(0); diff --git a/lib/fdbuf/fdibuf.h b/lib/fdbuf/fdibuf.h new file mode 100644 index 0000000..8906b8c --- /dev/null +++ b/lib/fdbuf/fdibuf.h @@ -0,0 +1,53 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#ifndef FDBUF__FDIBUF__H__ +#define FDBUF__FDIBUF__H__ + +#include "fdbuf.h" + +class fdibuf : protected fdbuf +{ +public: + fdibuf(const char* filename, unsigned bufsz = FDBUF_SIZE); + fdibuf(int fdesc, bool dc = false, unsigned bufsz = FDBUF_SIZE); + virtual ~fdibuf(); + bool close() { lock(); bool r = fdbuf::close(); unlock(); return r; } + bool eof() const; + bool operator!() const ; + operator bool() const { return !operator!(); } + virtual bool get(char& ch); + virtual bool getline(mystring& out, char terminator = '\n'); + virtual bool getnetstring(mystring& out); + virtual bool read(char*, unsigned); + virtual bool read_large(char*, unsigned); + bool read(unsigned char* b, unsigned l) { return read((char*)b, l); } + bool read(signed char* b, unsigned l) { return read((char*)b, l); } + unsigned last_count() { return count; } + bool seek(unsigned o); + bool seekfwd(unsigned o); + bool rewind() { return seek(0); } + unsigned tell() const { return offset-buflength+bufstart; } + int error_number() const { return errnum; } +protected: + unsigned count; // Number of bytes read by last operation + bool refill(); + virtual ssize_t _read(char*, ssize_t); +}; + +extern fdibuf fin; + +#endif // FDBUF__FDIBUF__H__ diff --git a/lib/fdbuf/fdibuf_mystring.cc b/lib/fdbuf/fdibuf_mystring.cc new file mode 100644 index 0000000..3b40bdc --- /dev/null +++ b/lib/fdbuf/fdibuf_mystring.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include <string.h> +#include "fdbuf.h" +#include "mystring/mystring.h" + +bool fdibuf::getline(mystring& out, char terminator) +{ + lock(); + count = 0; + if(bufstart >= buflength) + refill(); + if(eof() || error()) { + unlock(); + return false; + } + out = ""; + while(!eof() && !error()) { + char* ptr = buf+bufstart; + unsigned bufleft = buflength - bufstart; + const char* end = (const char*)memchr(ptr, terminator, bufleft); + if(!end) { + out += mystring(ptr, bufleft); + bufstart = buflength; + count += bufleft; + refill(); + } + else { + unsigned copylen = end - ptr; + out += mystring(ptr, copylen); + bufstart += copylen+1; + count += copylen+1; + break; + } + } + unlock(); + return true; +} diff --git a/lib/fdbuf/fdibuf_netstring.cc b/lib/fdbuf/fdibuf_netstring.cc new file mode 100644 index 0000000..5f16004 --- /dev/null +++ b/lib/fdbuf/fdibuf_netstring.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include <string.h> +#include "fdbuf.h" +#include "mystring/mystring.h" + +bool fdibuf::getnetstring(mystring& out) +{ + // Read in the size + char ch; + unsigned long size = 0; + for(;;) { + if(!get(ch)) + return false; + if(ch == ':') + break; + else if(ch >= '0' && ch <= '9') + size = size*10 + (ch-'0'); + else + return false; + } + char tmp[size]; + if(!read(tmp, size) || !get(ch) || ch != ',') + return false; + out = mystring(tmp, size); + return true; +} diff --git a/lib/fdbuf/fdobuf.cc b/lib/fdbuf/fdobuf.cc new file mode 100644 index 0000000..e1a6031 --- /dev/null +++ b/lib/fdbuf/fdobuf.cc @@ -0,0 +1,214 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" +#include <errno.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> + +/////////////////////////////////////////////////////////////////////////////// +// Globals +/////////////////////////////////////////////////////////////////////////////// +fdobuf fout(1); +fdobuf ferr(2); + +/////////////////////////////////////////////////////////////////////////////// +// Class fdobuf +/////////////////////////////////////////////////////////////////////////////// +fdobuf::fdobuf(int fdesc, bool dc, unsigned bufsz) + : fdbuf(fdesc, dc, bufsz), + bufpos(0) +{ +} + +fdobuf::fdobuf(const char* filename, int f, int mode, unsigned bufsz) + : fdbuf(open(filename, O_WRONLY | f, mode), true, bufsz), + bufpos(0) +{ + if(fd == -1) { + flags = flag_error; + errnum = errno; + } +} + +fdobuf::~fdobuf() +{ + flush(); +} + +bool fdobuf::close() +{ + if(!flush()) + return false; + lock(); + bool r = fdbuf::close(); + unlock(); + return r; +} + +bool fdobuf::operator!() const +{ + return error() || closed(); +} + +bool fdobuf::nflush(bool withsync) +{ + if(flags) + return false; + while(bufstart < buflength) { + ssize_t written = _write(buf+bufstart, buflength-bufstart); + if(written < 0) { + flags |= flag_error; + errnum = errno; + return false; + } + else { + bufstart += written; + offset += written; + } + } + buflength = 0; + bufstart = 0; + bufpos = 0; + if(withsync && (fsync(fd) == -1)) { + flags |= flag_error; + errnum = errno; + return false; + } + return true; +} + +bool fdobuf::flush() +{ + lock(); + bool r = nflush(false); + unlock(); + return r; +} + +bool fdobuf::sync() +{ + lock(); + bool r = nflush(true); + unlock(); + return r; +} + +bool fdobuf::write(char ch) +{ + if(flags) + return false; + + lock(); + count = 0; + buf[bufpos++] = ch; + //if(buflength >= bufsize && !nflush(false)) { + // unlock(); + // return false; + //} + if(bufpos >= buflength) + buflength = bufpos; + if(buflength >= bufsize && !nflush(false)) { + unlock(); + return false; + } + count = 1; + unlock(); + return true; +} + +bool fdobuf::write_large(const char* data, unsigned datalen) +{ + if(flags) + return false; + + lock(); + count = 0; + + if(!nflush(false)) { + unlock(); + return false; + } + + while(datalen > 0) { + ssize_t written = _write(data, datalen); + if(written < 0) { + flags |= flag_error; + errnum = errno; + unlock(); + return false; + } + datalen -= written; + data += written; + offset += written; + count += written; + } + unlock(); + return true; +} + +bool fdobuf::write(const char* data, unsigned datalen) +{ + if(datalen >= bufsize) + return write_large(data, datalen); + + if(flags) + return false; + + lock(); + const char* ptr = data; + count = 0; + // Amount is the number of bytes available in the buffer + unsigned amount = bufsize-bufpos; + while(datalen >= amount) { + // If we get here, this copy will completely fill the buffer, + // requiring a flush + memcpy(buf+bufpos, ptr, amount); + bufpos = bufsize; + buflength = bufsize; + datalen -= amount; + ptr += amount; + if(!nflush(false)) { + unlock(); + return false; + } + count += amount; + amount = bufsize-bufpos; + } + // At this point, the remaining data will fit into the buffer + memcpy(buf+bufpos, ptr, datalen); + count += datalen; + bufpos += datalen; + if(bufpos > buflength) buflength = bufpos; + unlock(); + return true; +} + +ssize_t fdobuf::_write(const char* buf, ssize_t len) +{ + return ::write(fd, buf, len); +} + +/////////////////////////////////////////////////////////////////////////////// +// Manipulators +/////////////////////////////////////////////////////////////////////////////// +fdobuf& endl(fdobuf& fd) +{ + fd.write("\n", 1); + fd.flush(); + return fd; +} diff --git a/lib/fdbuf/fdobuf.h b/lib/fdbuf/fdobuf.h new file mode 100644 index 0000000..f59f815 --- /dev/null +++ b/lib/fdbuf/fdobuf.h @@ -0,0 +1,92 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#ifndef FDBUF__FDOBUF__H__ +#define FDBUF__FDOBUF__H__ + +#include "fdbuf.h" + +class fdobuf : protected fdbuf +{ +public: + enum openflags { create=O_CREAT, + excl=O_EXCL, + trunc=O_TRUNC, + append=O_APPEND }; + + fdobuf(const char* filename, int, int mode = 0666, + unsigned bufsz = FDBUF_SIZE); + fdobuf(int fdesc, bool dc=false, unsigned bufsz = FDBUF_SIZE); + virtual ~fdobuf(); + bool close(); + bool operator!() const; + operator bool() const + { + return !operator!(); + } + bool flush(); + bool sync(); + virtual bool write(char); + bool write(unsigned char c) { return write((char)c); } + bool write(signed char c) { return write((char)c); } + virtual bool write(const char*, unsigned); + bool write(const unsigned char* b, unsigned l) { return write((char*)b, l); } + bool write(const signed char* b, unsigned l) { return write((char*)b, l); } + virtual bool write_large(const char*, unsigned); + unsigned last_count() { return count; } + bool seek(unsigned o); + bool rewind() { return seek(0); } + unsigned tell() const { return offset + bufpos; } + + bool chown(uid_t, gid_t) const; + bool chmod(mode_t) const; + + fdobuf& operator<<(const char* str) + { + write(str, strlen(str)); + return *this; + } + fdobuf& operator<<(char ch) + { + write(ch); + return *this; + } + fdobuf& operator<<(fdobuf& (*manip)(fdobuf&)) + { + return manip(*this); + } + fdobuf& operator<<(unsigned long); + fdobuf& operator<<(signed long); + fdobuf& operator<<(unsigned i) { return operator<<((unsigned long)i); } + fdobuf& operator<<(signed i) { return operator<<((signed long)i); } + fdobuf& operator<<(unsigned short i) { return operator<<((unsigned long)i); } + fdobuf& operator<<(signed short i) { return operator<<((signed long)i); } + + int error_number() const { return errnum; } +protected: + virtual bool nflush(bool withsync); + virtual ssize_t _write(const char* buf, ssize_t len); + + unsigned bufpos; // Current write position in the buffer + unsigned count; // Number of bytes written by last operation +}; + +fdobuf& endl(fdobuf& fd); + +extern fdobuf fout; +extern fdobuf ferr; + +#endif // FDBUF__FDOBUF__H__ diff --git a/lib/fdbuf/fdobuf_chownmod.cc b/lib/fdbuf/fdobuf_chownmod.cc new file mode 100644 index 0000000..61bc34a --- /dev/null +++ b/lib/fdbuf/fdobuf_chownmod.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include <string.h> +#include "fdbuf.h" +#include <sys/stat.h> +#include <unistd.h> + +bool fdobuf::chown(uid_t uid, gid_t gid) const +{ + if(error()) + return false; + return fchown(fd, uid, gid) != -1; +} + +bool fdobuf::chmod(mode_t mode) const +{ + if(error()) + return false; + return fchmod(fd, mode) != -1; +} diff --git a/lib/fdbuf/fdobuf_seek.cc b/lib/fdbuf/fdobuf_seek.cc new file mode 100644 index 0000000..ab376ea --- /dev/null +++ b/lib/fdbuf/fdobuf_seek.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" +#include <errno.h> +#include <unistd.h> + +bool fdobuf::seek(unsigned o) +{ + if(flags) + return false; + + lock(); + unsigned buf_start = offset; + unsigned buf_end = offset + buflength; + if(o >= buf_start && o < buf_end) { + bufpos = o - buf_start; + } + else { + if(!nflush(false)) { + unlock(); + return false; + } + if(lseek(fd, o, SEEK_SET) != (off_t)o) { + errnum = errno; + flags |= flag_error; + unlock(); + return false; + } + offset = o; + } + count = 0; + unlock(); + return true; +} diff --git a/lib/fdbuf/fdobuf_signed.cc b/lib/fdbuf/fdobuf_signed.cc new file mode 100644 index 0000000..4282ace --- /dev/null +++ b/lib/fdbuf/fdobuf_signed.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" +#include <limits.h> + +#define MAXSTRLEN ((sizeof(signed long)*CHAR_BIT)/3) + +fdobuf& fdobuf::operator<<(signed long i) +{ + if(i == 0) + return operator<<('0'); + if(i < 0) { + operator<<('-'); + i = -i; + } + char buf[MAXSTRLEN+1]; + char* ptr = buf+MAXSTRLEN; + *ptr-- = 0; + while(i) { + *ptr-- = i % 10 + '0'; + i /= 10; + } + return operator<<(ptr+1); +} diff --git a/lib/fdbuf/fdobuf_unsigned.cc b/lib/fdbuf/fdobuf_unsigned.cc new file mode 100644 index 0000000..61fc098 --- /dev/null +++ b/lib/fdbuf/fdobuf_unsigned.cc @@ -0,0 +1,34 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "fdbuf.h" +#include <limits.h> + +#define MAXSTRLEN ((sizeof(signed long)*CHAR_BIT)/3) + +fdobuf& fdobuf::operator<<(unsigned long i) +{ + if(i == 0) + return operator<<('0'); + char buf[MAXSTRLEN+1]; + char* ptr = buf+MAXSTRLEN; + *ptr-- = 0; + while(i) { + *ptr-- = i % 10 + '0'; + i /= 10; + } + return operator<<(ptr+1); +} diff --git a/lib/fdbuf/tlsibuf.cc b/lib/fdbuf/tlsibuf.cc new file mode 100644 index 0000000..787c323 --- /dev/null +++ b/lib/fdbuf/tlsibuf.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "tlsibuf.h" + +/////////////////////////////////////////////////////////////////////////////// +// Class tlsibuf +/////////////////////////////////////////////////////////////////////////////// +tlsibuf::tlsibuf(gnutls_session_t s, unsigned bufsz) + : fdibuf(-1, false, bufsz), session(s) +{ + flags &= ~flag_closed; +} + +ssize_t tlsibuf::_read(char* buf, ssize_t len) +{ + return gnutls_record_recv(session, buf, len); +} diff --git a/lib/fdbuf/tlsibuf.h b/lib/fdbuf/tlsibuf.h new file mode 100644 index 0000000..3c74365 --- /dev/null +++ b/lib/fdbuf/tlsibuf.h @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#ifndef FDBUF__TLSIBUF__H__ +#define FDBUF__TLSIBUF__H__ + +#include "fdibuf.h" +#include <gnutls/gnutls.h> + +class tlsibuf : public fdibuf +{ +public: + tlsibuf(gnutls_session_t, unsigned bufsz = FDBUF_SIZE); +protected: + gnutls_session_t session; + virtual ssize_t _read(char* buf, ssize_t len); +}; + +#endif // FDBUF__TLSIBUF__H__ diff --git a/lib/fdbuf/tlsobuf.cc b/lib/fdbuf/tlsobuf.cc new file mode 100644 index 0000000..83d68f8 --- /dev/null +++ b/lib/fdbuf/tlsobuf.cc @@ -0,0 +1,31 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#include "tlsobuf.h" + +/////////////////////////////////////////////////////////////////////////////// +// Class tlsobuf +/////////////////////////////////////////////////////////////////////////////// +tlsobuf::tlsobuf(gnutls_session_t s, unsigned bufsz) + : fdobuf(-1, false, bufsz), session(s) +{ + flags &= ~flag_closed; +} + +ssize_t tlsobuf::_write(const char* buf, ssize_t len) +{ + return gnutls_record_send(session, buf, len); +} diff --git a/lib/fdbuf/tlsobuf.h b/lib/fdbuf/tlsobuf.h new file mode 100644 index 0000000..43f68ec --- /dev/null +++ b/lib/fdbuf/tlsobuf.h @@ -0,0 +1,32 @@ +// Copyright (C) 2017 Bruce Guenter <bruce@untroubled.org> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +#ifndef FDBUF__TLSOBUF__H__ +#define FDBUF__TLSOBUF__H__ + +#include "fdobuf.h" +#include <gnutls/gnutls.h> + +class tlsobuf : public fdobuf +{ +public: + tlsobuf(gnutls_session_t, unsigned bufsz = FDBUF_SIZE); +protected: + gnutls_session_t session; + virtual ssize_t _write(const char* buf, ssize_t len); +}; + +#endif // FDBUF__TLSOBUF__H__ |