You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
the begginning
This commit is contained in:
30
utils/messageqcpp/Calpont.xml
Normal file
30
utils/messageqcpp/Calpont.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Calpont Version="V1.0.0">
|
||||
<Messageq>
|
||||
<Dir>.</Dir>
|
||||
</Messageq>
|
||||
<server1>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
<Port>7601</Port>
|
||||
</server1>
|
||||
<server2>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
<Port>7602</Port>
|
||||
</server2>
|
||||
<server3>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
<Port>7603</Port>
|
||||
</server3>
|
||||
<server4>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
<Port>7604</Port>
|
||||
</server4>
|
||||
<server5>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
<Port>7605</Port>
|
||||
</server5>
|
||||
<server6>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
<Port>7606</Port>
|
||||
</server6>
|
||||
</Calpont>
|
105
utils/messageqcpp/Makefile
Executable file
105
utils/messageqcpp/Makefile
Executable file
@ -0,0 +1,105 @@
|
||||
include ../../rules.mak
|
||||
#******************************************************************************************
|
||||
# Copyright (C) 2009-2012 Calpont Corporation
|
||||
# All rights reserved
|
||||
#*****************************************************************************************/
|
||||
.PHONY: install clean test docs coverage leakcheck
|
||||
|
||||
PROGRAM=libmessageqcpp.so
|
||||
VERSION=1.0.0
|
||||
LIBRARY=$(PROGRAM).$(VERSION)
|
||||
|
||||
CPPFLAGS=-I$(EXPORT_ROOT)/include -I/usr/include/libxml2 -DPIC
|
||||
CXXFLAGS+=$(DEBUG_FLAGS) -Wall -fpic
|
||||
|
||||
CLIBS=-L$(EXPORT_ROOT)/lib -lconfigcpp -lmessageqcpp -lloggingcpp -lidbboot -lxml2 -lboost_idb
|
||||
TLIBS=-L. $(IDB_COMMON_LIBS) -lcppunit $(CLIBS)
|
||||
GLIBS=$(TLIBS)
|
||||
|
||||
LLIBS=-L$(CALPONT_LIBRARY_PATH) -lloggingcpp
|
||||
|
||||
SRCS= messagequeue.cpp bytestream.cpp socketparms.cpp inetstreamsocket.cpp iosocket.cpp \
|
||||
compressed_iss.cpp
|
||||
LINCLUDES= messagequeue.h bytestream.h socketparms.h inetstreamsocket.h iosocket.h \
|
||||
serversocket.h socket.h serializeable.h socketclosed.h
|
||||
|
||||
OBJS=$(SRCS:.cpp=.o)
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
$(LINK.cpp) -shared -o $(LIBRARY) $(OBJS)
|
||||
rm -f $(PROGRAM)
|
||||
ln -s $(LIBRARY) $(PROGRAM)
|
||||
|
||||
install: bootstrap $(LIBRARY)
|
||||
umask 002; \
|
||||
mkdir -p $(INSTALL_ROOT_LIB) $(INSTALL_ROOT_INCLUDE); \
|
||||
pushd $(INSTALL_ROOT_LIB) >/dev/null; \
|
||||
rm -f $(LIBRARY) $(PROGRAM); \
|
||||
ln -s $(LIBRARY) $(PROGRAM); \
|
||||
popd >/dev/null; \
|
||||
$(INSTALL) $(LIBRARY) $(INSTALL_ROOT_LIB)
|
||||
|
||||
bootstrap:
|
||||
$(INSTALL) $(LINCLUDES) $(INSTALL_ROOT_INCLUDE)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) tdriver.o $(PROGRAM) $(LIBRARY) tdriver core *~ *.tag *-gcov.* *.gcov tdriver-gcov *.d
|
||||
rm -rf html cli cli.o srv srv.o
|
||||
|
||||
docs:
|
||||
doxygen $(EXPORT_ROOT)/etc/Doxyfile
|
||||
|
||||
tdriver: tdriver.o
|
||||
$(LINK.cpp) -o $@ $^ $(TLIBS)
|
||||
|
||||
test: $(LIBRARY) tdriver
|
||||
LD_LIBRARY_PATH=.:$(EXPORT_ROOT)/lib:/usr/local/lib ./tdriver
|
||||
|
||||
%-gcov.o: %.cpp
|
||||
$(COMPILE.cpp) -o $@ $^
|
||||
|
||||
tdriver-gcov: CXXFLAGS+=-fprofile-arcs -ftest-coverage
|
||||
tdriver-gcov: tdriver-gcov.o $(subst .o,-gcov.o,$(OBJS))
|
||||
$(LINK.cpp) -o $@ $^ $(GLIBS)
|
||||
|
||||
coverage: tdriver-gcov
|
||||
rm -f *.gcda
|
||||
LD_LIBRARY_PATH=.:$(EXPORT_ROOT)/lib:/usr/local/lib ./tdriver-gcov
|
||||
for file in $(SRCS); do \
|
||||
bfile=`basename $$file .cpp`; \
|
||||
gcov -o $${bfile}-gcov $$file >/dev/null; \
|
||||
done
|
||||
/usr/local/bin/genCoverage.pl $(SRCS)
|
||||
|
||||
PGLIBS=$(GLIBS)
|
||||
|
||||
%-prof.o: %.cpp
|
||||
$(COMPILE.cpp) -o $@ $^
|
||||
|
||||
tdriver-prof: CXXFLAGS+=-pg
|
||||
tdriver-prof: tdriver-prof.o $(subst .o,-prof.o,$(OBJS))
|
||||
$(LINK.cpp) -o $@ $^ $(PGLIBS)
|
||||
|
||||
profile: tdriver-prof
|
||||
LD_LIBRARY_PATH=.:$(EXPORT_ROOT)/lib:/usr/local/lib ./tdriver-prof
|
||||
gprof ./tdriver-prof
|
||||
|
||||
leakcheck: $(LIBRARY) tdriver
|
||||
LD_LIBRARY_PATH=.:$(EXPORT_ROOT)/lib:/usr/local/lib valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./tdriver --leakcheck
|
||||
|
||||
srv: srv.o
|
||||
$(LINK.cpp) -o $@ $^ $(CLIBS)
|
||||
|
||||
cli: cli.o
|
||||
$(LINK.cpp) -o $@ $^ $(CLIBS)
|
||||
|
||||
%.d: %.cpp
|
||||
@set -e; rm -f $@; \
|
||||
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
|
||||
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
|
||||
rm -f $@.$$$$
|
||||
|
||||
ifndef BOOTSTRAP
|
||||
-include $(SRCS:.cpp=.d) tdriver.d
|
||||
endif
|
||||
|
39
utils/messageqcpp/Makefile.am
Normal file
39
utils/messageqcpp/Makefile.am
Normal file
@ -0,0 +1,39 @@
|
||||
# Copyright (C) 2014 InfiniDB, Inc.
|
||||
#
|
||||
# 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; version 2 of
|
||||
# the License.
|
||||
#
|
||||
# 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
# $Id: Makefile.am 3639 2013-03-18 12:36:37Z rdempsey $
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AM_CPPFLAGS = $(idb_common_includes) $(idb_cppflags)
|
||||
AM_CFLAGS = $(idb_cflags)
|
||||
AM_CXXFLAGS = $(idb_cxxflags)
|
||||
AM_LDFLAGS = -version-info 1:0:0 $(idb_ldflags)
|
||||
lib_LTLIBRARIES = libmessageqcpp.la
|
||||
libmessageqcpp_la_SOURCES = messagequeue.cpp bytestream.cpp socketparms.cpp inetstreamsocket.cpp iosocket.cpp compressed_iss.cpp
|
||||
include_HEADERS = messagequeue.h bytestream.h socketparms.h inetstreamsocket.h iosocket.h \
|
||||
serversocket.h socket.h serializeable.h socketclosed.h
|
||||
|
||||
test:
|
||||
|
||||
coverage:
|
||||
|
||||
leakcheck:
|
||||
|
||||
docs:
|
||||
|
||||
bootstrap: install-data-am
|
||||
|
552
utils/messageqcpp/Makefile.in
Normal file
552
utils/messageqcpp/Makefile.in
Normal file
@ -0,0 +1,552 @@
|
||||
# Makefile.in generated by automake 1.9.6 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
# 2003, 2004, 2005 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@
|
||||
|
||||
# Copyright (C) 2014 InfiniDB, Inc.
|
||||
#
|
||||
# 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; version 2 of
|
||||
# the License.
|
||||
#
|
||||
# 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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301, USA.
|
||||
|
||||
# $Id: Makefile.am 3639 2013-03-18 12:36:37Z rdempsey $
|
||||
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
top_builddir = ../..
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
INSTALL = @INSTALL@
|
||||
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@
|
||||
subdir = utils/messageqcpp
|
||||
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/compilerflags.m4 \
|
||||
$(top_srcdir)/m4/functions.m4 $(top_srcdir)/m4/install.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_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 = `echo $$p | sed -e 's|^.*/||'`;
|
||||
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
|
||||
libLTLIBRARIES_INSTALL = $(INSTALL)
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
libmessageqcpp_la_LIBADD =
|
||||
am_libmessageqcpp_la_OBJECTS = messagequeue.lo bytestream.lo \
|
||||
socketparms.lo inetstreamsocket.lo iosocket.lo \
|
||||
compressed_iss.lo
|
||||
libmessageqcpp_la_OBJECTS = $(am_libmessageqcpp_la_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
LTCXXCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(CXX) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CXXFLAGS) $(CXXFLAGS)
|
||||
CXXLD = $(CXX)
|
||||
CXXLINK = $(LIBTOOL) --tag=CXX --mode=link $(CXXLD) $(AM_CXXFLAGS) \
|
||||
$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
SOURCES = $(libmessageqcpp_la_SOURCES)
|
||||
DIST_SOURCES = $(libmessageqcpp_la_SOURCES)
|
||||
includeHEADERS_INSTALL = $(INSTALL_HEADER)
|
||||
HEADERS = $(include_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
ALLOCA = @ALLOCA@
|
||||
AMDEP_FALSE = @AMDEP_FALSE@
|
||||
AMDEP_TRUE = @AMDEP_TRUE@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
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@
|
||||
ECHO = @ECHO@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
F77 = @F77@
|
||||
FFLAGS = @FFLAGS@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LEX = @LEX@
|
||||
LEXLIB = @LEXLIB@
|
||||
LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
POW_LIB = @POW_LIB@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
XML2_CONFIG = @XML2_CONFIG@
|
||||
XML_CPPFLAGS = @XML_CPPFLAGS@
|
||||
XML_LIBS = @XML_LIBS@
|
||||
YACC = @YACC@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_CXX = @ac_ct_CXX@
|
||||
ac_ct_F77 = @ac_ct_F77@
|
||||
ac_ct_RANLIB = @ac_ct_RANLIB@
|
||||
ac_ct_STRIP = @ac_ct_STRIP@
|
||||
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
|
||||
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
|
||||
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
|
||||
am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
|
||||
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@
|
||||
datadir = @datadir@
|
||||
etcdir = @etcdir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
idb_brm_libs = @idb_brm_libs@
|
||||
idb_cflags = @idb_cflags@
|
||||
idb_common_includes = @idb_common_includes@
|
||||
idb_common_ldflags = @idb_common_ldflags@
|
||||
idb_common_libs = @idb_common_libs@
|
||||
idb_cppflags = @idb_cppflags@
|
||||
idb_cxxflags = @idb_cxxflags@
|
||||
idb_exec_libs = @idb_exec_libs@
|
||||
idb_ldflags = @idb_ldflags@
|
||||
idb_oam_libs = @idb_oam_libs@
|
||||
idb_write_libs = @idb_write_libs@
|
||||
idbinstall = @idbinstall@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
localdir = @localdir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
march_flags = @march_flags@
|
||||
mibdir = @mibdir@
|
||||
mkdir_p = @mkdir_p@
|
||||
mysqldir = @mysqldir@
|
||||
netsnmp_libs = @netsnmp_libs@
|
||||
netsnmpagntdir = @netsnmpagntdir@
|
||||
netsnmpdir = @netsnmpdir@
|
||||
netsnmplibrdir = @netsnmplibrdir@
|
||||
netsnmpmachdir = @netsnmpmachdir@
|
||||
netsnmpsysdir = @netsnmpsysdir@
|
||||
oldincludedir = @oldincludedir@
|
||||
postdir = @postdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
sbindir = @sbindir@
|
||||
sharedir = @sharedir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
toolsdir = @toolsdir@
|
||||
AM_CPPFLAGS = $(idb_common_includes) $(idb_cppflags)
|
||||
AM_CFLAGS = $(idb_cflags)
|
||||
AM_CXXFLAGS = $(idb_cxxflags)
|
||||
AM_LDFLAGS = -version-info 1:0:0 $(idb_ldflags)
|
||||
lib_LTLIBRARIES = libmessageqcpp.la
|
||||
libmessageqcpp_la_SOURCES = messagequeue.cpp bytestream.cpp socketparms.cpp inetstreamsocket.cpp iosocket.cpp compressed_iss.cpp
|
||||
include_HEADERS = messagequeue.h bytestream.h socketparms.h inetstreamsocket.h iosocket.h \
|
||||
serversocket.h socket.h serializeable.h socketclosed.h
|
||||
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .cpp .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 \
|
||||
&& exit 0; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu utils/messageqcpp/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu utils/messageqcpp/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
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
|
||||
$(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
p=$(am__strip_dir) \
|
||||
echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
|
||||
$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
|
||||
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
|
||||
libmessageqcpp.la: $(libmessageqcpp_la_OBJECTS) $(libmessageqcpp_la_DEPENDENCIES)
|
||||
$(CXXLINK) -rpath $(libdir) $(libmessageqcpp_la_LDFLAGS) $(libmessageqcpp_la_OBJECTS) $(libmessageqcpp_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bytestream.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/compressed_iss.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inetstreamsocket.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iosocket.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/messagequeue.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/socketparms.Plo@am__quote@
|
||||
|
||||
.cpp.o:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $<
|
||||
|
||||
.cpp.obj:
|
||||
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.cpp.lo:
|
||||
@am__fastdepCXX_TRUE@ if $(LTCXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
|
||||
@am__fastdepCXX_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
-rm -f libtool
|
||||
uninstall-info-am:
|
||||
install-includeHEADERS: $(include_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
test -z "$(includedir)" || $(mkdir_p) "$(DESTDIR)$(includedir)"
|
||||
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
f=$(am__strip_dir) \
|
||||
echo " $(includeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(includedir)/$$f'"; \
|
||||
$(includeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(includedir)/$$f"; \
|
||||
done
|
||||
|
||||
uninstall-includeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||
f=$(am__strip_dir) \
|
||||
echo " rm -f '$(DESTDIR)$(includedir)/$$f'"; \
|
||||
rm -f "$(DESTDIR)$(includedir)/$$f"; \
|
||||
done
|
||||
|
||||
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; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
mkid -fID $$unique
|
||||
tags: TAGS
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
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; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$tags $$unique; \
|
||||
fi
|
||||
ctags: CTAGS
|
||||
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
|
||||
$(TAGS_FILES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
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; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$tags $$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& 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)'; for file in $$list; do \
|
||||
case $$file in \
|
||||
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
|
||||
esac; \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
|
||||
dir="/$$dir"; \
|
||||
$(mkdir_p) "$(distdir)$$dir"; \
|
||||
else \
|
||||
dir=''; \
|
||||
fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
|
||||
fi; \
|
||||
cp -pR $$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) $(HEADERS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libdir)" "$(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:
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
`test -z '$(STRIP)' || \
|
||||
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_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-libLTLIBRARIES clean-libtool \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-includeHEADERS
|
||||
|
||||
install-exec-am: install-libLTLIBRARIES
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-man:
|
||||
|
||||
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-includeHEADERS uninstall-info-am \
|
||||
uninstall-libLTLIBRARIES
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libLTLIBRARIES clean-libtool ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags distdir dvi dvi-am html html-am info info-am \
|
||||
install install-am install-data install-data-am install-exec \
|
||||
install-exec-am install-includeHEADERS install-info \
|
||||
install-info-am install-libLTLIBRARIES install-man \
|
||||
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-includeHEADERS uninstall-info-am \
|
||||
uninstall-libLTLIBRARIES
|
||||
|
||||
|
||||
test:
|
||||
|
||||
coverage:
|
||||
|
||||
leakcheck:
|
||||
|
||||
docs:
|
||||
|
||||
bootstrap: install-data-am
|
||||
# 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:
|
9
utils/messageqcpp/bogus.xml
Normal file
9
utils/messageqcpp/bogus.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Calpont Version="V1.0.0">
|
||||
<ExeMgr>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
</ExeMgr>
|
||||
<JobProc>
|
||||
<IPAddr>127.0.0.1</IPAddr>
|
||||
</JobProc>
|
||||
</Calpont>
|
592
utils/messageqcpp/bytestream.cpp
Normal file
592
utils/messageqcpp/bytestream.cpp
Normal file
@ -0,0 +1,592 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: bytestream.cpp 3862 2013-06-05 13:29:12Z rdempsey $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <inttypes.h>
|
||||
using namespace std;
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/scoped_array.hpp>
|
||||
#include <boost/version.hpp>
|
||||
using namespace boost;
|
||||
|
||||
#define BYTESTREAM_DLLEXPORT
|
||||
#include "bytestream.h"
|
||||
#undef BYTESTREAM_DLLEXPORT
|
||||
|
||||
#define DEBUG_DUMP_STRINGS_LESS_THAN 0
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
/* Copies only the data left to be read */
|
||||
void ByteStream::doCopy(const ByteStream &rhs)
|
||||
{
|
||||
uint32_t rlen = rhs.length();
|
||||
|
||||
if (fMaxLen < rlen) {
|
||||
delete [] fBuf;
|
||||
fBuf = new uint8_t[rlen + ISSOverhead];
|
||||
fMaxLen = rlen;
|
||||
}
|
||||
|
||||
memcpy(fBuf + ISSOverhead, rhs.fCurOutPtr, rlen);
|
||||
fCurInPtr = fBuf + ISSOverhead + rlen;
|
||||
fCurOutPtr = fBuf + ISSOverhead;
|
||||
}
|
||||
|
||||
ByteStream::ByteStream(const ByteStream& rhs) :
|
||||
fBuf(0), fCurInPtr(0), fCurOutPtr(0), fMaxLen(0)
|
||||
{
|
||||
//don't need to copy an empty ByteStream
|
||||
if (rhs.fBuf)
|
||||
doCopy(rhs);
|
||||
}
|
||||
|
||||
ByteStream::ByteStream(const SBS &rhs) :
|
||||
fBuf(0), fCurInPtr(0), fCurOutPtr(0), fMaxLen(0)
|
||||
{
|
||||
if (rhs->fBuf)
|
||||
doCopy(*rhs);
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator=(const ByteStream& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
if (rhs.fBuf)
|
||||
doCopy(rhs);
|
||||
else
|
||||
{
|
||||
delete [] fBuf;
|
||||
fBuf = fCurInPtr = fCurOutPtr = 0;
|
||||
fMaxLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream::ByteStream(uint32_t initSize) :
|
||||
fBuf(0), fCurInPtr(0), fCurOutPtr(0), fMaxLen(0)
|
||||
{
|
||||
if (initSize > 0) growBuf(initSize);
|
||||
}
|
||||
|
||||
void ByteStream::add(const uint8_t b)
|
||||
{
|
||||
if (fBuf == 0 || (static_cast<uint32_t>(fCurInPtr - fBuf) == fMaxLen + ISSOverhead))
|
||||
growBuf();
|
||||
|
||||
*fCurInPtr++ = b;
|
||||
}
|
||||
|
||||
void ByteStream::growBuf(uint32_t toSize)
|
||||
{
|
||||
if (fBuf == 0)
|
||||
{
|
||||
if (toSize == 0)
|
||||
toSize = BlockSize;
|
||||
else
|
||||
toSize = ((toSize + BlockSize - 1) / BlockSize) * BlockSize;
|
||||
fBuf = new uint8_t[toSize + ISSOverhead];
|
||||
#ifdef ZERO_ON_NEW
|
||||
memset(fBuf, 0, (toSize+ISSOverhead));
|
||||
#endif
|
||||
fMaxLen = toSize;
|
||||
fCurInPtr =
|
||||
fCurOutPtr = fBuf + ISSOverhead;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (toSize == 0)
|
||||
toSize = fMaxLen + BlockSize;
|
||||
else
|
||||
toSize = ((toSize + BlockSize - 1) / BlockSize) * BlockSize;
|
||||
if (toSize <= fMaxLen)
|
||||
return;
|
||||
|
||||
// Make sure we at least double the allocation
|
||||
toSize = std::max(toSize, fMaxLen * 2);
|
||||
|
||||
uint8_t* t = new uint8_t[toSize + ISSOverhead];
|
||||
uint32_t curOutOff = fCurOutPtr - fBuf;
|
||||
uint32_t curInOff = fCurInPtr - fBuf;
|
||||
memcpy(t, fBuf, fCurInPtr - fBuf);
|
||||
#ifdef ZERO_ON_NEW
|
||||
memset(t+(fCurInPtr-fBuf), 0, (toSize+ISSOverhead)-(fCurInPtr-fBuf));
|
||||
#endif
|
||||
delete [] fBuf;
|
||||
fBuf = t;
|
||||
fMaxLen = toSize;
|
||||
fCurInPtr = fBuf + curInOff;
|
||||
fCurOutPtr = fBuf + curOutOff;
|
||||
}
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const int8_t b)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 1U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((int8_t *) fCurInPtr) = b;
|
||||
fCurInPtr += 1;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const uint8_t b)
|
||||
{
|
||||
add(b);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const int16_t d)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 2U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((int16_t *) fCurInPtr) = d;
|
||||
fCurInPtr += 2;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const uint16_t d)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 2U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((uint16_t *) fCurInPtr) = d;
|
||||
fCurInPtr += 2;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const int32_t q)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 4U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((int32_t *) fCurInPtr) = q;
|
||||
fCurInPtr += 4;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const uint32_t q)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 4U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((uint32_t *) fCurInPtr) = q;
|
||||
fCurInPtr += 4;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const int64_t o)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 8U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((int64_t *) fCurInPtr) = o;
|
||||
fCurInPtr += 8;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const uint64_t o)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 8U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
*((uint64_t *) fCurInPtr) = o;
|
||||
fCurInPtr += 8;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const string& s)
|
||||
{
|
||||
int32_t len = s.size();
|
||||
|
||||
*this << len;
|
||||
#if DEBUG_DUMP_STRINGS_LESS_THAN > 0
|
||||
if (len < DEBUG_DUMP_STRINGS_LESS_THAN)
|
||||
{
|
||||
cerr << "bs: appending string len " << len << ": ";
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
char xxx=s.c_str()[i];
|
||||
if (isprint(xxx)) cerr << xxx << ' ';
|
||||
else cerr << "0x" << hex << ((unsigned)xxx&0xff) << dec << ' ';
|
||||
}
|
||||
cerr << endl;
|
||||
}
|
||||
#endif
|
||||
append(reinterpret_cast<const uint8_t*>(s.c_str()), len);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(int8_t& b)
|
||||
{
|
||||
peek(b);
|
||||
fCurOutPtr++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uint8_t& b)
|
||||
{
|
||||
peek(b);
|
||||
fCurOutPtr++;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(int16_t& d)
|
||||
{
|
||||
peek(d);
|
||||
fCurOutPtr += 2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uint16_t& d)
|
||||
{
|
||||
peek(d);
|
||||
fCurOutPtr += 2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(int32_t& q)
|
||||
{
|
||||
peek(q);
|
||||
fCurOutPtr += 4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uint32_t& q)
|
||||
{
|
||||
peek(q);
|
||||
fCurOutPtr += 4;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(int64_t& o)
|
||||
{
|
||||
peek(o);
|
||||
fCurOutPtr += 8;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uint64_t& o)
|
||||
{
|
||||
peek(o);
|
||||
fCurOutPtr += 8;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(string& s)
|
||||
{
|
||||
peek(s);
|
||||
fCurOutPtr += 4 + s.length();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uint8_t*& bpr)
|
||||
{
|
||||
peek(bpr);
|
||||
restart();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ByteStream::peek(int8_t& b) const
|
||||
{
|
||||
if (length() < 1)
|
||||
throw underflow_error("ByteStream::peek(int8_t): not enough data in stream to fill datatype");
|
||||
|
||||
b = *fCurOutPtr;
|
||||
}
|
||||
|
||||
void ByteStream::peek(uint8_t& b) const
|
||||
{
|
||||
if (length() < 1)
|
||||
throw underflow_error("ByteStream::peek(uint8_t): not enough data in stream to fill datatype");
|
||||
|
||||
b = *((int8_t *)fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(int16_t& d) const
|
||||
{
|
||||
if (length() < 2)
|
||||
throw underflow_error("ByteStream>int16_t: not enough data in stream to fill datatype");
|
||||
|
||||
d = *((int16_t *) fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(uint16_t& d) const
|
||||
{
|
||||
if (length() < 2)
|
||||
throw underflow_error("ByteStream>uint16_t: not enough data in stream to fill datatype");
|
||||
|
||||
d = *((uint16_t *) fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(int32_t& q) const
|
||||
{
|
||||
if (length() < 4)
|
||||
throw underflow_error("ByteStream>int32_t: not enough data in stream to fill datatype");
|
||||
|
||||
q = *((int32_t *) fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(uint32_t& q) const
|
||||
{
|
||||
if (length() < 4)
|
||||
throw underflow_error("ByteStream>uint32_t: not enough data in stream to fill datatype");
|
||||
|
||||
q = *((uint32_t *) fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(int64_t& o) const
|
||||
{
|
||||
|
||||
if (length() < 8)
|
||||
throw underflow_error("ByteStream>int64_t: not enough data in stream to fill datatype");
|
||||
|
||||
o = *((int64_t *) fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(uint64_t& o) const
|
||||
{
|
||||
|
||||
if (length() < 8)
|
||||
throw underflow_error("ByteStream>uint64_t: not enough data in stream to fill datatype");
|
||||
|
||||
o = *((uint64_t *) fCurOutPtr);
|
||||
}
|
||||
|
||||
void ByteStream::peek(string& s) const
|
||||
{
|
||||
int32_t len;
|
||||
|
||||
peek(len);
|
||||
#if DEBUG_DUMP_STRINGS_LESS_THAN > 0
|
||||
if (len < DEBUG_DUMP_STRINGS_LESS_THAN)
|
||||
{
|
||||
cerr << "bs: reading string len " << len << ": ";
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
char xxx = fCurOutPtr[4+i];
|
||||
if (isprint(xxx)) cerr << xxx << ' ';
|
||||
else cerr << "0x" << hex << ((unsigned)xxx&0xff) << dec << ' ';
|
||||
}
|
||||
cerr << endl;
|
||||
}
|
||||
#endif
|
||||
if (len < 0)
|
||||
throw logging::ProtocolError("expected a string");
|
||||
|
||||
//we know len >= 0 by now...
|
||||
if (length() < static_cast<uint32_t>(len + 4))
|
||||
{
|
||||
#if DEBUG_DUMP_STRINGS_LESS_THAN > 0
|
||||
cerr << "bs: wanted " << len + 4 << " bytes, but there are only " << length() << " remaining" << endl;
|
||||
#endif
|
||||
// "put back" the qbyte we just read for strong exception guarantee
|
||||
throw underflow_error("ByteStream>string: not enough data in stream to fill datatype");
|
||||
}
|
||||
|
||||
s.assign((char *) &fCurOutPtr[4], len);
|
||||
}
|
||||
|
||||
void ByteStream::load(const uint8_t* bp, uint32_t len)
|
||||
{
|
||||
// Do all the stuff that could throw an exception first
|
||||
if (bp == 0 && len != 0)
|
||||
throw invalid_argument("ByteStream::load: bp cannot equal 0 when len is not equal to 0");
|
||||
|
||||
uint32_t newMaxLen = (len + BlockSize - 1) / BlockSize * BlockSize;
|
||||
|
||||
if (len > fMaxLen) {
|
||||
delete [] fBuf;
|
||||
fBuf = new uint8_t[newMaxLen + ISSOverhead];
|
||||
fMaxLen = newMaxLen;
|
||||
}
|
||||
|
||||
memcpy(fBuf + ISSOverhead, bp, len);
|
||||
fCurOutPtr = fBuf + ISSOverhead;
|
||||
fCurInPtr = fBuf + len + ISSOverhead;
|
||||
}
|
||||
|
||||
void ByteStream::append(const uint8_t* bp, uint32_t len)
|
||||
{
|
||||
if (len == 0)
|
||||
return;
|
||||
if (bp == 0)
|
||||
throw invalid_argument("ByteStream::append: bp cannot equal 0 when len is not equal to 0");
|
||||
|
||||
uint32_t newSize = static_cast<uint32_t>(fCurInPtr - fBuf + len);
|
||||
|
||||
if (fBuf == 0 || (newSize > fMaxLen))
|
||||
growBuf(newSize);
|
||||
|
||||
memcpy(fCurInPtr, bp, len);
|
||||
fCurInPtr += len;
|
||||
}
|
||||
|
||||
void ByteStream::swap(ByteStream& rhs)
|
||||
{
|
||||
std::swap(fBuf, rhs.fBuf);
|
||||
std::swap(fCurInPtr, rhs.fCurInPtr);
|
||||
std::swap(fCurOutPtr, rhs.fCurOutPtr);
|
||||
std::swap(fMaxLen, rhs.fMaxLen);
|
||||
}
|
||||
|
||||
ifstream& operator>>(ifstream& ifs, ByteStream& bs)
|
||||
{
|
||||
int ifs_len;
|
||||
ifs.seekg(0, ios::end);
|
||||
ifs_len = ifs.tellg();
|
||||
ifs.seekg(0, ios::beg);
|
||||
boost::scoped_array<char> buf(new char[ifs_len]);
|
||||
ifs.read(buf.get(), ifs_len);
|
||||
bs.append(reinterpret_cast<const uint8_t*>(buf.get()), ifs_len);
|
||||
return ifs;
|
||||
}
|
||||
|
||||
bool ByteStream::operator==(const ByteStream& b) const
|
||||
{
|
||||
if (b.length() != length())
|
||||
return false;
|
||||
|
||||
return (memcmp(fCurOutPtr, b.fCurOutPtr, length()) == 0);
|
||||
}
|
||||
|
||||
bool ByteStream::operator!=(const ByteStream& b) const
|
||||
{
|
||||
return !(*this == b);
|
||||
}
|
||||
|
||||
/* Serializeable interface */
|
||||
void ByteStream::serialize(ByteStream &bs) const
|
||||
{
|
||||
bs << length();
|
||||
bs.append(buf(), length());
|
||||
}
|
||||
|
||||
void ByteStream::deserialize(ByteStream &bs)
|
||||
{
|
||||
uint32_t len;
|
||||
|
||||
restart();
|
||||
bs >> len;
|
||||
load(bs.buf(), len);
|
||||
bs.advance(len);
|
||||
}
|
||||
|
||||
void ByteStream::needAtLeast(size_t amount)
|
||||
{
|
||||
size_t currentSpace;
|
||||
|
||||
currentSpace = fMaxLen - (fCurInPtr - (fBuf + ISSOverhead));
|
||||
if (currentSpace < amount)
|
||||
growBuf(fMaxLen + amount);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#if BOOST_VERSION < 104500
|
||||
ByteStream& ByteStream::operator<<(const uint32_t ui)
|
||||
{
|
||||
if (fBuf == 0 || (fCurInPtr - fBuf + 4U > fMaxLen + ISSOverhead))
|
||||
growBuf(fMaxLen + BlockSize);
|
||||
uint32_t q = ui;
|
||||
*((uint32_t *) fCurInPtr) = q;
|
||||
fCurInPtr += 4;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uint32_t& ui)
|
||||
{
|
||||
uint32_t q;
|
||||
peek(q);
|
||||
fCurOutPtr += 4;
|
||||
ui = q;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ByteStream& ByteStream::operator<<(const ByteStream& bs)
|
||||
{
|
||||
uint32_t len = bs.length();
|
||||
|
||||
*this << len;
|
||||
|
||||
append(bs.buf(), len);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(ByteStream& bs)
|
||||
{
|
||||
peek(bs);
|
||||
fCurOutPtr += 4 + bs.length();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ByteStream::peek(ByteStream& bs) const
|
||||
{
|
||||
uint32_t len;
|
||||
|
||||
peek(len);
|
||||
|
||||
if (length() < len)
|
||||
throw underflow_error("ByteStream>ByteStream: not enough data in stream to fill datatype");
|
||||
|
||||
bs.load(&fCurOutPtr[4], len);
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator<<(const uuid& u)
|
||||
{
|
||||
append(reinterpret_cast<const uint8_t*>(&u.data[0]), uuids::uuid::static_size());
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteStream& ByteStream::operator>>(uuid& u)
|
||||
{
|
||||
peek(u);
|
||||
fCurOutPtr += uuids::uuid::static_size();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ByteStream::peek(uuid& u) const
|
||||
{
|
||||
if (length() < uuids::uuid::static_size())
|
||||
throw underflow_error("ByteStream>uuid: not enough data in stream to fill datatype");
|
||||
|
||||
memcpy(&u.data[0], fCurOutPtr, uuids::uuid::static_size());
|
||||
}
|
||||
|
||||
}//namespace messageqcpp
|
||||
|
567
utils/messageqcpp/bytestream.h
Normal file
567
utils/messageqcpp/bytestream.h
Normal file
@ -0,0 +1,567 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/******************************************************************************************
|
||||
* $Id: bytestream.h 3861 2013-06-04 20:59:23Z dhall $
|
||||
*
|
||||
*
|
||||
******************************************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_BYTESTREAM_H
|
||||
#define MESSAGEQCPP_BYTESTREAM_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <stdint.h>
|
||||
#include <cstring>
|
||||
|
||||
#include "exceptclasses.h"
|
||||
#include "serializeable.h"
|
||||
|
||||
class ByteStreamTestSuite;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxBYTESTREAM_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
typedef boost::shared_ptr<ByteStream> SBS;
|
||||
|
||||
/**
|
||||
* @brief A class to marshall bytes as a stream
|
||||
*
|
||||
* The ByteStream class is used to marshall numeric data into and out of a stream of
|
||||
* bytes (unsigned chars). It is a FIFO queue that maintains current input and output
|
||||
* pointers.
|
||||
*
|
||||
* @warning Alas, due to recent changes this class no longer implements a strong execption guarantee.
|
||||
*
|
||||
* @warning the current implementation does not know how to compact memory, so it should be
|
||||
* destructed or have reset() called to clear out the current uint8_t array. Also, multi-uint8_t
|
||||
* numeric values are pushed and dequeued in the native byte order, so they are not portable
|
||||
* across machines with different byte orders.
|
||||
*
|
||||
*/
|
||||
class ByteStream : public Serializeable
|
||||
{
|
||||
public:
|
||||
// We now use the standard Linux types of uint8_t, uint16_t, etc.
|
||||
// These are kept around for backward compatibility
|
||||
typedef uint8_t byte;
|
||||
typedef uint16_t doublebyte;
|
||||
typedef uint32_t quadbyte;
|
||||
typedef uint64_t octbyte;
|
||||
typedef boost::uuids::uuid uuid;
|
||||
|
||||
/**
|
||||
* default ctor
|
||||
*/
|
||||
EXPORT explicit ByteStream(uint32_t initSize=8192); // multiples of pagesize are best
|
||||
/**
|
||||
* ctor with a uint8_t array and len initializer
|
||||
*/
|
||||
inline ByteStream(const uint8_t* bp, const uint32_t len);
|
||||
/**
|
||||
* copy ctor
|
||||
*/
|
||||
EXPORT ByteStream(const ByteStream& rhs);
|
||||
EXPORT ByteStream(const SBS &rhs);
|
||||
/**
|
||||
* assign op
|
||||
*/
|
||||
EXPORT ByteStream& operator=(const ByteStream& rhs);
|
||||
/**
|
||||
* assign op
|
||||
*/
|
||||
inline ByteStream& operator=(const SBS &rhs);
|
||||
/**
|
||||
* dtor
|
||||
*/
|
||||
inline virtual ~ByteStream();
|
||||
|
||||
/**
|
||||
* push a int8_t onto the end of the stream
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const int8_t b);
|
||||
/**
|
||||
* push a uint8_t onto the end of the stream
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const uint8_t b);
|
||||
/**
|
||||
* push a int16_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const int16_t d);
|
||||
/**
|
||||
* push a uint16_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const uint16_t d);
|
||||
/**
|
||||
* push a int32_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const int32_t q);
|
||||
/**
|
||||
* push a uint32_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const uint32_t q);
|
||||
#ifdef _MSC_VER
|
||||
#if BOOST_VERSION < 104500
|
||||
//These 2 are to make MS VC++ w/ boost < 1.45 happy
|
||||
// TODO: Do we still need these?
|
||||
EXPORT ByteStream& operator<<(const uint32_t ui);
|
||||
|
||||
EXPORT ByteStream& operator>>(uint32_t& ui);
|
||||
#endif
|
||||
#endif
|
||||
/**
|
||||
* push an int64_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const int64_t o);
|
||||
/**
|
||||
* push an uint64_t onto the end of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const uint64_t o);
|
||||
/**
|
||||
* push a std::string onto the end of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const std::string& s);
|
||||
/**
|
||||
* push an arbitrary class onto the end of the stream.
|
||||
*/
|
||||
inline ByteStream& operator<<(const Serializeable& s);
|
||||
/**
|
||||
* push a ByteStream onto the end of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const ByteStream& bs);
|
||||
/**
|
||||
* push a UUID onto the end of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator<<(const uuid& u);
|
||||
|
||||
/**
|
||||
* extract a int8_t from the front of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(int8_t& b);
|
||||
/**
|
||||
* extract a uint8_t from the front of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uint8_t& b);
|
||||
/**
|
||||
* extract a int16_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(int16_t& d);
|
||||
/**
|
||||
* extract a uint16_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uint16_t& d);
|
||||
/**
|
||||
* extract a int32_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(int32_t& q);
|
||||
/**
|
||||
* extract a uint32_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uint32_t& q);
|
||||
/**
|
||||
* extract an int64_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(int64_t& o);
|
||||
/**
|
||||
* extract an uint64_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uint64_t& o);
|
||||
/**
|
||||
* extract a std::string from the front of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(std::string& s);
|
||||
/**
|
||||
* write the current stream into b. The ByteStream will be empty after this operation.
|
||||
* @warning the caller is responsible for making sure b is big enough to hold all the data (perhaps by
|
||||
* calling length()).
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uint8_t*& b);
|
||||
/**
|
||||
* extract an arbitrary object from the front of the stream.
|
||||
*/
|
||||
inline ByteStream& operator>>(Serializeable& s);
|
||||
/**
|
||||
* extract a ByteStream from the front of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(ByteStream& bs);
|
||||
/**
|
||||
* extract a UUID from the front of the stream.
|
||||
*/
|
||||
EXPORT ByteStream& operator>>(uuid& u);
|
||||
|
||||
/**
|
||||
* Peek at a int8_t from the front of the stream.
|
||||
*/
|
||||
EXPORT void peek(int8_t& b) const;
|
||||
/**
|
||||
* Peek at a uint8_t from the front of the stream.
|
||||
*/
|
||||
EXPORT void peek(uint8_t& b) const;
|
||||
/**
|
||||
* Peek at a int16_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(int16_t& d) const;
|
||||
/**
|
||||
* Peek at a uint16_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(uint16_t& d) const;
|
||||
/**
|
||||
* Peek at a int32_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(int32_t& q) const;
|
||||
/**
|
||||
* Peek at a uint32_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(uint32_t& q) const;
|
||||
/**
|
||||
* Peek at an int64_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(int64_t& o) const;
|
||||
/**
|
||||
* Peek at an uint64_t from the front of the stream. The byte order is whatever the native byte order is.
|
||||
*/
|
||||
EXPORT void peek(uint64_t& o) const;
|
||||
/**
|
||||
* Peek at a std::string from the front of the stream.
|
||||
*/
|
||||
EXPORT void peek(std::string& s) const;
|
||||
/**
|
||||
* Peek at the whole ByteStream buffer.
|
||||
* @warning the caller is responsible for making sure b is big enough to hold all the data (perhaps by
|
||||
* calling length()).
|
||||
*/
|
||||
inline void peek(uint8_t*& b) const;
|
||||
/**
|
||||
* Peek at a ByteStream from the front of the stream.
|
||||
*/
|
||||
EXPORT void peek(ByteStream& bs) const;
|
||||
/**
|
||||
* Peek at a UUID from the front of the stream.
|
||||
*/
|
||||
EXPORT void peek(uuid& u) const;
|
||||
|
||||
/**
|
||||
* load the stream from an array. Clears out any previous data.
|
||||
*/
|
||||
EXPORT void load(const uint8_t* bp, uint32_t len);
|
||||
|
||||
/**
|
||||
* append bytes to the end of the stream.
|
||||
*/
|
||||
EXPORT void append(const uint8_t* bp, uint32_t len);
|
||||
|
||||
/**
|
||||
* equality check on buffer contents.
|
||||
*/
|
||||
EXPORT bool operator==(const ByteStream& b) const;
|
||||
|
||||
/**
|
||||
* inequality check on buffer contents.
|
||||
*/
|
||||
EXPORT bool operator!=(const ByteStream& b) const;
|
||||
|
||||
/**
|
||||
* these fcns are an alternative to code like {build a msg, bs.load or bs.append}.
|
||||
* This will let us build the msg directly in the BS buffer.
|
||||
*/
|
||||
EXPORT void needAtLeast(size_t amount);
|
||||
inline uint8_t *getInputPtr();
|
||||
inline void advanceInputPtr(size_t amount);
|
||||
|
||||
/**
|
||||
* returns a const pointer to the current head of the queue. If you use it for
|
||||
* raw access, you might want to advance the current head.
|
||||
*/
|
||||
inline const uint8_t* buf() const;
|
||||
|
||||
/**
|
||||
* returns a pointer to the current head of the queue. If you use it for
|
||||
* raw access, you might want to advance the current head.
|
||||
*/
|
||||
inline uint8_t* buf();
|
||||
|
||||
/**
|
||||
* advance the output ptr without having to extract bytes
|
||||
* @warning be careful advancing near 4GB!
|
||||
*/
|
||||
inline void advance(uint32_t amt);
|
||||
|
||||
/**
|
||||
* returns the length of the queue (in bytes)
|
||||
* @warning do not attempt to make a ByteStream bigger than 4GB!
|
||||
*/
|
||||
inline uint32_t length() const;
|
||||
inline bool empty() const;
|
||||
|
||||
/**
|
||||
* returns the length of the queue, including header overhead (in bytes)
|
||||
*/
|
||||
inline uint32_t lengthWithHdrOverhead() const;
|
||||
|
||||
/**
|
||||
* clears the stream. Releases any current stream and sets all pointers to 0. The state of the object
|
||||
* is identical to its state immediately after default construction.
|
||||
*/
|
||||
inline void reset();
|
||||
|
||||
/**
|
||||
* operator+=
|
||||
*/
|
||||
inline ByteStream& operator+=(const ByteStream& rhs);
|
||||
|
||||
/**
|
||||
* swap this ByteStream with another ByteStream
|
||||
*/
|
||||
EXPORT void swap(ByteStream& rhs);
|
||||
|
||||
/**
|
||||
* reset the input & output pointers to the beginning
|
||||
*/
|
||||
inline void restart();
|
||||
|
||||
/**
|
||||
* Move the input pointer back to the beginning so the contents
|
||||
* can be read again.
|
||||
*/
|
||||
inline void rewind();
|
||||
|
||||
/**
|
||||
* Serializeable interface
|
||||
*/
|
||||
EXPORT void serialize(ByteStream &bs) const;
|
||||
|
||||
/**
|
||||
* Serializeable interface
|
||||
*/
|
||||
EXPORT void deserialize(ByteStream &bs);
|
||||
|
||||
/**
|
||||
* memory allocation chunk size
|
||||
*/
|
||||
EXPORT static const uint32_t BlockSize = 4096;
|
||||
|
||||
/** size of the space we want in front of the data */
|
||||
EXPORT static const uint32_t ISSOverhead = 2*sizeof(uint32_t); //space for the BS magic & length
|
||||
|
||||
friend class ::ByteStreamTestSuite;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* pushes one uint8_t onto the end of the stream
|
||||
*/
|
||||
void add(const uint8_t b);
|
||||
/**
|
||||
* adds another BlockSize bytes to the internal buffer
|
||||
*/
|
||||
void growBuf(uint32_t toSize=0);
|
||||
/**
|
||||
* handles member copying from one ByteStream to another
|
||||
*/
|
||||
void doCopy(const ByteStream& rhs);
|
||||
|
||||
private:
|
||||
|
||||
uint8_t* fBuf; ///the start of the allocated buffer
|
||||
uint8_t* fCurInPtr; //the point in fBuf where data is inserted next
|
||||
uint8_t* fCurOutPtr; //the point in fBuf where data is extracted from next
|
||||
uint32_t fMaxLen; //how big fBuf is currently
|
||||
};
|
||||
|
||||
// type descriptors to let ByteStream point out protocol errors, WIP
|
||||
static const uint8_t BS_UINT8 = 0;
|
||||
static const uint8_t BS_UINT16 = 1;
|
||||
static const uint8_t BS_UINT32 = 2;
|
||||
static const uint8_t BS_UINT64 = 3;
|
||||
static const uint8_t BS_INT8 = 4;
|
||||
static const uint8_t BS_INT16 = 5;
|
||||
static const uint8_t BS_INT32 = 6;
|
||||
static const uint8_t BS_INT64 = 7;
|
||||
static const uint8_t BS_STRING = 8;
|
||||
static const uint8_t BS_BLOB = 9;
|
||||
static const uint8_t BS_SERIALIZABLE = 10;
|
||||
static const uint8_t BS_UUID = 11;
|
||||
|
||||
inline ByteStream::ByteStream(const uint8_t* bp, const uint32_t len) : fBuf(0), fMaxLen(0) { load(bp, len); }
|
||||
inline ByteStream::~ByteStream() { delete [] fBuf; }
|
||||
|
||||
inline const uint8_t* ByteStream::buf() const { return fCurOutPtr; }
|
||||
inline uint8_t* ByteStream::buf() { return fCurOutPtr; }
|
||||
inline uint32_t ByteStream::length() const { return (uint32_t)(fCurInPtr - fCurOutPtr); }
|
||||
inline bool ByteStream::empty() const { return (length() == 0); }
|
||||
inline uint32_t ByteStream::lengthWithHdrOverhead() const
|
||||
{return (length() + ISSOverhead);}
|
||||
inline void ByteStream::reset() { delete [] fBuf; fMaxLen = 0;
|
||||
fCurInPtr = fCurOutPtr = fBuf = 0; }
|
||||
inline void ByteStream::restart() { fCurInPtr = fCurOutPtr = fBuf + ISSOverhead; }
|
||||
inline void ByteStream::rewind() { fCurOutPtr = fBuf + ISSOverhead; }
|
||||
inline void ByteStream::advance(uint32_t adv)
|
||||
{
|
||||
//fCurOutPtr is always >= fBuf, so fCurOutPtr - fBuf is >= 0, and this difference is always <= 32 bits
|
||||
//there is an edge condition not detected here: if fCurOutPtr - fBuf is nearly 4GB and you try to
|
||||
//advance by a lot, you will wrap over, so be warned!
|
||||
if (adv > length())
|
||||
throw std::length_error("ByteStream: advanced beyond the end of the buffer");
|
||||
fCurOutPtr += adv;
|
||||
}
|
||||
inline uint8_t* ByteStream::getInputPtr() { return fCurInPtr; }
|
||||
inline void ByteStream::advanceInputPtr(size_t amount) { fCurInPtr += amount; }
|
||||
inline void ByteStream::peek(uint8_t*& bpr) const { memcpy(bpr, fCurOutPtr, length()); }
|
||||
|
||||
inline ByteStream& ByteStream::operator+=(const ByteStream& rhs) { append(rhs.buf(), rhs.length()); return *this; }
|
||||
inline ByteStream operator+(const ByteStream& lhs, const ByteStream& rhs) { ByteStream temp(lhs); return temp += rhs; }
|
||||
inline ByteStream& ByteStream::operator>>(Serializeable& s) { s.deserialize(*this); return *this; }
|
||||
inline ByteStream& ByteStream::operator<<(const Serializeable& s) { s.serialize(*this); return *this; }
|
||||
inline ByteStream& ByteStream::operator=(const SBS& rhs) { *this = *rhs; return *this; }
|
||||
|
||||
/**
|
||||
* stream a ByteStream out to any ostream
|
||||
*/
|
||||
inline std::ostream& operator<<(std::ostream& os, const ByteStream& bs)
|
||||
{
|
||||
return os.write(reinterpret_cast<const char*>(bs.buf()), bs.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* stream a ByteStream in from a file
|
||||
*/
|
||||
EXPORT std::ifstream& operator>>(std::ifstream& os, ByteStream& bs);
|
||||
|
||||
/// Generic method to export a vector of T's that implement Serializeable
|
||||
template<typename T>
|
||||
void serializeVector(ByteStream& bs, const std::vector<T>& v)
|
||||
{
|
||||
typename std::vector<T>::const_iterator it;
|
||||
uint64_t size;
|
||||
|
||||
size = v.size();
|
||||
bs << size;
|
||||
for (it = v.begin(); it != v.end(); it++)
|
||||
bs << *it;
|
||||
}
|
||||
|
||||
/// Generic method to deserialize a vector of T's that implement Serializeable
|
||||
template<typename T>
|
||||
void deserializeVector(ByteStream& bs, std::vector<T>& v)
|
||||
{
|
||||
uint32_t i;
|
||||
T tmp;
|
||||
uint64_t size;
|
||||
|
||||
v.clear();
|
||||
bs >> size;
|
||||
for (i = 0; i < size; i++) {
|
||||
bs >> tmp;
|
||||
v.push_back(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
//Until the API is fixed to be 64-bit clean...
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable : 4267)
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
void serializeInlineVector(ByteStream &bs, const std::vector<T> &v)
|
||||
{
|
||||
uint64_t size = v.size();
|
||||
bs << size;
|
||||
if (size > 0)
|
||||
bs.append((const uint8_t *) &(v[0]), sizeof(T) * size);
|
||||
}
|
||||
|
||||
inline void serializeVector(ByteStream& bs, const std::vector<int64_t>& v) { serializeInlineVector<int64_t>(bs, v); }
|
||||
|
||||
template<typename T>
|
||||
void deserializeInlineVector(ByteStream &bs, std::vector<T> &v)
|
||||
{
|
||||
uint64_t size;
|
||||
const uint8_t *buf;
|
||||
|
||||
v.clear();
|
||||
bs >> size;
|
||||
if (size > 0)
|
||||
{
|
||||
v.resize(size);
|
||||
buf = bs.buf();
|
||||
memcpy(&(v[0]), buf, sizeof(T) * size);
|
||||
bs.advance(sizeof(T) * size);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
inline void deserializeVector(ByteStream& bs, std::vector<int64_t>& v) { deserializeInlineVector<int64_t>(bs, v); }
|
||||
|
||||
/// Generic method to serialize a set of T's that implement Serializeable
|
||||
template<typename T>
|
||||
void serializeSet(ByteStream &bs, const std::set<T> &s)
|
||||
{
|
||||
uint64_t size = s.size();
|
||||
bs << size;
|
||||
typename std::set<T>::const_iterator it;
|
||||
for (it = s.begin(); it != s.end(); ++it)
|
||||
bs << *it;
|
||||
}
|
||||
|
||||
/// Generic method to deserialize a set of T's that implement Serializeable
|
||||
template<typename T>
|
||||
void deserializeSet(ByteStream& bs, std::set<T>& s)
|
||||
{
|
||||
uint32_t i;
|
||||
T tmp;
|
||||
uint64_t size;
|
||||
|
||||
s.clear();
|
||||
bs >> size;
|
||||
for (i = 0; i < size; i++) {
|
||||
bs >> tmp;
|
||||
s.insert(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace messageqcpp
|
||||
|
||||
namespace std
|
||||
{
|
||||
/** total specialization of std::swap
|
||||
*
|
||||
*/
|
||||
template<> inline void swap<messageqcpp::ByteStream>(messageqcpp::ByteStream& lhs, messageqcpp::ByteStream&rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
}//namespace std
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif //MESSAGEQCPP_BYTESTREAM_H
|
38
utils/messageqcpp/cli.cpp
Normal file
38
utils/messageqcpp/cli.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace std;
|
||||
|
||||
#include "messagequeue.h"
|
||||
using namespace messageqcpp;
|
||||
|
||||
#include "configcpp.h"
|
||||
using namespace config;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Config* cf = Config::makeConfig("./Calpont.xml");
|
||||
MessageQueueClient mqc("server1", cf);
|
||||
|
||||
ByteStream obs;
|
||||
string msg("Hello, world!");
|
||||
ByteStream ibs;
|
||||
uint32_t qb;
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
obs.restart();
|
||||
obs << msg;
|
||||
cout << "writing " << obs.length() << " bytes to " << mqc.addr2String() << endl;
|
||||
mqc.write(obs);
|
||||
ibs = mqc.read();
|
||||
ibs >> qb;
|
||||
if (qb != 0)
|
||||
{
|
||||
string emsg("server did not ack message!");
|
||||
cerr << emsg << endl;
|
||||
throw runtime_error(emsg);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
239
utils/messageqcpp/compressed_iss.cpp
Normal file
239
utils/messageqcpp/compressed_iss.cpp
Normal file
@ -0,0 +1,239 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id$
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#ifdef _MSC_VER
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <icmpapi.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#if __FreeBSD__
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
#include <sys/socket.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include "compressed_iss.h"
|
||||
#include "iosocket.h"
|
||||
#include "configcpp.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace compress;
|
||||
|
||||
namespace messageqcpp
|
||||
{
|
||||
|
||||
CompressedInetStreamSocket::CompressedInetStreamSocket()
|
||||
{
|
||||
config::Config *config = config::Config::makeConfig();
|
||||
string val;
|
||||
|
||||
try {
|
||||
val = config->getConfig("NetworkCompression", "Enabled");
|
||||
}
|
||||
catch(...) { }
|
||||
|
||||
if (val == "" || val == "Y")
|
||||
useCompression = true;
|
||||
else
|
||||
useCompression = false;
|
||||
}
|
||||
|
||||
Socket * CompressedInetStreamSocket::clone() const
|
||||
{
|
||||
return new CompressedInetStreamSocket(*this);
|
||||
}
|
||||
|
||||
const SBS CompressedInetStreamSocket::read(const struct timespec* timeout, bool* isTimeOut,
|
||||
Stats *stats) const
|
||||
{
|
||||
SBS readBS, ret;
|
||||
size_t uncompressedSize;
|
||||
bool err;
|
||||
|
||||
readBS = InetStreamSocket::read(timeout, isTimeOut, stats);
|
||||
if (readBS->length() == 0 || fMagicBuffer == BYTESTREAM_MAGIC)
|
||||
return readBS;
|
||||
|
||||
err = alg.getUncompressedSize((char *) readBS->buf(), readBS->length(), &uncompressedSize);
|
||||
if (!err)
|
||||
return SBS(new ByteStream(0));
|
||||
|
||||
ret.reset(new ByteStream(uncompressedSize));
|
||||
alg.uncompress((char *) readBS->buf(), readBS->length(), (char *) ret->getInputPtr());
|
||||
ret->advanceInputPtr(uncompressedSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CompressedInetStreamSocket::write(const ByteStream &msg, Stats *stats)
|
||||
{
|
||||
size_t outLen=0;
|
||||
uint32_t len = msg.length();
|
||||
|
||||
if (useCompression && (len > 512)) {
|
||||
ByteStream smsg(alg.maxCompressedSize(len));
|
||||
|
||||
alg.compress((char *) msg.buf(), len, (char *) smsg.getInputPtr(), &outLen);
|
||||
smsg.advanceInputPtr(outLen);
|
||||
if (outLen < len)
|
||||
do_write(smsg, COMPRESSED_BYTESTREAM_MAGIC, stats);
|
||||
else
|
||||
InetStreamSocket::write(msg, stats);
|
||||
}
|
||||
else
|
||||
InetStreamSocket::write(msg, stats);
|
||||
}
|
||||
|
||||
void CompressedInetStreamSocket::write(SBS msg, Stats *stats)
|
||||
{
|
||||
write(*msg, stats);
|
||||
}
|
||||
|
||||
/* this was cut & pasted from InetStreamSocket;
|
||||
* is there a clean way to wrap ISS::accept()?
|
||||
*/
|
||||
const IOSocket CompressedInetStreamSocket::accept(const struct timespec* timeout)
|
||||
{
|
||||
int clientfd;
|
||||
long msecs = 0;
|
||||
|
||||
struct pollfd pfd[1];
|
||||
pfd[0].fd = socketParms().sd();
|
||||
pfd[0].events = POLLIN;
|
||||
|
||||
if (timeout != 0)
|
||||
{
|
||||
msecs = timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000;
|
||||
if (poll(pfd, 1, msecs) != 1 || (pfd[0].revents & POLLIN) == 0 ||
|
||||
pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL))
|
||||
return IOSocket(new CompressedInetStreamSocket());
|
||||
}
|
||||
|
||||
struct sockaddr sa;
|
||||
socklen_t sl = sizeof(sa);
|
||||
int e;
|
||||
do
|
||||
{
|
||||
clientfd = ::accept(socketParms().sd(), &sa, &sl);
|
||||
e = errno;
|
||||
} while (clientfd < 0 && (e == EINTR ||
|
||||
#ifdef ERESTART
|
||||
e == ERESTART ||
|
||||
#endif
|
||||
#ifdef ECONNABORTED
|
||||
e == ECONNABORTED ||
|
||||
#endif
|
||||
false));
|
||||
if (clientfd < 0)
|
||||
{
|
||||
string msg = "CompressedInetStreamSocket::accept: accept() error: ";
|
||||
scoped_array<char> buf(new char[80]);
|
||||
#if STRERROR_R_CHAR_P
|
||||
const char* p;
|
||||
if ((p = strerror_r(e, buf.get(), 80)) != 0)
|
||||
msg += p;
|
||||
#else
|
||||
int p;
|
||||
if ((p = strerror_r(e, buf.get(), 80)) == 0)
|
||||
msg += buf.get();
|
||||
#endif
|
||||
throw runtime_error(msg);
|
||||
}
|
||||
|
||||
if (fSyncProto)
|
||||
{
|
||||
/* send a byte to artificially synchronize with connect() on the remote */
|
||||
char b = 'A';
|
||||
int ret;
|
||||
|
||||
ret = ::send(clientfd, &b, 1, 0);
|
||||
e = errno;
|
||||
if (ret < 0) {
|
||||
ostringstream os;
|
||||
char blah[80];
|
||||
#if STRERROR_R_CHAR_P
|
||||
const char* p;
|
||||
if ((p = strerror_r(e, blah, 80)) != 0)
|
||||
os << "CompressedInetStreamSocket::accept sync: " << p;
|
||||
#else
|
||||
int p;
|
||||
if ((p = strerror_r(e, blah, 80)) == 0)
|
||||
os << "CompressedInetStreamSocket::accept sync: " << blah;
|
||||
#endif
|
||||
::close(clientfd);
|
||||
throw runtime_error(os.str());
|
||||
}
|
||||
else if (ret == 0) {
|
||||
::close(clientfd);
|
||||
throw runtime_error("CompressedInetStreamSocket::accept sync: got unexpected error code");
|
||||
}
|
||||
}
|
||||
|
||||
CompressedInetStreamSocket *ciss = new CompressedInetStreamSocket();
|
||||
IOSocket ios;
|
||||
sockaddr_in *sin = (sockaddr_in *) &sa;
|
||||
|
||||
if ((sin->sin_addr.s_addr == fSa.sin_addr.s_addr) ||
|
||||
sin->sin_addr.s_addr == inet_addr("127.0.0.1"))
|
||||
ciss->useCompression = false;
|
||||
|
||||
ios.setSocketImpl(ciss);
|
||||
SocketParms sp;
|
||||
sp = ios.socketParms();
|
||||
sp.sd(clientfd);
|
||||
ios.socketParms(sp);
|
||||
ios.sa(&sa);
|
||||
return ios;
|
||||
}
|
||||
|
||||
void CompressedInetStreamSocket::connect(const sockaddr* serv_addr)
|
||||
{
|
||||
sockaddr_in *sin = (sockaddr_in *) serv_addr;
|
||||
|
||||
if (sin->sin_addr.s_addr == fSa.sin_addr.s_addr ||
|
||||
sin->sin_addr.s_addr == inet_addr("127.0.0.1"))
|
||||
useCompression = false;
|
||||
InetStreamSocket::connect(serv_addr);
|
||||
}
|
||||
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
61
utils/messageqcpp/compressed_iss.h
Normal file
61
utils/messageqcpp/compressed_iss.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id$
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_COMPRESSED_ISS_H
|
||||
#define MESSAGEQCPP_COMPRESSED_ISS_H
|
||||
|
||||
#include <unistd.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "socket.h"
|
||||
#include "iosocket.h"
|
||||
#include "bytestream.h"
|
||||
#include "inetstreamsocket.h"
|
||||
#include "idbcompress.h"
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
class CompressedInetStreamSocket : public InetStreamSocket
|
||||
{
|
||||
public:
|
||||
CompressedInetStreamSocket();
|
||||
|
||||
virtual Socket * clone() const;
|
||||
virtual const SBS read(const struct timespec* timeout=0, bool* isTimeOut = NULL,
|
||||
Stats *stats = NULL) const;
|
||||
virtual void write(const ByteStream& msg, Stats *stats = NULL);
|
||||
virtual void write(SBS msg, Stats *stats = NULL);
|
||||
virtual const IOSocket accept(const struct timespec *timeout);
|
||||
virtual void connect(const sockaddr *addr);
|
||||
private:
|
||||
compress::IDBCompressInterface alg;
|
||||
bool useCompression;
|
||||
};
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif
|
1055
utils/messageqcpp/inetstreamsocket.cpp
Normal file
1055
utils/messageqcpp/inetstreamsocket.cpp
Normal file
File diff suppressed because it is too large
Load Diff
260
utils/messageqcpp/inetstreamsocket.h
Normal file
260
utils/messageqcpp/inetstreamsocket.h
Normal file
@ -0,0 +1,260 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: inetstreamsocket.h 3632 2013-03-13 18:08:46Z pleblanc $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_INETSTREAMSOCKET_H
|
||||
#define MESSAGEQCPP_INETSTREAMSOCKET_H
|
||||
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
#ifndef _MSC_VER
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include <cstring>
|
||||
|
||||
#include "socket.h"
|
||||
#include "socketparms.h"
|
||||
#include "bytestream.h"
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxINETSTREAMSOCKET_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
class MessageQTestSuite;
|
||||
|
||||
namespace messageqcpp {
|
||||
class IOSocket;
|
||||
|
||||
/// random # marking the beginning of a ByteStream in the stream
|
||||
const uint32_t BYTESTREAM_MAGIC = 0x14fbc137;
|
||||
const uint32_t COMPRESSED_BYTESTREAM_MAGIC = 0x14fbc138;
|
||||
|
||||
/** An Inet Stream Socket
|
||||
*
|
||||
*/
|
||||
class InetStreamSocket : public Socket
|
||||
{
|
||||
public:
|
||||
/** ctor
|
||||
*
|
||||
*/
|
||||
explicit InetStreamSocket(size_t blocksize=ByteStream::BlockSize);
|
||||
|
||||
/** dtor
|
||||
*
|
||||
*/
|
||||
virtual ~InetStreamSocket();
|
||||
|
||||
/** copy ctor
|
||||
*
|
||||
*/
|
||||
InetStreamSocket(const InetStreamSocket& rhs);
|
||||
|
||||
/** assign op
|
||||
*
|
||||
*/
|
||||
virtual InetStreamSocket& operator=(const InetStreamSocket& rhs);
|
||||
|
||||
/** fSocket mutator
|
||||
*
|
||||
*/
|
||||
inline virtual void socketParms(const SocketParms& socket);
|
||||
|
||||
/** fSocket accessor
|
||||
*
|
||||
*/
|
||||
inline virtual const SocketParms socketParms() const;
|
||||
|
||||
/** sockaddr mutator
|
||||
*
|
||||
*/
|
||||
inline virtual void sa(const sockaddr* sa);
|
||||
|
||||
/** call socket() to get a sd
|
||||
*
|
||||
*/
|
||||
virtual void open();
|
||||
|
||||
/** close the sd
|
||||
*
|
||||
*/
|
||||
virtual void close();
|
||||
|
||||
/** test if this socket is open
|
||||
*
|
||||
*/
|
||||
inline virtual const bool isOpen() const;
|
||||
|
||||
/** read a message from the socket
|
||||
*
|
||||
* wait for and return a message from the socket. The deafult timeout waits forever. Note that
|
||||
* eventhough struct timespec has nanosecond resolution, this method only has milisecond resolution.
|
||||
* @warning If you specify a timeout, the stream can be corrupted in certain
|
||||
* extreme circumstances. The circumstance: receiving a portion of the message
|
||||
* followed by a timeout. If the rest of the message is ever received, it
|
||||
* will be misinterpreted by the following read(). Symptom: The caller will
|
||||
* receive an incomplete ByteStream
|
||||
* (do try-catch around all ">>" operations to detect underflow). Mitigation:
|
||||
* the caller should not perform another read(). Caller should close the connection.
|
||||
* The behavior will be unpredictable and possibly fatal.
|
||||
* @note A fix is being reviewed but this is low-priority.
|
||||
*/
|
||||
virtual const SBS read(const struct timespec* timeout=0, bool* isTimeOut = NULL, Stats *stats = NULL) const;
|
||||
|
||||
/** write a message to the socket
|
||||
*
|
||||
* write a message to the socket
|
||||
*/
|
||||
virtual void write(const ByteStream& msg, Stats *stats = NULL);
|
||||
virtual void write_raw(const ByteStream& msg, Stats *stats = NULL) const;
|
||||
|
||||
/** this version of write takes ownership of the bytestream
|
||||
*/
|
||||
virtual void write(SBS msg, Stats *stats = NULL);
|
||||
|
||||
/** bind to a port
|
||||
*
|
||||
*/
|
||||
virtual void bind(const sockaddr* serv_addr);
|
||||
|
||||
/** listen for connections
|
||||
*
|
||||
*/
|
||||
virtual void listen(int backlog=5);
|
||||
|
||||
/** return an (accepted) IOSocket ready for I/O
|
||||
*
|
||||
*/
|
||||
virtual const IOSocket accept(const struct timespec* timeout=0);
|
||||
|
||||
/** connect to a server socket
|
||||
*
|
||||
*/
|
||||
virtual void connect(const sockaddr* serv_addr);
|
||||
|
||||
/** dynamically allocate a copy of this object
|
||||
*
|
||||
*/
|
||||
virtual Socket* clone() const;
|
||||
|
||||
/** get a string rep of the object
|
||||
*
|
||||
*/
|
||||
virtual const std::string toString() const;
|
||||
|
||||
/** set the connection timeout (in ms)
|
||||
*
|
||||
*/
|
||||
virtual void connectionTimeout(const struct ::timespec* timeout) { if (timeout) fConnectionTimeout = *timeout; }
|
||||
|
||||
/** set the connection protocol to be synchronous
|
||||
*
|
||||
*/
|
||||
virtual void syncProto(bool use) { fSyncProto = use; }
|
||||
|
||||
const int getConnectionNum() const { return fSocketParms.sd(); }
|
||||
|
||||
/* The caller needs to know when/if the remote closes the connection or sends data.
|
||||
* Returns 0 on timeout, 1 if there is data to read, 2 if the connection was dropped.
|
||||
* On error 3 is returned.
|
||||
*/
|
||||
static int pollConnection(int connectionNum, long msecs);
|
||||
|
||||
/** return the address as a string
|
||||
*
|
||||
*/
|
||||
virtual const std::string addr2String() const;
|
||||
|
||||
/** compare 2 addresses
|
||||
*
|
||||
*/
|
||||
virtual const bool isSameAddr(const Socket* rhs) const;
|
||||
|
||||
/** ping an ip address
|
||||
*
|
||||
*/
|
||||
EXPORT static int ping(const std::string& ipaddr, const struct timespec* timeout=0);
|
||||
|
||||
/*
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
protected:
|
||||
static const int KERR_ERESTARTSYS = 512;
|
||||
|
||||
void logIoError(const char* errMsg, int errNum) const;
|
||||
|
||||
/** Empty the stream up to the beginning of the next ByteStream.
|
||||
*
|
||||
* Reads until the beginning of the next ByteStream is found.
|
||||
* @param msecs An optional timeout value.
|
||||
* @param residual Pass in an array of at least 8 bytes, on return it will contain
|
||||
* the first bytes of the stream.
|
||||
* @param reslen On return, it will contain the # of bytes in residual.
|
||||
* @return true if the next byte in the stream is the beginning of a ByteStream,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool readToMagic(long msecs, bool* isTimeOut, Stats *stats) const;
|
||||
|
||||
void do_write(const ByteStream &msg, uint32_t magic, Stats *stats = NULL) const;
|
||||
ssize_t written(int fd, const uint8_t* ptr, size_t nbytes) const;
|
||||
|
||||
SocketParms fSocketParms; /// The socket parms
|
||||
size_t fBlocksize;
|
||||
sockaddr_in fSa;
|
||||
|
||||
// how long to wait for a connect() call to complete (in ms)
|
||||
struct ::timespec fConnectionTimeout;
|
||||
|
||||
// use sync proto
|
||||
bool fSyncProto;
|
||||
|
||||
/// The buffer used to scan for the ByteStream magic in the stream.
|
||||
mutable uint32_t fMagicBuffer;
|
||||
|
||||
private:
|
||||
void doCopy(const InetStreamSocket& rhs);
|
||||
};
|
||||
|
||||
inline const bool InetStreamSocket::isOpen() const { return (fSocketParms.sd() >= 0); }
|
||||
inline const SocketParms InetStreamSocket::socketParms() const { return fSocketParms; }
|
||||
inline void InetStreamSocket::socketParms(const SocketParms& socketParms) { fSocketParms = socketParms; }
|
||||
inline void InetStreamSocket::sa(const sockaddr* sa) { memcpy(&fSa, sa, sizeof(sockaddr_in)); }
|
||||
|
||||
/**
|
||||
* stream an InetStreamSocket rep to any ostream
|
||||
*/
|
||||
inline std::ostream& operator<<(std::ostream& os, const InetStreamSocket& rhs)
|
||||
{
|
||||
os << rhs.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif //MESSAGEQCPP_INETSTREAMSOCKET_H
|
||||
|
98
utils/messageqcpp/iosocket.cpp
Normal file
98
utils/messageqcpp/iosocket.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: iosocket.cpp 3632 2013-03-13 18:08:46Z pleblanc $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef _MSC_VER
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#define IOSOCKET_DLLEXPORT
|
||||
#include "iosocket.h"
|
||||
#undef IOSOCKET_DLLEXPORT
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
IOSocket::IOSocket(Socket* socket) :
|
||||
fSocket(socket), sockID(0)
|
||||
{
|
||||
memset(&fSa, 0, sizeof(fSa));
|
||||
}
|
||||
|
||||
IOSocket::~IOSocket()
|
||||
{
|
||||
delete fSocket;
|
||||
}
|
||||
|
||||
void IOSocket::doCopy(const IOSocket& rhs)
|
||||
{
|
||||
fSocket = rhs.fSocket->clone();
|
||||
fSa = rhs.fSa;
|
||||
sockID = rhs.sockID;
|
||||
}
|
||||
|
||||
IOSocket::IOSocket(const IOSocket& rhs)
|
||||
{
|
||||
doCopy(rhs);
|
||||
}
|
||||
|
||||
IOSocket& IOSocket::operator=(const IOSocket& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
delete fSocket;
|
||||
doCopy(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const string IOSocket::toString() const
|
||||
{
|
||||
#ifdef NOSSTREAM
|
||||
return "IOSocket";
|
||||
#else
|
||||
ostringstream oss;
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
SocketParms sp = fSocket->socketParms();
|
||||
const sockaddr_in* sinp = reinterpret_cast<const sockaddr_in*>(&fSa);
|
||||
oss << "IOSocket: sd: " << sp.sd() <<
|
||||
#ifndef _MSC_VER
|
||||
" inet: " << inet_ntop(AF_INET, &sinp->sin_addr, buf, INET_ADDRSTRLEN) <<
|
||||
#endif
|
||||
" port: " << ntohs(sinp->sin_port);
|
||||
return oss.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
226
utils/messageqcpp/iosocket.h
Normal file
226
utils/messageqcpp/iosocket.h
Normal file
@ -0,0 +1,226 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: iosocket.h 3632 2013-03-13 18:08:46Z pleblanc $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_IOSOCKET_H
|
||||
#define MESSAGEQCPP_IOSOCKET_H
|
||||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <sys/types.h>
|
||||
#include <ctime>
|
||||
#ifdef _MSC_VER
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#if __FreeBSD__
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include "socket.h"
|
||||
#include "socketparms.h"
|
||||
#include "bytestream.h"
|
||||
|
||||
class MessageQTestSuite;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxIOSOCKET_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace messageqcpp {
|
||||
class ServerSocket;
|
||||
|
||||
/** a socket capable of I/O
|
||||
*
|
||||
*/
|
||||
class IOSocket
|
||||
{
|
||||
public:
|
||||
|
||||
/** ctor
|
||||
*
|
||||
*/
|
||||
EXPORT explicit IOSocket(Socket* socket=0);
|
||||
|
||||
/** copy ctor
|
||||
*
|
||||
*/
|
||||
EXPORT IOSocket(const IOSocket& rhs);
|
||||
|
||||
/** assign op
|
||||
*
|
||||
*/
|
||||
EXPORT IOSocket& operator=(const IOSocket& rhs);
|
||||
|
||||
/** dtor
|
||||
*
|
||||
*/
|
||||
EXPORT virtual ~IOSocket();
|
||||
|
||||
/** read a ByteStream from this socket
|
||||
*
|
||||
* This socket needs to be connected first. Will throw runtime_error on I/O error. Caller should
|
||||
* call close() method if exception is thrown.
|
||||
*/
|
||||
virtual const SBS read(const struct timespec* timeout=0, bool* isTimeOut = NULL, Stats *stats = NULL) const;
|
||||
|
||||
/** write a ByteStream to this socket
|
||||
*
|
||||
* This socket needs to be connected first. Will throw runtime_error on I/O error. Caller should
|
||||
* call close() method if exception is thrown.
|
||||
*/
|
||||
EXPORT virtual void write(const ByteStream& msg, Stats *stats = NULL) const;
|
||||
EXPORT virtual void write_raw(const ByteStream& msg, Stats *stats = NULL) const;
|
||||
EXPORT virtual void write(SBS msg, Stats *stats = NULL) const;
|
||||
|
||||
/** access the sockaddr member
|
||||
*/
|
||||
inline virtual const sockaddr sa() const;
|
||||
|
||||
/** modify the sockaddr member
|
||||
*/
|
||||
inline virtual void sa(const sockaddr* sa);
|
||||
|
||||
/** open the socket
|
||||
*
|
||||
*/
|
||||
inline virtual void open();
|
||||
|
||||
/** close the socket
|
||||
*
|
||||
*/
|
||||
inline virtual void close();
|
||||
|
||||
/** test if the socket is open
|
||||
*
|
||||
*/
|
||||
inline virtual const bool isOpen() const;
|
||||
|
||||
/** get the socket params
|
||||
*
|
||||
*/
|
||||
inline virtual const SocketParms socketParms() const;
|
||||
|
||||
/** set the socket params
|
||||
*
|
||||
*/
|
||||
inline virtual void socketParms(const SocketParms& socketParms);
|
||||
|
||||
/** set the socket implementation
|
||||
*
|
||||
* Install a socket implementation that meets the Socket interface
|
||||
*/
|
||||
EXPORT virtual void setSocketImpl(Socket* socket);
|
||||
|
||||
/** get a string rep of the IOSocket
|
||||
*
|
||||
*/
|
||||
EXPORT virtual const std::string toString() const;
|
||||
|
||||
/** syncProto() forwarder for inherited classes
|
||||
*
|
||||
*/
|
||||
EXPORT virtual void syncProto(bool use) { fSocket->syncProto(use); }
|
||||
|
||||
EXPORT virtual const int getConnectionNum() const;
|
||||
|
||||
// Debug
|
||||
EXPORT void setSockID(uint32_t id) {sockID = id;}
|
||||
EXPORT uint32_t getSockID() {return sockID;}
|
||||
/*
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
/**
|
||||
* @brief return the address as a string
|
||||
*/
|
||||
virtual const std::string addr2String() const { return fSocket->addr2String(); }
|
||||
|
||||
/**
|
||||
* @brief compare 2 addresses
|
||||
*/
|
||||
virtual const bool isSameAddr(const IOSocket *rhs) const { return fSocket->isSameAddr(rhs->fSocket); }
|
||||
|
||||
/** connect() forwarder for inherited classes
|
||||
*
|
||||
*/
|
||||
virtual void connect(const struct sockaddr* serv_addr) { fSocket->connect(serv_addr); }
|
||||
|
||||
/** connectionTimeout() forwarder for inherited classes
|
||||
*
|
||||
*/
|
||||
virtual void connectionTimeout(const struct timespec* timeout) { fSocket->connectionTimeout(timeout); }
|
||||
|
||||
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
private:
|
||||
void doCopy(const IOSocket& rhs);
|
||||
|
||||
Socket* fSocket;
|
||||
sockaddr fSa;
|
||||
uint32_t sockID; // For debug purposes
|
||||
};
|
||||
|
||||
|
||||
inline const sockaddr IOSocket::sa() const { return fSa; }
|
||||
inline void IOSocket::sa(const sockaddr* sa)
|
||||
{ fSa = *sa;
|
||||
if (fSocket)
|
||||
fSocket->sa( sa ); }
|
||||
inline void IOSocket::open() { idbassert(fSocket); fSocket->open(); }
|
||||
//RJD: changing close() to simply bail on null fSocket. I'm not really sure what's best here, but this is probably
|
||||
// better that asserting...
|
||||
inline void IOSocket::close() { if (fSocket) fSocket->close(); }
|
||||
inline const bool IOSocket::isOpen() const { return (fSocket && fSocket->isOpen()); }
|
||||
inline const SBS IOSocket::read(const struct timespec* timeout, bool* isTimeOut, Stats *stats) const
|
||||
{ idbassert(fSocket); return fSocket->read(timeout, isTimeOut, stats); }
|
||||
inline void IOSocket::write(const ByteStream& msg, Stats *stats) const { idbassert(fSocket); fSocket->write(msg, stats); }
|
||||
inline void IOSocket::write_raw(const ByteStream& msg, Stats *stats) const { idbassert(fSocket); fSocket->write_raw(msg, stats); }
|
||||
inline void IOSocket::write(SBS msg, Stats *stats) const { idbassert(fSocket); fSocket->write(msg, stats); }
|
||||
inline const SocketParms IOSocket::socketParms() const { idbassert(fSocket); return fSocket->socketParms(); }
|
||||
inline void IOSocket::socketParms(const SocketParms& socketParms) { idbassert(fSocket); fSocket->socketParms(socketParms); }
|
||||
inline void IOSocket::setSocketImpl(Socket* socket) { delete fSocket; fSocket = socket; }
|
||||
inline const int IOSocket::getConnectionNum() const { return fSocket->getConnectionNum(); }
|
||||
|
||||
/**
|
||||
* stream an IOSocket rep to any ostream
|
||||
*/
|
||||
inline std::ostream& operator<<(std::ostream& os, const IOSocket& rhs)
|
||||
{
|
||||
os << rhs.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif //MESSAGEQCPP_IOSOCKET_H
|
||||
|
330
utils/messageqcpp/messagequeue.cpp
Normal file
330
utils/messageqcpp/messagequeue.cpp
Normal file
@ -0,0 +1,330 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: messagequeue.cpp 3632 2013-03-13 18:08:46Z pleblanc $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef _MSC_VER
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "configcpp.h"
|
||||
using namespace config;
|
||||
|
||||
#include "bytestream.h"
|
||||
#include "inetstreamsocket.h"
|
||||
#ifndef SKIP_IDB_COMPRESSION
|
||||
#include "compressed_iss.h"
|
||||
#endif
|
||||
#include "socketclosed.h"
|
||||
|
||||
#define MESSAGEQUEUE_DLLEXPORT
|
||||
#include "messagequeue.h"
|
||||
#undef MESSAGEQUEUE_DLLEXPORT
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
void MessageQueueServer::setup(size_t blocksize, int backlog, bool syncProto)
|
||||
{
|
||||
string thisEndPortStr;
|
||||
|
||||
thisEndPortStr = fConfig->getConfig(fThisEnd, "Port");
|
||||
uint16_t port;
|
||||
|
||||
if (thisEndPortStr.length() == 0 || (port = static_cast<uint16_t>(strtol(thisEndPortStr.c_str(), 0, 0))) == 0)
|
||||
{
|
||||
string msg = "MessageQueueServer::MessageQueueServer: config error: Invalid/Missing Port "
|
||||
"attribute for " + fThisEnd;
|
||||
throw runtime_error(msg);
|
||||
}
|
||||
|
||||
in_addr listenAddr;
|
||||
listenAddr.s_addr = INADDR_ANY;
|
||||
string listenAddrStr = fConfig->getConfig(fThisEnd, "ListenAddr");
|
||||
if (listenAddrStr.length() > 0)
|
||||
{
|
||||
struct in_addr la;
|
||||
if (inet_aton(listenAddrStr.c_str(), &la) != 0)
|
||||
listenAddr = la;
|
||||
}
|
||||
|
||||
memset(&fServ_addr, 0, sizeof(fServ_addr));
|
||||
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
|
||||
sinp->sin_family = AF_INET;
|
||||
sinp->sin_addr.s_addr = listenAddr.s_addr;
|
||||
sinp->sin_port = htons(port);
|
||||
|
||||
#ifdef SKIP_IDB_COMPRESSION
|
||||
fListenSock.setSocketImpl(new InetStreamSocket(blocksize));
|
||||
#else
|
||||
fListenSock.setSocketImpl(new CompressedInetStreamSocket());
|
||||
#endif
|
||||
fListenSock.syncProto(syncProto);
|
||||
fListenSock.open();
|
||||
fListenSock.bind(&fServ_addr);
|
||||
fListenSock.listen(backlog);
|
||||
|
||||
#ifdef SKIP_IDB_COMPRESSION
|
||||
fClientSock.setSocketImpl(new InetStreamSocket(blocksize));
|
||||
#else
|
||||
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
|
||||
#endif
|
||||
fClientSock.syncProto(syncProto);
|
||||
}
|
||||
|
||||
MessageQueueServer::MessageQueueServer(const string& thisEnd, const string& config,
|
||||
size_t blocksize, int backlog, bool syncProto) :
|
||||
fThisEnd(thisEnd),
|
||||
fConfig(Config::makeConfig(config)),
|
||||
fLogger(31)
|
||||
{
|
||||
setup(blocksize, backlog, syncProto);
|
||||
}
|
||||
|
||||
MessageQueueServer::MessageQueueServer(const string& thisEnd, Config* config,
|
||||
size_t blocksize, int backlog, bool syncProto) :
|
||||
fThisEnd(thisEnd),
|
||||
fConfig(config),
|
||||
fLogger(31)
|
||||
{
|
||||
if (fConfig == 0)
|
||||
fConfig = Config::makeConfig();
|
||||
|
||||
setup(blocksize, backlog, syncProto);
|
||||
}
|
||||
|
||||
MessageQueueServer::~MessageQueueServer()
|
||||
{
|
||||
fClientSock.close();
|
||||
fListenSock.close();
|
||||
}
|
||||
|
||||
const IOSocket MessageQueueServer::accept(const struct timespec* timeout) const
|
||||
{
|
||||
return fListenSock.accept(timeout);
|
||||
}
|
||||
|
||||
void MessageQueueServer::syncProto(bool use)
|
||||
{
|
||||
fListenSock.syncProto(use);
|
||||
fClientSock.syncProto(use);
|
||||
}
|
||||
|
||||
MessageQueueClient::~MessageQueueClient()
|
||||
{
|
||||
fClientSock.close();
|
||||
}
|
||||
|
||||
void MessageQueueClient::shutdown()
|
||||
{
|
||||
fClientSock.close();
|
||||
}
|
||||
|
||||
void MessageQueueClient::setup(bool syncProto)
|
||||
{
|
||||
string otherEndIPStr;
|
||||
string otherEndPortStr;
|
||||
uint16_t port;
|
||||
|
||||
otherEndIPStr = fConfig->getConfig(fOtherEnd, "IPAddr");
|
||||
otherEndPortStr = fConfig->getConfig(fOtherEnd, "Port");
|
||||
|
||||
if (otherEndIPStr.length() == 0) otherEndIPStr = "127.0.0.1";
|
||||
|
||||
if (otherEndPortStr.length() == 0 || (port = static_cast<uint16_t>(strtol(otherEndPortStr.c_str(), 0, 0))) == 0)
|
||||
{
|
||||
string msg = "MessageQueueClient::MessageQueueClient: config error: Invalid/Missing Port attribute";
|
||||
throw runtime_error(msg);
|
||||
}
|
||||
|
||||
memset(&fServ_addr, 0, sizeof(fServ_addr));
|
||||
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
|
||||
sinp->sin_family = AF_INET;
|
||||
sinp->sin_port = htons(port);
|
||||
sinp->sin_addr.s_addr = inet_addr(otherEndIPStr.c_str());
|
||||
|
||||
#ifdef SKIP_IDB_COMPRESSION
|
||||
fClientSock.setSocketImpl(new InetStreamSocket());
|
||||
#else
|
||||
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
|
||||
#endif
|
||||
fClientSock.syncProto(syncProto);
|
||||
fClientSock.sa(&fServ_addr);
|
||||
}
|
||||
|
||||
MessageQueueClient::MessageQueueClient(const string& otherEnd, const string& config, bool syncProto) :
|
||||
fOtherEnd(otherEnd), fConfig(Config::makeConfig(config)), fLogger(31), fIsAvailable(true)
|
||||
{
|
||||
setup(syncProto);
|
||||
}
|
||||
|
||||
MessageQueueClient::MessageQueueClient(const string& otherEnd, Config* config, bool syncProto) :
|
||||
fOtherEnd(otherEnd), fConfig(config), fLogger(31), fIsAvailable(true)
|
||||
{
|
||||
if (fConfig == 0)
|
||||
fConfig = Config::makeConfig();
|
||||
|
||||
setup(syncProto);
|
||||
}
|
||||
|
||||
MessageQueueClient::MessageQueueClient(const string& ip, uint16_t port, bool syncProto) :
|
||||
fLogger(31), fIsAvailable(true)
|
||||
{
|
||||
memset(&fServ_addr, 0, sizeof(fServ_addr));
|
||||
sockaddr_in* sinp = reinterpret_cast<sockaddr_in*>(&fServ_addr);
|
||||
sinp->sin_family = AF_INET;
|
||||
sinp->sin_port = htons(port);
|
||||
sinp->sin_addr.s_addr = inet_addr(ip.c_str());
|
||||
|
||||
#ifdef SKIP_IDB_COMPRESSION
|
||||
fClientSock.setSocketImpl(new InetStreamSocket());
|
||||
#else
|
||||
fClientSock.setSocketImpl(new CompressedInetStreamSocket());
|
||||
#endif
|
||||
fClientSock.syncProto(syncProto);
|
||||
fClientSock.sa(&fServ_addr);
|
||||
}
|
||||
|
||||
const SBS MessageQueueClient::read(const struct timespec* timeout, bool* isTimeOut, Stats *stats) const
|
||||
{
|
||||
if (!fClientSock.isOpen())
|
||||
{
|
||||
fClientSock.open();
|
||||
try {
|
||||
fClientSock.connect(&fServ_addr);
|
||||
}
|
||||
catch (...) {
|
||||
fClientSock.close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
SBS res;
|
||||
try
|
||||
{
|
||||
res = fClientSock.read(timeout, isTimeOut, stats);
|
||||
}
|
||||
catch (runtime_error& re)
|
||||
{
|
||||
// This is an I/O error from IOSocket::read()
|
||||
// cerr << "MessageQueueClient::read: close socket for " << re.what() << endl;
|
||||
logging::Message::Args args;
|
||||
logging::LoggingID li(31);
|
||||
args.add("Client read close socket for");
|
||||
args.add(re.what());
|
||||
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
|
||||
fClientSock.close();
|
||||
throw;
|
||||
}
|
||||
catch (SocketClosed &e) {
|
||||
// cerr << "MessageQueueClient::read: close socket for " << e.what() << endl;
|
||||
logging::Message::Args args;
|
||||
logging::LoggingID li(31);
|
||||
args.add("Client read close socket for");
|
||||
args.add(e.what());
|
||||
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
|
||||
fClientSock.close();
|
||||
throw;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void MessageQueueClient::write(const ByteStream& msg, const struct timespec* timeout, Stats *stats) const
|
||||
{
|
||||
if (!fClientSock.isOpen())
|
||||
{
|
||||
fClientSock.open();
|
||||
try {
|
||||
fClientSock.connectionTimeout(timeout);
|
||||
fClientSock.connect(&fServ_addr);
|
||||
}
|
||||
catch(...) {
|
||||
fClientSock.close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
fClientSock.write(msg, stats);
|
||||
}
|
||||
catch (runtime_error &e) {
|
||||
try
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "MessageQueueClient::write: error writing " << msg.length() << " bytes to "
|
||||
<< fClientSock << ". Socket error was " << e.what() << endl;
|
||||
// cerr << oss.str() << endl;
|
||||
logging::Message::Args args;
|
||||
logging::LoggingID li(31);
|
||||
args.add(oss.str());
|
||||
fLogger.logMessage(logging::LOG_TYPE_WARNING, logging::M0000, args, li);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
fClientSock.close();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
bool MessageQueueClient::connect() const
|
||||
{
|
||||
if (!fClientSock.isOpen())
|
||||
{
|
||||
fClientSock.open();
|
||||
|
||||
try {
|
||||
fClientSock.connect(&fServ_addr);
|
||||
}
|
||||
catch (runtime_error& re) {
|
||||
string what = re.what();
|
||||
if (what.find("Connection refused") != string::npos)
|
||||
{
|
||||
try {
|
||||
fClientSock.close();
|
||||
}
|
||||
catch (...) {
|
||||
}
|
||||
}
|
||||
else
|
||||
throw;
|
||||
}
|
||||
catch (...) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return fClientSock.isOpen();
|
||||
}
|
||||
|
||||
}//namespace messageqcpp
|
294
utils/messageqcpp/messagequeue.h
Normal file
294
utils/messageqcpp/messagequeue.h
Normal file
@ -0,0 +1,294 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/******************************************************************************************
|
||||
* $Id: messagequeue.h 3632 2013-03-13 18:08:46Z pleblanc $
|
||||
*
|
||||
*
|
||||
******************************************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_MESSAGEQUEUE_H
|
||||
#define MESSAGEQCPP_MESSAGEQUEUE_H
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef _MSC_VER
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "serversocket.h"
|
||||
#include "iosocket.h"
|
||||
#include "bytestream.h"
|
||||
#include "logger.h"
|
||||
namespace config
|
||||
{
|
||||
class Config;
|
||||
}
|
||||
|
||||
class MessageQTestSuite;
|
||||
|
||||
#if defined(_MSC_VER) && defined(xxxMESSAGEQUEUE_DLLEXPORT)
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define EXPORT
|
||||
#endif
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
/**
|
||||
* @brief a message queue server
|
||||
* This class can recieve (and send) messages
|
||||
*
|
||||
* MessageQueueServer looks in the config file specified by cfile for an entry like:
|
||||
* @code
|
||||
* <thisEnd>
|
||||
* <IPAddr>127.0.0.1</IPAddr>
|
||||
* <Port>7601</Port>
|
||||
* </thisEnd>
|
||||
* @endcode
|
||||
* and binds/listens/accepts on the port specified. It ignores the IPAddr setting.
|
||||
*
|
||||
* Users of this class need to decide whether they want to use it in a single-threaded-
|
||||
* compatible (message-at-a-time) mode or in a multi-threaded-compatible (connection-per-
|
||||
* thread) mode. For the former, read() and write() are available, and accept() cannot be
|
||||
* used. In the latter, the opposite applies.
|
||||
*/
|
||||
class MessageQueueServer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief construct a server queue for thisEnd
|
||||
*
|
||||
* construct a server queue for thisEnd. Optionally specify a Config object to use.
|
||||
*/
|
||||
EXPORT explicit MessageQueueServer(const std::string& thisEnd, config::Config* config=0,
|
||||
size_t blocksize=ByteStream::BlockSize, int backlog=5, bool syncProto=true);
|
||||
|
||||
/**
|
||||
* @brief construct a server queue for thisEnd
|
||||
*
|
||||
* construct a server queue for thisEnd, specifying the name of a config file to use.
|
||||
*/
|
||||
EXPORT MessageQueueServer(const std::string& thisEnd, const std::string& config,
|
||||
size_t blocksize=ByteStream::BlockSize, int backlog=5, bool syncProto=true);
|
||||
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
EXPORT ~MessageQueueServer();
|
||||
//
|
||||
/**
|
||||
* @brief wait for a connection and return an IOSocket
|
||||
*
|
||||
* This method can be used by a main thread to wait for an incoming connection. The IOSocket
|
||||
* that is returned can be passed to a thread to handle the socket connection. The main thread
|
||||
* is then free to wait again for another connection. The IOSocket is already open and ready for
|
||||
* read() and/or write(). The caller is responsible for calling close() when it is done.
|
||||
*/
|
||||
EXPORT const IOSocket accept(const struct timespec* timeout=0) const;
|
||||
|
||||
/**
|
||||
* @brief get a mutable pointer to the client IOSocket
|
||||
*/
|
||||
inline IOSocket& clientSock() const;
|
||||
|
||||
/**
|
||||
* @brief set the sync proto
|
||||
*/
|
||||
EXPORT void syncProto(bool use);
|
||||
|
||||
/**
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
private:
|
||||
/** copy ctor
|
||||
*
|
||||
*/
|
||||
MessageQueueServer(const MessageQueueServer& rhs);
|
||||
|
||||
/** assign op
|
||||
*
|
||||
*/
|
||||
MessageQueueServer& operator=(const MessageQueueServer& rhs);
|
||||
|
||||
/** ctor helper
|
||||
*
|
||||
*/
|
||||
void setup(size_t blocksize, int backlog, bool syncProto);
|
||||
|
||||
std::string fThisEnd; /// the process name for this process
|
||||
struct sockaddr fServ_addr; /// the addr of the server (may be this process)
|
||||
config::Config* fConfig; /// config file has the IP addrs and port numbers
|
||||
mutable ServerSocket fListenSock; /// the socket the server listens on for new connections
|
||||
mutable IOSocket fClientSock; /// the socket connected to a client
|
||||
|
||||
mutable logging::Logger fLogger;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief a message queue client
|
||||
* This class can send (and recieve) messages
|
||||
*
|
||||
* MessageQueueClient looks in the config file specified by cfile for an entry like:
|
||||
* @code
|
||||
* <otherEnd>
|
||||
* <IPAddr>127.0.0.1</IPAddr>
|
||||
* <Port>7601</Port>
|
||||
* </otherEnd>
|
||||
* @endcode
|
||||
* and connects to the ipaddr/port specified. It does a "lazy" connect in that it doesn't
|
||||
* actually connect until read() is invoked the first time.
|
||||
*/
|
||||
class MessageQueueClient
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief construct a queue to otherEnd
|
||||
*
|
||||
* construct a queue from this process to otherEnd. Optionally specify a Config object to use.
|
||||
*/
|
||||
EXPORT explicit MessageQueueClient(const std::string& otherEnd, config::Config* config=0, bool syncProto=true);
|
||||
|
||||
/**
|
||||
* @brief construct a queue to otherEnd
|
||||
*
|
||||
* construct a queue from this process to otherEnd, specifying the name of a config file to use.
|
||||
*/
|
||||
EXPORT explicit MessageQueueClient(const std::string& otherEnd, const std::string& config, bool syncProto=true);
|
||||
|
||||
/**
|
||||
* @brief construct a queue to otherEnd
|
||||
*
|
||||
* construct a queue from this process to otherEnd on the given IP and Port.
|
||||
*/
|
||||
EXPORT explicit MessageQueueClient(const std::string& ip, uint16_t port, bool syncProto=true);
|
||||
|
||||
|
||||
/**
|
||||
* @brief destructor
|
||||
*
|
||||
* calls shutdown() method.
|
||||
*/
|
||||
EXPORT ~MessageQueueClient();
|
||||
|
||||
/**
|
||||
* @brief read a message from the queue
|
||||
*
|
||||
* wait for and return a message from otherEnd. The deafult timeout waits forever. Note that
|
||||
* eventhough struct timespec has nanosecond resolution, this method only has milisecond resolution.
|
||||
*/
|
||||
EXPORT const SBS read(const struct timespec* timeout=0, bool* isTimeOut = NULL, Stats *stats = NULL) const;
|
||||
|
||||
/**
|
||||
* @brief write a message to the queue
|
||||
*
|
||||
* write a message to otherEnd. If the socket is not open, the timeout parm (in ms) will be used
|
||||
* to establish a sync connection w/ the server
|
||||
*/
|
||||
EXPORT void write(const ByteStream& msg, const struct timespec* timeout=0, Stats *stats = NULL) const;
|
||||
|
||||
/**
|
||||
* @brief shutdown the connection to the server
|
||||
*
|
||||
* indicate to the class that the user is done with the socket
|
||||
* and the other class methods won't be used.
|
||||
*/
|
||||
EXPORT void shutdown();
|
||||
|
||||
/**
|
||||
* @brief connect to the server. Returns true if connection was successful.
|
||||
*
|
||||
* read() and write() automatically connect, but this method can be used to verify a server is listening
|
||||
* before that.
|
||||
*/
|
||||
EXPORT bool connect() const;
|
||||
|
||||
/**
|
||||
* @brief accessors and mutators
|
||||
*/
|
||||
EXPORT const sockaddr serv_addr() const { return fServ_addr; }
|
||||
EXPORT const std::string otherEnd() const { return fOtherEnd; }
|
||||
EXPORT const bool isAvailable() const { return fIsAvailable; }
|
||||
EXPORT void isAvailable (const bool isAvailable) { fIsAvailable = isAvailable; }
|
||||
EXPORT const std::string moduleName() const {return fModuleName;}
|
||||
EXPORT void moduleName(const std::string& moduleName) {fModuleName = moduleName;}
|
||||
|
||||
/**
|
||||
* @brief set the sync proto
|
||||
*/
|
||||
inline void syncProto(bool use);
|
||||
|
||||
/**
|
||||
* @brief return the address as a string
|
||||
*/
|
||||
inline const std::string addr2String() const;
|
||||
|
||||
/**
|
||||
* @brief compare the addresses of 2 MessageQueueClient
|
||||
*/
|
||||
inline const bool isSameAddr(const MessageQueueClient& rhs) const;
|
||||
|
||||
/*
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
private:
|
||||
/** copy ctor
|
||||
*
|
||||
*/
|
||||
MessageQueueClient(const MessageQueueClient& rhs);
|
||||
|
||||
/** assign op
|
||||
*
|
||||
*/
|
||||
MessageQueueClient& operator=(const MessageQueueClient& rhs);
|
||||
|
||||
/** ctor helper
|
||||
*
|
||||
*/
|
||||
void setup(bool syncProto);
|
||||
|
||||
std::string fOtherEnd; /// the process name for this process
|
||||
struct sockaddr fServ_addr; /// the addr of the server (may be this process)
|
||||
config::Config* fConfig; /// config file has the IP addrs and port numbers
|
||||
mutable IOSocket fClientSock; /// the socket to communicate with the server
|
||||
mutable logging::Logger fLogger;
|
||||
bool fIsAvailable;
|
||||
std::string fModuleName;
|
||||
};
|
||||
|
||||
inline IOSocket& MessageQueueServer::clientSock() const { return fClientSock; }
|
||||
inline const std::string MessageQueueClient::addr2String() const { return fClientSock.addr2String(); }
|
||||
inline const bool MessageQueueClient::isSameAddr(const MessageQueueClient& rhs) const
|
||||
{ return fClientSock.isSameAddr(&rhs.fClientSock); }
|
||||
inline void MessageQueueClient::syncProto(bool use) { fClientSock.syncProto(use); }
|
||||
|
||||
}
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif //MESSAGEQCPP_MESSAGEQUEUE_H
|
||||
// vim:ts=4 sw=4:
|
||||
|
4704
utils/messageqcpp/messagequeue.xmi
Normal file
4704
utils/messageqcpp/messagequeue.xmi
Normal file
File diff suppressed because it is too large
Load Diff
59
utils/messageqcpp/serializeable.h
Normal file
59
utils/messageqcpp/serializeable.h
Normal file
@ -0,0 +1,59 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/******************************************************************************
|
||||
* $Id$
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/** @file
|
||||
* class XXX interface
|
||||
*/
|
||||
|
||||
#ifndef _SERIALIZEABLE_H_
|
||||
#define _SERIALIZEABLE_H_
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
class ByteStream;
|
||||
|
||||
/** This is an abstract class that defines the interface ByteStream will
|
||||
use to serialize and deserialize your class.
|
||||
|
||||
To serialize an object, do 'ByteStream << object'
|
||||
To deserialize an object, instantiate one of its type and do 'ByteStream >> object'
|
||||
*/
|
||||
|
||||
class Serializeable {
|
||||
public:
|
||||
/** dtor
|
||||
*
|
||||
*/
|
||||
virtual ~Serializeable() { };
|
||||
/** serialize interface
|
||||
*
|
||||
*/
|
||||
virtual void serialize(ByteStream&) const = 0;
|
||||
/** deserialize interface
|
||||
*
|
||||
*/
|
||||
virtual void deserialize(ByteStream&) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
140
utils/messageqcpp/serversocket.h
Normal file
140
utils/messageqcpp/serversocket.h
Normal file
@ -0,0 +1,140 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: serversocket.h 3495 2013-01-21 14:09:51Z rdempsey $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_SERVERSOCKET_H
|
||||
#define MESSAGEQCPP_SERVERSOCKET_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef _MSC_VER
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
class MessageQTestSuite;
|
||||
|
||||
#include "socket.h"
|
||||
#include "iosocket.h"
|
||||
|
||||
namespace messageqcpp {
|
||||
class SocketParms;
|
||||
|
||||
/** a class capable of acting as a server listen socket
|
||||
*
|
||||
*/
|
||||
class ServerSocket
|
||||
{
|
||||
public:
|
||||
|
||||
/** ctor
|
||||
*
|
||||
*/
|
||||
explicit ServerSocket(Socket* socket=0) : fSocket(socket) {}
|
||||
|
||||
/** dtor
|
||||
*
|
||||
*/
|
||||
virtual ~ServerSocket() { delete fSocket; }
|
||||
|
||||
/** bind to an port
|
||||
*
|
||||
* bind this ServerSocket to the address/port specified in serv_addr
|
||||
*/
|
||||
inline virtual void bind(const struct sockaddr* serv_addr);
|
||||
|
||||
/** setup to listen for incoming connections
|
||||
*
|
||||
*/
|
||||
inline virtual void listen(int backlog=5);
|
||||
|
||||
/** accept an incoming connection
|
||||
*
|
||||
* accepts a new incoming connection and returns an IOSocket to communicate over
|
||||
*/
|
||||
inline virtual const IOSocket accept(const struct timespec* timeout=0);
|
||||
|
||||
/** open the socket
|
||||
*
|
||||
*/
|
||||
inline virtual void open();
|
||||
|
||||
/** close the socket
|
||||
*
|
||||
*/
|
||||
inline virtual void close();
|
||||
|
||||
/** test if the socket is open
|
||||
*
|
||||
*/
|
||||
inline virtual bool isOpen() const;
|
||||
|
||||
/** get the socket params
|
||||
*
|
||||
*/
|
||||
inline virtual const SocketParms socketParms() const;
|
||||
|
||||
/** set the socket params
|
||||
*
|
||||
*/
|
||||
inline virtual void socketParms(const SocketParms& socketParms);
|
||||
|
||||
/** set the socket implementation
|
||||
*
|
||||
* Install a socket implementation that meets the Socket interface
|
||||
*/
|
||||
inline virtual void setSocketImpl(Socket* socket);
|
||||
|
||||
/** set the socket sync proto
|
||||
*
|
||||
*/
|
||||
inline virtual void syncProto(bool use);
|
||||
|
||||
/*
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
private:
|
||||
ServerSocket(const ServerSocket& rhs);
|
||||
ServerSocket& operator=(const ServerSocket& rhs);
|
||||
|
||||
Socket* fSocket;
|
||||
};
|
||||
|
||||
inline void ServerSocket::bind(const struct sockaddr* serv_addr) { fSocket->bind(serv_addr); }
|
||||
inline void ServerSocket::listen(int backlog) { fSocket->listen(backlog); }
|
||||
inline const IOSocket ServerSocket::accept(const struct timespec* timeout) { return fSocket->accept(timeout); }
|
||||
inline void ServerSocket::open() { fSocket->open(); }
|
||||
inline void ServerSocket::close() { fSocket->close(); }
|
||||
inline bool ServerSocket::isOpen() const { return fSocket->isOpen(); }
|
||||
inline const SocketParms ServerSocket::socketParms() const { return fSocket->socketParms(); }
|
||||
inline void ServerSocket::socketParms(const SocketParms& socketParms) { fSocket->socketParms(socketParms); }
|
||||
inline void ServerSocket::setSocketImpl(Socket* socket) { delete fSocket; fSocket = socket; }
|
||||
inline void ServerSocket::syncProto(bool use) { fSocket->syncProto(use); }
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
||||
#endif //MESSAGEQCPP_SERVERSOCKET_H
|
||||
|
173
utils/messageqcpp/socket.h
Normal file
173
utils/messageqcpp/socket.h
Normal file
@ -0,0 +1,173 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: socket.h 3633 2013-03-13 20:50:23Z pleblanc $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_SOCKET_H
|
||||
#define MESSAGEQCPP_SOCKET_H
|
||||
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "bytestream.h"
|
||||
|
||||
class MessageQTestSuite;
|
||||
|
||||
namespace messageqcpp
|
||||
{
|
||||
class IOSocket;
|
||||
class SocketParms;
|
||||
|
||||
|
||||
// Might want to expand on this / derive from it to include things like uncompressed
|
||||
// data size, etc...
|
||||
class Stats
|
||||
{
|
||||
public:
|
||||
Stats() : data_sent(0), data_recvd(0)
|
||||
{ }
|
||||
virtual ~Stats() { }
|
||||
virtual uint64_t dataSent() { return data_sent; }
|
||||
virtual uint64_t dataRecvd() { return data_recvd; }
|
||||
virtual void dataSent(uint64_t amt) { data_sent += amt; }
|
||||
virtual void dataRecvd(uint64_t amt) { data_recvd += amt; }
|
||||
private:
|
||||
uint64_t data_sent;
|
||||
uint64_t data_recvd;
|
||||
};
|
||||
|
||||
/** an abstract socket class interface
|
||||
*
|
||||
*/
|
||||
class Socket
|
||||
{
|
||||
public:
|
||||
/** dtor
|
||||
*
|
||||
*/
|
||||
virtual ~Socket() {}
|
||||
|
||||
/** open the socket
|
||||
*
|
||||
*/
|
||||
virtual void open() = 0;
|
||||
|
||||
/** read a message from the socket
|
||||
*
|
||||
* wait for and return a message from the socket. The deafult timeout waits forever. Note that
|
||||
* eventhough struct timespec has nanosecond resolution, this method only has millisecond resolution.
|
||||
*/
|
||||
virtual const SBS read(const struct timespec* timeout=0, bool* isTimeOut = NULL, Stats *stats = NULL) const = 0;
|
||||
|
||||
/** write a message to the socket
|
||||
*
|
||||
* write a message to the socket
|
||||
*/
|
||||
virtual void write(const ByteStream& msg, Stats *stats = NULL) = 0;
|
||||
virtual void write_raw(const ByteStream& msg, Stats *stats = NULL) const = 0;
|
||||
virtual void write(SBS msg, Stats *stats = NULL) = 0;
|
||||
|
||||
/** close the socket
|
||||
*
|
||||
*/
|
||||
virtual void close() = 0;
|
||||
|
||||
/** bind to a port
|
||||
*
|
||||
*/
|
||||
virtual void bind(const struct sockaddr* serv_addr) = 0;
|
||||
|
||||
/** listen for connections
|
||||
*
|
||||
*/
|
||||
virtual void listen(int backlog=5) = 0;
|
||||
|
||||
/** return an (accepted) IOSocket ready for I/O
|
||||
*
|
||||
*/
|
||||
virtual const IOSocket accept(const struct timespec* timeout=0) = 0;
|
||||
|
||||
/** connect to a server socket
|
||||
*
|
||||
*/
|
||||
virtual void connect(const sockaddr* serv_addr) = 0;
|
||||
|
||||
/** test if this socket is open
|
||||
*
|
||||
*/
|
||||
virtual const bool isOpen() const = 0;
|
||||
|
||||
/** get the SocketParms
|
||||
*
|
||||
*/
|
||||
virtual const SocketParms socketParms() const = 0;
|
||||
|
||||
/** set the SocketParms
|
||||
*
|
||||
*/
|
||||
virtual void socketParms(const SocketParms& socketParms) = 0;
|
||||
|
||||
/** set the sockaddr struct
|
||||
*
|
||||
*/
|
||||
virtual void sa(const sockaddr* sa) = 0;
|
||||
|
||||
/** dynamically allocate a copy of this object
|
||||
*
|
||||
*/
|
||||
virtual Socket* clone() const = 0;
|
||||
|
||||
/** set the connection timeout (in ms)
|
||||
*
|
||||
*/
|
||||
virtual void connectionTimeout(const struct ::timespec* timeout) = 0;
|
||||
|
||||
/** set the connection protocol to be synchronous
|
||||
*
|
||||
*/
|
||||
virtual void syncProto(bool use) = 0;
|
||||
|
||||
virtual const int getConnectionNum() const = 0;
|
||||
|
||||
/** return the address as a string
|
||||
*
|
||||
*/
|
||||
virtual const std::string addr2String() const = 0;
|
||||
|
||||
/** compare 2 addresses
|
||||
*
|
||||
*/
|
||||
virtual const bool isSameAddr(const Socket* rhs) const = 0;
|
||||
|
||||
/*
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
||||
#endif //MESSAGEQCPP_SOCKET_H
|
||||
|
57
utils/messageqcpp/socketclosed.h
Normal file
57
utils/messageqcpp/socketclosed.h
Normal file
@ -0,0 +1,57 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/******************************************************************************
|
||||
* $Id$
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/** @file */
|
||||
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#ifndef SOCKETCLOSED_H_
|
||||
#define SOCKETCLOSED_H_
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
/** @brief A closed socket exception class
|
||||
*
|
||||
* Some sort of activity has been requested on a closed socket
|
||||
*/
|
||||
class SocketClosed : public std::exception
|
||||
{
|
||||
std::string _M_msg;
|
||||
|
||||
public:
|
||||
/** Takes a character string describing the error. */
|
||||
explicit
|
||||
SocketClosed(const std::string& __arg) : _M_msg(__arg) { }
|
||||
|
||||
virtual
|
||||
~SocketClosed() throw() { }
|
||||
|
||||
/** Returns a C-style character string describing the general cause of
|
||||
* the current error (the same string passed to the ctor). */
|
||||
virtual const char*
|
||||
what() const throw() { return _M_msg.c_str(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
61
utils/messageqcpp/socketparms.cpp
Normal file
61
utils/messageqcpp/socketparms.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: socketparms.cpp 3495 2013-01-21 14:09:51Z rdempsey $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
|
||||
#include "socketparms.h"
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
SocketParms::SocketParms(int domain, int type, int protocol) :
|
||||
fSd(-1), fDomain(domain), fType(type), fProtocol(protocol)
|
||||
{
|
||||
}
|
||||
|
||||
SocketParms::~SocketParms()
|
||||
{
|
||||
}
|
||||
|
||||
void SocketParms::doCopy(const SocketParms& rhs)
|
||||
{
|
||||
fSd = rhs.fSd;
|
||||
fDomain = rhs.fDomain;
|
||||
fType = rhs.fType;
|
||||
fProtocol = rhs.fProtocol;
|
||||
}
|
||||
|
||||
SocketParms::SocketParms(const SocketParms& rhs)
|
||||
{
|
||||
doCopy(rhs);
|
||||
}
|
||||
|
||||
SocketParms& SocketParms::operator=(const SocketParms& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
doCopy(rhs);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
129
utils/messageqcpp/socketparms.h
Normal file
129
utils/messageqcpp/socketparms.h
Normal file
@ -0,0 +1,129 @@
|
||||
/* Copyright (C) 2014 InfiniDB, Inc.
|
||||
|
||||
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; version 2 of
|
||||
the License.
|
||||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
|
||||
/***********************************************************************
|
||||
* $Id: socketparms.h 3495 2013-01-21 14:09:51Z rdempsey $
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
/** @file */
|
||||
#ifndef MESSAGEQCPP_SOCKETPARMS_H
|
||||
#define MESSAGEQCPP_SOCKETPARMS_H
|
||||
|
||||
class MessageQTestSuite;
|
||||
|
||||
namespace messageqcpp {
|
||||
|
||||
/** a simple socket parameters class
|
||||
*
|
||||
*/
|
||||
class SocketParms
|
||||
{
|
||||
public:
|
||||
/** ctor
|
||||
*
|
||||
*/
|
||||
explicit SocketParms(int domain=-1, int type=-1, int protocol=-1);
|
||||
|
||||
/** dtor
|
||||
*
|
||||
*/
|
||||
virtual ~SocketParms();
|
||||
|
||||
/** copy ctor
|
||||
*
|
||||
*/
|
||||
SocketParms(const SocketParms& rhs);
|
||||
|
||||
/** assign op
|
||||
*
|
||||
*/
|
||||
SocketParms& operator=(const SocketParms& rhs);
|
||||
|
||||
/** accessor
|
||||
*
|
||||
*/
|
||||
inline int sd() const;
|
||||
|
||||
/** accessor
|
||||
*
|
||||
*/
|
||||
inline int domain() const;
|
||||
|
||||
/** accessor
|
||||
*
|
||||
*/
|
||||
inline int type() const;
|
||||
|
||||
/** accessor
|
||||
*
|
||||
*/
|
||||
inline int protocol() const;
|
||||
|
||||
/** mutator
|
||||
*
|
||||
*/
|
||||
inline void sd(int sd);
|
||||
|
||||
/** mutator
|
||||
*
|
||||
*/
|
||||
inline void domain(int domain);
|
||||
|
||||
/** mutator
|
||||
*
|
||||
*/
|
||||
inline void type(int type);
|
||||
|
||||
/** mutator
|
||||
*
|
||||
*/
|
||||
inline void protocol(int protocol);
|
||||
|
||||
/** isOpen test
|
||||
*
|
||||
*/
|
||||
inline bool isOpen() const;
|
||||
|
||||
/*
|
||||
* allow test suite access to private data for OOB test
|
||||
*/
|
||||
friend class ::MessageQTestSuite;
|
||||
|
||||
private:
|
||||
void doCopy(const SocketParms& rhs);
|
||||
|
||||
int fSd; /// the socket descriptor
|
||||
int fDomain; /// the socket domain
|
||||
int fType; /// the socket type
|
||||
int fProtocol; /// the socket protocol
|
||||
};
|
||||
|
||||
inline int SocketParms::sd() const { return fSd; }
|
||||
inline int SocketParms::domain() const { return fDomain; }
|
||||
inline int SocketParms::type() const { return fType; }
|
||||
inline int SocketParms::protocol() const { return fProtocol; }
|
||||
inline bool SocketParms::isOpen() const { return (fSd >= 0); }
|
||||
inline void SocketParms::sd(int sd) { fSd = sd; }
|
||||
inline void SocketParms::domain(int domain) { fDomain = domain; }
|
||||
inline void SocketParms::type(int type) { fType = type; }
|
||||
inline void SocketParms::protocol(int protocol) { fProtocol = protocol; }
|
||||
|
||||
} //namespace messageqcpp
|
||||
|
||||
#endif //MESSAGEQCPP_SOCKETPARMS_H
|
||||
|
38
utils/messageqcpp/srv.cpp
Normal file
38
utils/messageqcpp/srv.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
#include "messagequeue.h"
|
||||
using namespace messageqcpp;
|
||||
|
||||
#include "configcpp.h"
|
||||
using namespace config;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Config* cf = Config::makeConfig("./Calpont.xml");
|
||||
MessageQueueServer mqs("server1", cf);
|
||||
|
||||
cout << "server ready..." << endl;
|
||||
|
||||
IOSocket ios;
|
||||
ByteStream ibs;
|
||||
ByteStream obs;
|
||||
uint32_t qb = 0;
|
||||
while (1)
|
||||
{
|
||||
ios = mqs.accept();
|
||||
ibs = ios.read();
|
||||
while (ibs.length() > 0)
|
||||
{
|
||||
cout << "read " << ibs.length() << " bytes from " << ios << endl;
|
||||
obs.restart();
|
||||
obs << qb;
|
||||
ios.write(obs);
|
||||
ibs = ios.read();
|
||||
}
|
||||
ios.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
1729
utils/messageqcpp/tdriver.cpp
Normal file
1729
utils/messageqcpp/tdriver.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user