pax_global_header00006660000000000000000000000064133104311220014500gustar00rootroot0000000000000052 comment=8bc240b2487956a73dc71502caf831767c0def76 psocksxx-1.1.1/000077500000000000000000000000001331043112200133625ustar00rootroot00000000000000psocksxx-1.1.1/.gitignore000066400000000000000000000004601331043112200153520ustar00rootroot00000000000000# Compiled Object files *.slo *.lo *.o # Compiled Dynamic libraries *.so *.dylib # Compiled Static libraries *.lai *.la *.a # autotools autom4te.cache/* aux-build/* aclocal.m4 config.h.in configure Makefile.in # eclipse .project .cproject .settings/* # swap files *.swp # project specific build/* psocksxx-1.1.1/.travis.yml000066400000000000000000000011061331043112200154710ustar00rootroot00000000000000language: cpp sudo: required dist: trusty compiler: - gcc - clang before_install: - echo $LANG - echo $LC_ALL - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update && sudo apt-get install -y libcppunit-dev; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update && brew install cppunit; fi before_script: - if [ $TRAVIS_OS_NAME == linux ]; then libtoolize; fi - if [ $TRAVIS_OS_NAME == osx ]; then glibtoolize; fi - aclocal - autoheader - autoconf - automake --add-missing - ./configure script: - make - make distcheck os: - linux - osx psocksxx-1.1.1/Makefile.am000066400000000000000000000004071331043112200154170ustar00rootroot00000000000000## Makefile.am # amflags ACLOCAL_AMFLAGS = -I aux-build/m4 # sub dirs SUBDIRS = \ doc \ include \ lib \ src \ test # extra dist files EXTRA_DIST = \ changelog \ README.md # pkg-config pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = psocksxx.pc psocksxx-1.1.1/README.md000066400000000000000000000066541331043112200146540ustar00rootroot00000000000000psocksxx ======== [![GitHub release](https://img.shields.io/github/release/nukedzn/psocksxx.svg)](https://github.com/nukedzn/psocksxx/releases) [![Build Status](https://travis-ci.org/nukedzn/psocksxx.svg)](https://travis-ci.org/nukedzn/psocksxx) A C++ wrapper for POSIX sockets ## Copyright and License Copyright (C) 2013-2015 Uditha Atukorala. This software library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This software library 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 Lesser General Public License](http://www.gnu.org/licenses/lgpl.html) for more details. ## The Concept This project was started to add to the features provided by the simple [socket-library](https://github.com/uditha-atukorala/socket-library) project, specially socket timeouts. But rather than sticking to the same class structure it was decided to use [stream buffers](http://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html) in C++ standard library. The inspiration to derive from std::streambuf came from the [socket++](http://www.linuxhacker.at/socketxx) library initially developed by Gnanasekaran Swaminathan. While the socket++ library seems to be stable and feature rich, the coding style and the lack of API documentation makes it a little difficult for the beginners. psocksxx library attempts to borrow the concepts from socket++ and socket-library, but not the code, and create a well documented (and hopefully easy to understand) POSIX socket communication wrapper in C++. To keep the code simple and clean this project will only support POSIX sockets. ## Downloads You can download source distributions from https://github.com/nukedzn/psocksxx/releases. ### Debian/Ubuntu packages Please check availability for your distribution first ([Debian](https://packages.debian.org/psocksxx), [Ubuntu](http://packages.ubuntu.com/psocksxx)). $ sudo aptitude update $ sudo aptitude install libpsocksxx-dev ## Dependencies * CppUnit >= 1.12.1 (for unit tests) * Doxygen (for doxygen documentation, of course) ## Bugs and Feature Requests Please report all bugs and feature requests under [issues](https://github.com/nukedzn/psocksxx/issues). ## Compiling from source If you are using the github source then first you need to initialise autotools. $ libtoolize (glibtoolize in OS X) $ aclocal $ autoheader $ autoconf $ automake --add-missing (you will need automake >= 1.13) After that you can use the usual `./configure && make` ## Usage Please take a look at [examples](https://github.com/nukedzn/psocksxx/tree/master/src/examples) for more details. ### Simple Server ``` c++ // tcp socket stream psocksxx::tcpnsockstream ss; // network address to bind to psocksxx::nsockaddr naddr( "localhost", "21555" ); // bind and listen ss.bind( &naddr, true ); ss.listen(); // accept a connection psocksxx::nsockstream * css = ss.accept(); ``` ### Simple Client ``` c++ // tcp socket stream psocksxx::tcpnsockstream ss; // connect ss.connect( "localhost", 21555 ); // send a message ss << "hello" << std::endl; // receive a message std::string msg; ss >> msg; ``` ## API Documentation * [v1.0](https://nukedzn.github.io/psocksxx/docs/v1.0) psocksxx-1.1.1/acinclude.m4000066400000000000000000000056141331043112200155610ustar00rootroot00000000000000dnl dnl AM_PATH_CPPUNIT(MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) dnl AC_DEFUN([AM_PATH_CPPUNIT], [ AC_ARG_WITH(cppunit-prefix,[ --with-cppunit-prefix=PFX Prefix where CppUnit is installed (optional)], cppunit_config_prefix="$withval", cppunit_config_prefix="") AC_ARG_WITH(cppunit-exec-prefix,[ --with-cppunit-exec-prefix=PFX Exec prefix where CppUnit is installed (optional)], cppunit_config_exec_prefix="$withval", cppunit_config_exec_prefix="") if test x$cppunit_config_exec_prefix != x ; then cppunit_config_args="$cppunit_config_args --exec-prefix=$cppunit_config_exec_prefix" if test x${CPPUNIT_CONFIG+set} != xset ; then CPPUNIT_CONFIG=$cppunit_config_exec_prefix/bin/cppunit-config fi fi if test x$cppunit_config_prefix != x ; then cppunit_config_args="$cppunit_config_args --prefix=$cppunit_config_prefix" if test x${CPPUNIT_CONFIG+set} != xset ; then CPPUNIT_CONFIG=$cppunit_config_prefix/bin/cppunit-config fi fi AC_PATH_PROG(CPPUNIT_CONFIG, cppunit-config, no) cppunit_version_min=$1 AC_MSG_CHECKING(for Cppunit - version >= $cppunit_version_min) no_cppunit="" if test "$CPPUNIT_CONFIG" = "no" ; then AC_MSG_RESULT(no) no_cppunit=yes else CPPUNIT_CFLAGS=`$CPPUNIT_CONFIG --cflags` CPPUNIT_LIBS=`$CPPUNIT_CONFIG --libs` cppunit_version=`$CPPUNIT_CONFIG --version` cppunit_major_version=`echo $cppunit_version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` cppunit_minor_version=`echo $cppunit_version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` cppunit_micro_version=`echo $cppunit_version | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` cppunit_major_min=`echo $cppunit_version_min | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` if test "x${cppunit_major_min}" = "x" ; then cppunit_major_min=0 fi cppunit_minor_min=`echo $cppunit_version_min | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` if test "x${cppunit_minor_min}" = "x" ; then cppunit_minor_min=0 fi cppunit_micro_min=`echo $cppunit_version_min | \ sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` if test "x${cppunit_micro_min}" = "x" ; then cppunit_micro_min=0 fi cppunit_version_proper=`expr \ $cppunit_major_version \> $cppunit_major_min \| \ $cppunit_major_version \= $cppunit_major_min \& \ $cppunit_minor_version \> $cppunit_minor_min \| \ $cppunit_major_version \= $cppunit_major_min \& \ $cppunit_minor_version \= $cppunit_minor_min \& \ $cppunit_micro_version \>= $cppunit_micro_min ` if test "$cppunit_version_proper" = "1" ; then AC_MSG_RESULT([$cppunit_major_version.$cppunit_minor_version.$cppunit_micro_version]) else AC_MSG_RESULT(no) no_cppunit=yes fi fi if test "x$no_cppunit" = x ; then ifelse([$2], , :, [$2]) else CPPUNIT_CFLAGS="" CPPUNIT_LIBS="" ifelse([$3], , :, [$3]) fi AC_SUBST(CPPUNIT_CFLAGS) AC_SUBST(CPPUNIT_LIBS) ]) psocksxx-1.1.1/changelog000066400000000000000000000016201331043112200152330ustar00rootroot000000000000001.1.1 - 14th June 2018 * Drop ordered comparisons between pointers and zero * Use NULL instead of 0 for pointers 1.1.0 - 29th November 2015 * Add examples * Enforce Automake version check in configure.ac 1.0.0 - 04th November 2015 * First stable release (no code changes since v0.0.6) 0.0.6 - 03rd October 2014 * Remove obsolete doxygen tags 0.0.5 - 29th June 2014 * Fix inconsistent timeout behaviour on different systems 0.0.4 - 10th November 2013 * bug fix - member functions should not be throwing exceptions if the signature does not specify it. 0.0.3 - 31st October 2013 * Suppress SIGPIPE signals * Code cleanup work 0.0.2 - 29th September 2013 * Added timeout support for socket communications * New base socket stream I/O class to reduce redundant code * Added install targets for doxygen generated docs 0.0.1 - 19th September 2013 * Initial release psocksxx-1.1.1/configure.ac000066400000000000000000000044771331043112200156640ustar00rootroot00000000000000# configure.ac # Process this file with autoconf to produce a configure script. AC_PREREQ([2.68]) AC_INIT([psocksxx], [1.1.1], [https://github.com/nukedzn/psocksxx/issues]) AC_CONFIG_AUX_DIR([aux-build]) AC_CONFIG_MACRO_DIR([aux-build/m4]) AC_CONFIG_HEADERS([include/config.h]) # Versioning rules ( C:R:A ) # # 1. Start with version 0:0:0. # 2. If any of the sources have changed, increment R. This is a new revision # of the current interface. # 3. If the interface has changed, increment C and set R to 0. This is the # first revision of a new interface. # 4. If the new interface is a superset of the previous interface # (that is, if the previous interface has not been broken by the # changes in this new release), increment A. This release is backwards # compatible with the previous release. # 5. If the new interface has removed elements with respect to the # previous interface, then backward compatibility is broken; set A to 0. # This release has a new, but backwards incompatible interface. # # For more info see section 6.3 of the GNU Libtool Manual. # # In short; # +1 : ? : +1 == new interface that does not break old one # +1 : ? : 0 == new interface that breaks old one # ? : ? : 0 == no new interfaces, but breaks apps # ? :+1 : ? == just some internal changes, nothing breaks but might work # better # CURRENT : REVISION : AGE # lib versions LIBPSOCKSXX_LT_VERSION=1:4:1 AC_SUBST(LIBPSOCKSXX_LT_VERSION) # init AM_INIT_AUTOMAKE([1.13 foreign]) LT_INIT() # check for programs AC_PROG_CXX AC_PROG_INSTALL AC_PROG_AWK AC_PROG_MKDIR_P AC_PROG_LIBTOOL # language AC_LANG(C++) # doxygen AC_CHECK_PROGS([DOXYGEN], [doxygen], [false]) AM_CONDITIONAL([HAVE_DOXYGEN], [test "x$DOXYGEN" != xfalse]) AM_COND_IF([HAVE_DOXYGEN],, AC_MSG_WARN([Doxygen not found - continuing without Doxygen support]) ) # cppunit AM_PATH_CPPUNIT(1.12.1, [cppunit=true], [ cppunit=false AC_MSG_WARN([Cppunit not found - continuing without unit test support]) ] ) AM_CONDITIONAL([HAVE_CPPUNIT], [test x$cppunit = xtrue]) # TAP driver AC_REQUIRE_AUX_FILE([tap-driver.sh]) AC_CONFIG_FILES([ \ Makefile \ psocksxx.pc \ doc/doxygen.cfg \ doc/Makefile \ include/Makefile \ lib/Makefile \ lib/psocksxx/Makefile \ src/Makefile \ src/examples/Makefile \ src/examples/echo/Makefile \ test/Makefile \ ]) AC_OUTPUT psocksxx-1.1.1/doc/000077500000000000000000000000001331043112200141275ustar00rootroot00000000000000psocksxx-1.1.1/doc/Makefile.am000066400000000000000000000006241331043112200161650ustar00rootroot00000000000000## [psocksxx] doc/ # doxygen if HAVE_DOXYGEN doxygen.stamp: $(DOXYGEN) doxygen.cfg echo timestamp > doxygen.stamp CLEANFILES = doxygen.stamp doxygen-doc: doxygen.stamp install-doxygen-doc: doxygen-doc $(INSTALL) -d $(docdir) cp -r doxygen/html $(docdir) uninstall-local: rm -rf $(docdir)/html clean-local: rm -rf $(top_builddir)/doc/doxygen .PHONY: doxygen-doc install-doxygen-doc endif psocksxx-1.1.1/doc/doxygen.cfg.in000066400000000000000000000241621331043112200166770ustar00rootroot00000000000000# Doxyfile 1.8.3 #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- DOXYFILE_ENCODING = UTF-8 PROJECT_NAME = @PACKAGE_NAME@ PROJECT_NUMBER = @PACKAGE_VERSION@ PROJECT_BRIEF = PROJECT_LOGO = OUTPUT_DIRECTORY = @top_builddir@/doc/doxygen CREATE_SUBDIRS = NO OUTPUT_LANGUAGE = English BRIEF_MEMBER_DESC = YES REPEAT_BRIEF = YES ABBREVIATE_BRIEF = ALWAYS_DETAILED_SEC = NO INLINE_INHERITED_MEMB = NO FULL_PATH_NAMES = YES STRIP_FROM_PATH = STRIP_FROM_INC_PATH = SHORT_NAMES = NO JAVADOC_AUTOBRIEF = NO QT_AUTOBRIEF = NO MULTILINE_CPP_IS_BRIEF = NO INHERIT_DOCS = YES SEPARATE_MEMBER_PAGES = NO TAB_SIZE = 4 ALIASES = TCL_SUBST = OPTIMIZE_OUTPUT_FOR_C = NO OPTIMIZE_OUTPUT_JAVA = NO OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO EXTENSION_MAPPING = MARKDOWN_SUPPORT = YES AUTOLINK_SUPPORT = YES BUILTIN_STL_SUPPORT = NO CPP_CLI_SUPPORT = NO SIP_SUPPORT = NO IDL_PROPERTY_SUPPORT = YES DISTRIBUTE_GROUP_DOC = NO SUBGROUPING = YES INLINE_GROUPED_CLASSES = NO INLINE_SIMPLE_STRUCTS = NO TYPEDEF_HIDES_STRUCT = NO LOOKUP_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- EXTRACT_ALL = NO EXTRACT_PRIVATE = NO EXTRACT_PACKAGE = NO EXTRACT_STATIC = NO EXTRACT_LOCAL_CLASSES = YES EXTRACT_LOCAL_METHODS = NO EXTRACT_ANON_NSPACES = NO HIDE_UNDOC_MEMBERS = NO HIDE_UNDOC_CLASSES = NO HIDE_FRIEND_COMPOUNDS = NO HIDE_IN_BODY_DOCS = NO INTERNAL_DOCS = NO CASE_SENSE_NAMES = NO HIDE_SCOPE_NAMES = NO SHOW_INCLUDE_FILES = YES FORCE_LOCAL_INCLUDES = NO INLINE_INFO = YES SORT_MEMBER_DOCS = YES SORT_BRIEF_DOCS = NO SORT_MEMBERS_CTORS_1ST = NO SORT_GROUP_NAMES = NO SORT_BY_SCOPE_NAME = NO STRICT_PROTO_MATCHING = NO GENERATE_TODOLIST = YES GENERATE_TESTLIST = YES GENERATE_BUGLIST = YES GENERATE_DEPRECATEDLIST= YES ENABLED_SECTIONS = MAX_INITIALIZER_LINES = 30 SHOW_USED_FILES = NO SHOW_FILES = YES SHOW_NAMESPACES = YES FILE_VERSION_FILTER = LAYOUT_FILE = CITE_BIB_FILES = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- QUIET = YES WARNINGS = YES WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES WARN_NO_PARAMDOC = NO WARN_FORMAT = "$file:$line: $text" WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- INPUT = @top_srcdir@ INPUT_ENCODING = UTF-8 FILE_PATTERNS = RECURSIVE = YES EXCLUDE = @top_srcdir@/doc @top_srcdir@/test EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXCLUDE_SYMBOLS = EXAMPLE_PATH = EXAMPLE_PATTERNS = EXAMPLE_RECURSIVE = NO IMAGE_PATH = INPUT_FILTER = FILTER_PATTERNS = FILTER_SOURCE_FILES = NO FILTER_SOURCE_PATTERNS = USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- SOURCE_BROWSER = NO INLINE_SOURCES = NO STRIP_CODE_COMMENTS = YES REFERENCED_BY_RELATION = NO REFERENCES_RELATION = NO REFERENCES_LINK_SOURCE = YES USE_HTAGS = NO VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- ALPHABETICAL_INDEX = YES COLS_IN_ALPHA_INDEX = 5 IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = HTML_FOOTER = HTML_STYLESHEET = HTML_EXTRA_STYLESHEET = HTML_EXTRA_FILES = HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 HTML_TIMESTAMP = YES HTML_DYNAMIC_SECTIONS = NO HTML_INDEX_NUM_ENTRIES = 100 GENERATE_DOCSET = NO DOCSET_FEEDNAME = "Doxygen generated docs" DOCSET_BUNDLE_ID = org.doxygen.Project DOCSET_PUBLISHER_ID = org.doxygen.Publisher DOCSET_PUBLISHER_NAME = Publisher GENERATE_HTMLHELP = NO CHM_FILE = HHC_LOCATION = GENERATE_CHI = NO CHM_INDEX_ENCODING = BINARY_TOC = NO TOC_EXPAND = NO GENERATE_QHP = NO QCH_FILE = QHP_NAMESPACE = org.doxygen.Project QHP_VIRTUAL_FOLDER = doc QHP_CUST_FILTER_NAME = QHP_CUST_FILTER_ATTRS = QHP_SECT_FILTER_ATTRS = QHG_LOCATION = GENERATE_ECLIPSEHELP = NO ECLIPSE_DOC_ID = org.doxygen.Project DISABLE_INDEX = NO GENERATE_TREEVIEW = NO ENUM_VALUES_PER_LINE = 4 TREEVIEW_WIDTH = 250 EXT_LINKS_IN_WINDOW = NO FORMULA_FONTSIZE = 10 FORMULA_TRANSPARENT = YES USE_MATHJAX = NO MATHJAX_FORMAT = HTML-CSS MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest MATHJAX_EXTENSIONS = SEARCHENGINE = YES SERVER_BASED_SEARCH = NO EXTERNAL_SEARCH = NO SEARCHENGINE_URL = SEARCHDATA_FILE = searchdata.xml EXTRA_SEARCH_MAPPINGS = #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- GENERATE_LATEX = NO LATEX_OUTPUT = latex LATEX_CMD_NAME = latex MAKEINDEX_CMD_NAME = makeindex COMPACT_LATEX = NO PAPER_TYPE = a4 EXTRA_PACKAGES = LATEX_HEADER = LATEX_FOOTER = PDF_HYPERLINKS = YES USE_PDFLATEX = YES LATEX_BATCHMODE = NO LATEX_HIDE_INDICES = NO LATEX_SOURCE_CODE = NO LATEX_BIB_STYLE = plain #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- GENERATE_RTF = NO RTF_OUTPUT = rtf COMPACT_RTF = NO RTF_HYPERLINKS = NO RTF_STYLESHEET_FILE = RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- GENERATE_MAN = NO MAN_OUTPUT = man MAN_EXTENSION = .3 MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- GENERATE_XML = NO XML_OUTPUT = xml XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- GENERATE_PERLMOD = NO PERLMOD_LATEX = NO PERLMOD_PRETTY = YES PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- ENABLE_PREPROCESSING = YES MACRO_EXPANSION = NO EXPAND_ONLY_PREDEF = NO SEARCH_INCLUDES = YES INCLUDE_PATH = INCLUDE_FILE_PATTERNS = PREDEFINED = EXPAND_AS_DEFINED = SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- TAGFILES = GENERATE_TAGFILE = ALLEXTERNALS = NO EXTERNAL_GROUPS = YES PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- CLASS_DIAGRAMS = YES MSCGEN_PATH = HIDE_UNDOC_RELATIONS = YES HAVE_DOT = NO DOT_NUM_THREADS = 0 DOT_FONTNAME = Helvetica DOT_FONTSIZE = 10 DOT_FONTPATH = CLASS_GRAPH = YES COLLABORATION_GRAPH = YES GROUP_GRAPHS = YES UML_LOOK = NO UML_LIMIT_NUM_FIELDS = 10 TEMPLATE_RELATIONS = NO INCLUDE_GRAPH = YES INCLUDED_BY_GRAPH = YES CALL_GRAPH = NO CALLER_GRAPH = NO GRAPHICAL_HIERARCHY = YES DIRECTORY_GRAPH = YES DOT_IMAGE_FORMAT = png INTERACTIVE_SVG = NO DOT_PATH = DOTFILE_DIRS = MSCFILE_DIRS = DOT_GRAPH_MAX_NODES = 50 MAX_DOT_GRAPH_DEPTH = 0 DOT_TRANSPARENT = NO DOT_MULTI_TARGETS = NO GENERATE_LEGEND = YES DOT_CLEANUP = YES psocksxx-1.1.1/include/000077500000000000000000000000001331043112200150055ustar00rootroot00000000000000psocksxx-1.1.1/include/Makefile.am000066400000000000000000000000301331043112200170320ustar00rootroot00000000000000## [psocksxx] include/ psocksxx-1.1.1/lib/000077500000000000000000000000001331043112200141305ustar00rootroot00000000000000psocksxx-1.1.1/lib/Makefile.am000066400000000000000000000000471331043112200161650ustar00rootroot00000000000000## [psocksxx] lib/ SUBDIRS = psocksxx psocksxx-1.1.1/lib/psocksxx/000077500000000000000000000000001331043112200160125ustar00rootroot00000000000000psocksxx-1.1.1/lib/psocksxx/Makefile.am000066400000000000000000000014561331043112200200540ustar00rootroot00000000000000## [psocksxx] lib/psocksxx/ AM_CPPFLAGS = -I$(top_srcdir)/lib libpsocksxxincludedir = $(includedir)/psocksxx lib_LTLIBRARIES = libpsocksxx.la libpsocksxx_la_LIBADD = libpsocksxx_la_LDFLAGS = -version-info @LIBPSOCKSXX_LT_VERSION@ -no-undefined libpsocksxx_la_SOURCES = \ sockexception.cpp \ socktimeoutexception.cpp \ lsockaddr.cpp \ nsockaddr.cpp \ sockstreambuf.cpp \ iosocks.cpp \ isockstream.cpp \ osockstream.cpp \ lsockstream.cpp \ nsockstream.cpp \ tcpnsockstream.cpp \ udpnsockstream.cpp libpsocksxxinclude_HEADERS = \ sockexception.h \ socktimeoutexception.h \ sockaddr.h \ lsockaddr.h \ nsockaddr.h \ sockstreambuf.h \ iosocks.h \ isockstream.h \ osockstream.h \ iosockstream.h \ lsockstream.h \ nsockstream.h \ tcpnsockstream.h \ udpnsockstream.h psocksxx-1.1.1/lib/psocksxx/iosocks.cpp000066400000000000000000000025371331043112200201770ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "iosocks.h" namespace psocksxx { bool iosocks::timedout() const throw() { // socket stream buffer sockstreambuf * ssb = (sockstreambuf *) rdbuf(); return ssb->timedout(); } const timeval * iosocks::timeout( time_t sec, suseconds_t usec ) throw() { // socket stream buffer sockstreambuf * ssb = (sockstreambuf *) rdbuf(); return ssb->timeout( sec, usec ); } void * iosocks::clear_timeout() throw() { // socket stream buffer sockstreambuf * ssb = (sockstreambuf *) rdbuf(); return ssb->clear_timeout(); } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/iosocks.h000066400000000000000000000047431331043112200176450ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_IOSOCKS_H #define PSOCKSXX_IOSOCKS_H #include #include namespace psocksxx { /** * @brief base class for socket stream controller classes * * This class holds the common methods for socket stream controller * classes. */ class iosocks : public virtual std::ios { public: /** * @brief destructor * * Does nothing. * */ virtual ~iosocks() throw() { }; /** * @brief get the timed-out status flag value * @return boolean @c true if timed-out flag is set or @c false * otherwise. * * Returns the timed-out status for the associated socket stream * buffer. * */ bool timedout() const throw(); /** * @brief set the timeout value for stream communications * @param sec seconds * @param usec microseconds * @return a reference to the internal timeout structure * * Wrapper method for sockstreambuf::timeout() to set the * timeout value for stream communications. * * @see sockstreambuf::timeout() * */ const timeval * timeout( time_t sec, suseconds_t usec ) throw(); /** * @brief clear the timeout value * @return a reference to the internal timeout structure which will * always be a null-pointer (@c 0) after clearing the timeout * * This will clear any timeout values set for this stream using * timeout(). * */ void * clear_timeout() throw(); protected: /** * @brief empty default constructor * * Empty default constructor so that derived classes through virtual * inheritance does not have to call the constructor. * */ iosocks() throw() { } }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_IOSOCKS_H */ psocksxx-1.1.1/lib/psocksxx/iosockstream.h000066400000000000000000000037621331043112200206760ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_IOSOCKSTREAM_H #define PSOCKSXX_IOSOCKSTREAM_H #include #include namespace psocksxx { /** * @brief Input and Output controller class for socket streams * * This merges the two input and output controller * classes to create a single interface for controlling * both input and output socket streams. * */ class iosockstream : public isockstream, public osockstream { public: /** * @brief constructor * @param ssb socket stream buffer * * This constructor simply initialises the parent * classes with the passed in socket stream buffer */ iosockstream( sockstreambuf * ssb ) throw() : isockstream( ssb ), osockstream( ssb ) { // constructor } /** * @brief destructor */ virtual ~iosockstream() throw() { // destructor } /** * @brief get the timed-out status for this stream * @return boolean @c true if timed-out flag is set or @c false * otherwise. * * Returns the timed-out status. * */ bool timedout() const throw() { return ( isockstream::timedout() || osockstream::timedout() ); } }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_IOSOCKSTREAM_H */ psocksxx-1.1.1/lib/psocksxx/isockstream.cpp000066400000000000000000000020141331043112200210370ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "isockstream.h" namespace psocksxx { isockstream::isockstream( sockstreambuf * ssb ) throw() : std::istream( ssb ) { // constructor } isockstream::~isockstream() throw() { // destructor } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/isockstream.h000066400000000000000000000027171331043112200205160ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_ISOCKSTREAM_H #define PSOCKSXX_ISOCKSTREAM_H #include #include namespace psocksxx { /** * @brief Input controller class for socket streams * * This class acts as an interface for getting inputs * from a psocksxx::sockstreambuf class. */ class isockstream : public virtual iosocks, public std::istream { public: /** * @brief constructor * @param ssb socket stream buffer * * Create an input socket stream controller instance. * */ isockstream( sockstreambuf * ssb ) throw(); virtual ~isockstream() throw(); //!< destructor }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_ISOCKSTREAM_H */ psocksxx-1.1.1/lib/psocksxx/lsockaddr.cpp000066400000000000000000000023521331043112200204660ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "lsockaddr.h" #include namespace psocksxx { lsockaddr::lsockaddr( const char * path ) throw() { // set the socket address family sun_family = sockaddr::af_local; // set the socket path strcpy( sun_path, path ); } socklen_t lsockaddr::size() const throw() { return sizeof( sockaddr_un ); } ::sockaddr * lsockaddr::psockaddr() const throw() { return (::sockaddr *) (sockaddr_un *) this; } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/lsockaddr.h000066400000000000000000000030511331043112200201300ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_LSOCKADDR_H #define PSOCKSXX_LSOCKADDR_H #include #include namespace psocksxx { /** * @brief Socket address class for local sockets * * This class holds the socket addressing structure for local * (unix) socket communications. * */ class lsockaddr : public sockaddr, public sockaddr_un { public: /** * @brief constructor * @param path local socket address file path * * Create a local socket address instance with the given file * path as the socket address. * */ lsockaddr( const char * path ) throw(); // abstract method implementations socklen_t size() const throw(); ::sockaddr* psockaddr() const throw(); }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_LSOCKADDR_H */ psocksxx-1.1.1/lib/psocksxx/lsockstream.cpp000066400000000000000000000032261331043112200210500ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "lsockstream.h" namespace psocksxx { lsockstream::lsockstream() throw( sockexception ) : iosockstream( 0 ) { // socket stream buffer instance sockstreambuf * ssb = new sockstreambuf(); // open local socket ssb->open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); // update I/O buffer iosockstream::init( ssb ); } lsockstream::~lsockstream() throw() { // cleanup delete iosockstream::rdbuf(); } void lsockstream::connect( const char * path ) throw( sockexception, socktimeoutexception ) { lsockaddr saddr( path ); sockstreambuf * ssb = (sockstreambuf *) rdbuf(); ssb->connect( &saddr ); } void lsockstream::connect( const lsockaddr * saddr ) throw( sockexception, socktimeoutexception ) { sockstreambuf * ssb = (sockstreambuf *) rdbuf(); ssb->connect( saddr ); } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/lsockstream.h000066400000000000000000000046011331043112200205130ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_LSOCKSTREAM_H #define PSOCKSXX_LSOCKSTREAM_H #include #include namespace psocksxx { /** * @brief Local (unix) socket controller class * * This class acts as a controller for communicating through a * local (unix) socket and uses an instance of psocksxx::sockstreambuf * as the underlying / associated sequence. */ class lsockstream : public iosockstream { public: /** * @brief constructor * @throw psocksxx::sockexception socket exception * * Initialise a local (unix) communication stream. * */ lsockstream() throw( sockexception ); /** * @brief destructor */ virtual ~lsockstream() throw(); /** * @brief connect to a local socket * @param path local socket path * @throw psocksxx::sockexception socket exception * @throw psocksxx::socktimeoutexception connection timeout * exception * * Connect a to local socket at the given path. It is assumed * that the socket is ready to accept connections. * */ void connect( const char * path ) throw( sockexception, socktimeoutexception ); /** * @brief connect to a local socket * @param saddr local socket address instance * @throw psocksxx::sockexception socket exception * @throw psocksxx::socktimeoutexception connection timeout * exception * * Connect to a local socket using the passed in socket address * object. * */ void connect( const lsockaddr * saddr ) throw( sockexception, socktimeoutexception ); }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_LSOCKSTREAM_H */ psocksxx-1.1.1/lib/psocksxx/nsockaddr.cpp000066400000000000000000000062731331043112200204760ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "nsockaddr.h" #include "sockstreambuf.h" #include #include namespace psocksxx { nsockaddr::nsockaddr( const char * node, unsigned short port ) throw( sockexception ) { // set the socket address family sin_family = sockaddr::af_inet; // set the port sin_port = htons( port ); // set the address sin_addr.s_addr = resolve_node( node ); // zero out internals memset( sin_zero, 0, sizeof( sin_zero ) ); } nsockaddr::nsockaddr( unsigned short port ) throw() { // set the socket address family sin_family = sockaddr::af_inet; // set the port sin_port = htons( port ); // set the address sin_addr.s_addr = INADDR_ANY; // zero out internals memset( sin_zero, 0, sizeof( sin_zero ) ); } nsockaddr::nsockaddr( const char * node, const char * service ) throw( sockexception ) { int status; addrinfo hints; addrinfo * result; sockaddr_in * sinaddr; // empty the hints structure memset( &hints, 0, sizeof( hints ) ); // setup hints hints.ai_family = sockaddr::af_inet; hints.ai_socktype = sockstreambuf::sock_stream; // translate node and service into a network address if ( ( status = ( getaddrinfo( node, service, &hints, &result ) ) ) != 0 ) { throw sockexception( gai_strerror( status ) ); } // grab the address info we need sinaddr = (sockaddr_in *) result->ai_addr; sin_family = sockaddr::af_inet; sin_addr = sinaddr->sin_addr; sin_port = sinaddr->sin_port; // zero out internals memset( sin_zero, 0, sizeof( sin_zero ) ); // cleanup freeaddrinfo( result ); } in_addr_t nsockaddr::resolve_node( const char * node ) throw( sockexception ) { int status; addrinfo hints; addrinfo * result; in_addr_t in_addr; // empty the hints structure memset( &hints, 0, sizeof( hints ) ); // setup hints hints.ai_family = sockaddr::af_inet; hints.ai_socktype = sockstreambuf::sock_stream; // resolve node if ( ( status = ( getaddrinfo( node, 0, &hints, &result ) ) ) != 0 ) { throw sockexception( gai_strerror( status ) ); } // grab the address info we need in_addr = ( (sockaddr_in *) result->ai_addr )->sin_addr.s_addr; // cleanup freeaddrinfo( result ); return in_addr; } socklen_t nsockaddr::size() const throw() { return sizeof( sockaddr_in ); } ::sockaddr * nsockaddr::psockaddr() const throw() { return (::sockaddr *) (sockaddr_in *) this; } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/nsockaddr.h000066400000000000000000000052701331043112200201370ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_NSOCKADDR_H #define PSOCKSXX_NSOCKADDR_H #include #include #include namespace psocksxx { /** * @brief Socket address class for IPv4 addresses * * This class holds the socket addressing structure for IPv4 * socket communications. * */ class nsockaddr : public sockaddr, public sockaddr_in { public: /** * @brief constructor * @param node node (host name or IP) * @param port port number * @throw psocksxx::sockexception socket exception * * Create a IPv4 socket address instance with the give node * and port information. * */ nsockaddr( const char * node, unsigned short port ) throw( sockexception ); /** * @brief constructor * @param port port number * * Create a IPv4 socket address instance with the given port * and the node (host/IP) will be any available interface on * the host computer. * */ nsockaddr( unsigned short port ) throw(); /** * @brief constructor * @param node node (host name or IP) * @param service port number of the service name (e.g. "http") * @throw psocksxx::sockexception socket exception * * Create a IPv4 socket address instance with the give node * and service information. * */ nsockaddr( const char * node, const char * service ) throw( sockexception ); // abstract method implementations socklen_t size() const throw(); ::sockaddr* psockaddr() const throw(); protected: /** * @brief convert a node name to a IPv4 address * @param node node (host name or IP) * @throw psocksxx::sockexception socket exception * @return IPv4 address in network byte order * * Helper function to convert a node name into a IPv4 network * address. * */ in_addr_t resolve_node( const char * node ) throw( sockexception ); }; } /* end of namespace psockxx */ #endif /* !PSOCKSXX_NSOCKADDR_H */ psocksxx-1.1.1/lib/psocksxx/nsockstream.cpp000066400000000000000000000051251331043112200210520ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "nsockstream.h" namespace psocksxx { nsockstream::nsockstream( sockstreambuf::socket_type_t type, sockstreambuf::socket_protocol_t proto ) throw ( sockexception ) : iosockstream( 0 ) { // socket stream buffer instance sockstreambuf * ssb = new sockstreambuf(); // open the socket communication ssb->open( sockstreambuf::pf_inet, type, proto ); // update I/O buffer iosockstream::init( ssb ); } nsockstream::nsockstream( sockstreambuf * ssb ) throw() : iosockstream( ssb ) { } nsockstream::~nsockstream() throw() { // cleanup delete iosockstream::rdbuf(); } void nsockstream::connect( const nsockaddr * saddr ) throw( sockexception, socktimeoutexception ) { // socket stream buffer sockstreambuf * ssb = (sockstreambuf *) rdbuf(); // connect ssb->connect( saddr ); } void nsockstream::connect( const char * node, unsigned int port ) throw( sockexception, socktimeoutexception ) { // network address nsockaddr naddr( node, port ); // connect connect( &naddr ); } void nsockstream::bind( const nsockaddr * saddr, bool reuse_addr ) throw( sockexception ) { // socket stream buffer sockstreambuf * ssb = (sockstreambuf *) rdbuf(); // bind ssb->bind( saddr, reuse_addr ); } void nsockstream::listen( int backlog ) throw( sockexception ) { // socket stream buffer sockstreambuf * ssb = (sockstreambuf *) rdbuf(); if ( backlog == 0 ) { ssb->listen(); } else { ssb->listen( backlog ); } } nsockstream * nsockstream::accept() throw( sockexception ) { // socket stream buffers sockstreambuf * ssb = (sockstreambuf *) rdbuf(); sockstreambuf * cl_ssb; // accept sockstreambuf::socket_t cl_sock = ssb->accept(); cl_ssb = new sockstreambuf( cl_sock ); // return return new nsockstream( cl_ssb ); } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/nsockstream.h000066400000000000000000000111061331043112200205130ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_NSOCKSTREAM_H #define PSOCKSXX_NSOCKSTREAM_H #include #include namespace psocksxx { /** * @brief Network (IPv4) controller class * * This is the base class for network (IP version 4) * communications streams. * */ class nsockstream : public iosockstream { public: /** * @brief constructor * @param type socket communications type * @param proto socket communications protocol * @throw psocksxx::sockexception socket exception * * Open a network (IPv4) communications stream with the * passed in type and protocol. */ nsockstream( sockstreambuf::socket_type_t type, sockstreambuf::socket_protocol_t proto ) throw( sockexception ); /** * @brief constructor * @param ssb initialised socket stream buffer instance * * Initialise a network socket stream by using the passed in * socket stream buffer, @c ssb, as the associated sequence * which is assumed to be initialised with the correct type * and protocol. The class destructor will delete the psocksxx::sockstreambuf * instance pointed by @c ssb. * */ nsockstream( sockstreambuf * ssb ) throw(); /** * @brief destructor */ virtual ~nsockstream() throw(); /** * @brief connect to a network address * @param saddr destination address information * @throw psocksxx::sockexception socket exception * @throw psocksxx::socktimeoutexception connection timeout * exception * * Connect to a IPv4 communication end point making this stream * ready for I/O. * */ void connect( const nsockaddr * saddr ) throw( sockexception, socktimeoutexception ); /** * @brief connect to a network address * @param node node (host name or IP) * @param port port number * @throw psocksxx::sockexception socket exception * @throw psocksxx::socktimeoutexception connection timeout * exception * * Connect to a IPv4 communication end point making this stream * ready for I/O. * */ void connect( const char * node, unsigned int port ) throw( sockexception, socktimeoutexception ); /** * @brief bind the stream to a network address * @param saddr address information to bind to * @param reuse_addr allow address to be re-used * @throw psocksxx::sockexception socket exception * * This binds the network socket stream to the specified network * address. If you want to try to bind to any socket that is not * actively listening (e.g. TIME_WAIT) then set the @c reuse_addr * parameter to be @c true. * */ void bind( const nsockaddr * saddr, bool reuse_addr = false ) throw( sockexception ); /** * @brief make this stream passive and ready to accept connections * @param backlog maximum length of the queue for pending connections * and if this value is 0 (default) then it assumes * system default * * @throw psocksxx::sockexception socket exception * * Make this network stream passive and ready to accept connections. * Before calling this method the stream must be bound to a * network address using the bind() method. * */ void listen( int backlog = 0 ) throw( sockexception ); /** * @brief accept a connection on a listening (passive) stream * @throw psocksxx::sockexception socket exception * @return a new stream instance for the accepted connection * * This method will accept an incoming connection on a listening * stream and return a newly created stream instance that can * be used to communicate with the accepted client connection. * Note that the returned stream instance must be deleted by the * caller. * */ nsockstream * accept() throw( sockexception ); }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_NSOCKSTEAM_H */ psocksxx-1.1.1/lib/psocksxx/osockstream.cpp000066400000000000000000000020141331043112200210450ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "osockstream.h" namespace psocksxx { osockstream::osockstream( sockstreambuf * ssb ) throw() : std::ostream( ssb ) { // constructor } osockstream::~osockstream() throw() { // destructor } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/osockstream.h000066400000000000000000000027161331043112200205230ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_OSOCKSTREAM_H #define PSOCKSXX_OSOCKSTREAM_H #include #include namespace psocksxx { /** * @brief Output controller class for socket streams * * This class acts as an interface for sendding outputs * to a psocksxx::sockstreambuf class */ class osockstream : public virtual iosocks, public std::ostream { public: /** * @brief constructor * @param ssb socket stream buffer * * Create and output socket stream controller instance * */ osockstream( sockstreambuf * ssb ) throw(); virtual ~osockstream() throw(); //!< destructor }; } /* end of namespace psocksxx */ #endif /* !PSOCKS_OSOCKSTREAM_H */ psocksxx-1.1.1/lib/psocksxx/sockaddr.h000066400000000000000000000036411331043112200177610ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_SOCKADDR_H #define PSOCKSXX_SOCKADDR_H #include namespace psocksxx { /** * @brief Socket address base class * * This abstract class acts as an interface for accessing derived * socket address structures. * */ class sockaddr { public: /** socket address types definition */ enum address_t { af_unspec = AF_UNSPEC, /*! unspecified */ af_local = AF_LOCAL, /*! local addresses */ af_inet = AF_INET /*! network addresses */ }; /** * @brief destructor */ virtual ~sockaddr() { }; /** * @brief get POSIX socket address size * @return POSIX address size * * Helper function to get the size of the related POSIX socket * address. * */ virtual socklen_t size() const throw() =0; /** * @brief get a POSIX socket address structure * @return POSIX socket address structure * * Helper function to get a pointer to the POSIX socket * address structure relating to this socket address instance. * */ virtual ::sockaddr * psockaddr() const throw() =0; }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_SOCKADDR_H */ psocksxx-1.1.1/lib/psocksxx/sockexception.cpp000066400000000000000000000025551331043112200214030ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "sockexception.h" #include #include namespace psocksxx { sockexception::sockexception( const char * message ) throw() { // copy system error _errno = errno; _sys_msg = strerror( _errno ); // sanity check if ( message == 0 ) { // use system error message if no user message is passed in _message = _sys_msg; } else { // use the user message _message = message; } } sockexception::~sockexception() throw() { } const char * sockexception::what() const throw() { return _message.c_str(); } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/sockexception.h000066400000000000000000000036231331043112200210450ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_SOCKEXCEPTION_H #define PSOCKSXX_SOCKEXCEPTION_H #include #include #include namespace psocksxx { /** * @brief Socket exception * * This is the base class for all socket exceptions. */ class sockexception : public std::exception { public: /** * @brief constructor * * Create an instance with the passed in error message. * If a message is not passed in or is equal to @c 0 then * the system error message is used. * * @param message (optional) user error message */ sockexception( const char * message = 0 ) throw(); virtual ~sockexception() throw(); //!< destructor /** * @brief Returns exception message * * Returns a C-Style character string describing the * exception. * * @return exception message * @sa sockexception() constructor */ const char * what() const throw(); protected: /** user exception message */ std::string _message; /** system error number */ int _errno; /** system error message */ std::string _sys_msg; }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_SOCKEXCEPTION_H */ psocksxx-1.1.1/lib/psocksxx/sockstreambuf.cpp000066400000000000000000000226231331043112200213730ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "sockstreambuf.h" #include #include // Mac OSX does not define MSG_NOSIGNAL #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif namespace psocksxx { sockstreambuf::sockstreambuf() throw() : _socket( -1 ), _bufsize( SOCKSTREAMBUF_SIZE ), _putbacksize( SOCKSTREAMBUF_PUTBACK_SIZE ) { // initialise defaults init_defaults(); // initialise internal buffers init_buffers(); } sockstreambuf::sockstreambuf( socket_t socket ) throw() : _bufsize( SOCKSTREAMBUF_SIZE ), _putbacksize( SOCKSTREAMBUF_PUTBACK_SIZE ) { // update local copy of the socket data _socket = socket; // initialise defaults init_defaults(); // initialise internal buffers init_buffers(); } sockstreambuf::~sockstreambuf() { // close any open sockets close(); // cleanup buffers cleanup_buffers(); // cleanup timeout if ( _timeout ) { delete _timeout; } } void sockstreambuf::init_defaults() throw() { // timeout structure reference _timeout = NULL; // timed-out status _timed_out = false; } void sockstreambuf::open( socket_domain_t domain, socket_type_t type, socket_protocol_t proto ) throw( sockexception ) { // create a communication endpoint _socket = ::socket( domain, type, proto ); // sanity check if ( _socket == -1 ) { throw sockexception(); } #ifdef SO_NOSIGPIPE // suppress SIGPIPE (Mac OSX) int optval = 1; if ( setsockopt( _socket, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof( optval ) ) != 0 ) { throw sockexception(); } #endif } void sockstreambuf::close() throw() { // sanity check if ( _socket > -1 ) { // sync sync(); // close the socket ::close( _socket ); // update socket data _socket = -1; } } void sockstreambuf::connect( const sockaddr * dest_addr, unsigned int timeout ) throw( sockexception, socktimeoutexception ) { timeval t_val; timeval * t_ptr; // check timeout value if ( timeout > 0 ) { // setup timeval structure t_val.tv_sec = timeout; t_val.tv_usec = 0; // update pointer t_ptr = &t_val; } else { // fall-back to class value t_ptr = _timeout; } // call overloaded connect() connect( dest_addr, t_ptr ); } void sockstreambuf::connect( const sockaddr * dest_addr, timeval * timeout ) throw( sockexception, socktimeoutexception ) { // copy current flags int s_flags = fcntl( _socket, F_GETFL ); // sanity check - affectively we ignore the fcntl() error if ( s_flags == -1 ) { s_flags = 0; } // setup timeout if needed if ( timeout ) { // make the socket non-blocking if ( fcntl( _socket, F_SETFL, ( s_flags | O_NONBLOCK ) ) == -1 ) { throw sockexception(); } } // connect if ( ::connect( _socket, dest_addr->psockaddr(), dest_addr->size() ) != 0 ) { throw sockexception(); } // check for timeout if set if ( timeout ) { if (! ready( timeout ) ) { // shutdown ::shutdown( _socket, 2 ); // throw a timeout exception if ( _timed_out ) { throw socktimeoutexception( timeout, "sockstreambuf::connect()" ); } } // reset flags back to what they were fcntl( _socket, F_SETFL, s_flags ); } } void sockstreambuf::bind( const sockaddr * bind_addr, bool reuse_addr ) throw( sockexception ) { // set socket options - SO_REUSEADDR if ( reuse_addr ) { int optval = 1; if ( setsockopt( _socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof( optval ) ) != 0 ) { throw sockexception(); } } // bind if ( ::bind( _socket, bind_addr->psockaddr(), bind_addr->size() ) != 0 ) { throw sockexception(); } } void sockstreambuf::listen( int backlog ) throw( sockexception ) { if ( ::listen( _socket, backlog ) != 0 ) { throw sockexception(); } } sockstreambuf::socket_t sockstreambuf::accept() throw( sockexception ) { socket_t peer_sock; if ( ( peer_sock = ::accept( _socket, 0, 0 ) ) < 0 ) { throw sockexception(); } return peer_sock; } const sockstreambuf::socket_t & sockstreambuf::socket() const throw() { return _socket; } const timeval * sockstreambuf::timeout( time_t sec, suseconds_t usec ) throw() { _timeout = new timeval; _timeout->tv_sec = sec; _timeout->tv_usec = usec; return _timeout; } void * sockstreambuf::clear_timeout() throw() { // sanity check if ( _timeout ) { // delete structure delete _timeout; // set a null pointer _timeout = NULL; } return _timeout; } bool sockstreambuf::timedout() const throw() { return _timed_out; } void sockstreambuf::init_buffers() throw() { // allocate output buffer space char * pbuf = new char[_bufsize]; // allocate input buffer space char * gbuf = new char[_bufsize]; // setup output buffer setp( pbuf, pbuf + ( _bufsize - 1 ) ); // setup input buffer setg( gbuf, gbuf, gbuf ); } void sockstreambuf::cleanup_buffers() throw() { // cleanup output buffer delete [] pbase(); // cleanup input buffer delete [] eback(); } int sockstreambuf::flush() throw( socktimeoutexception ) { int flush_size = pptr() - pbase(); bool b_ready = false; // sanity check if ( flush_size > 0 ) { try { b_ready = ready( _timeout, false, true ); } catch ( sockexception &e ) { // couldn't select the socket return eof; } if ( b_ready ) { if ( ::send( _socket, pbase(), flush_size, MSG_NOSIGNAL ) == flush_size ) { pbump( -flush_size ); return flush_size; } } else { // timed out - throw a timeout exception if ( _timed_out ) { throw socktimeoutexception( _timeout, "sockstreambuf::flush()" ); } } } return eof; } int sockstreambuf::sync() throw() { try { // flush buffer if ( flush() != eof ) { return 0; } } catch ( socktimeoutexception &e ) { // communication timeout - suppress the exception } // sync failed return -1; } int sockstreambuf::overflow( int c ) throw( socktimeoutexception ) { // sanity check if ( c != eof ) { // insert the overflowed char into the buffer *pptr() = c; pbump( 1 ); } // flush the buffer - could throw a timeout exception if ( flush() == eof ) { return eof; } return c; } int sockstreambuf::underflow() throw( socktimeoutexception ) { // sanity check - read position before end-of-buffer? if ( gptr() < egptr() ) { return traits_type::to_int_type( *gptr() ); } char * read_buffer; size_t putback_size = gptr() - eback(); size_t readable_size = 0; bool b_ready = false; ssize_t read_size = 0; // sanitise putback size if ( putback_size > _putbacksize ) { putback_size = _putbacksize; } // update read buffer position read_buffer = eback() + putback_size; // calculate read buffer size readable_size = _bufsize - putback_size; // check for availability try { b_ready = ready( _timeout, true, false ); } catch ( sockexception &e ) { // couldn't select the socket return eof; } // read from socket if ( b_ready ) { read_size = ::read( _socket, read_buffer, readable_size ); } else { // timed out - throw a timeout exception if ( _timed_out ) { throw socktimeoutexception( _timeout, "sockstreambuf::overflow()" ); } } // sanity check if ( read_size <= 0 ) { return eof; } // update pointers setg( eback(), read_buffer, read_buffer + read_size ); // return next character return traits_type::to_int_type( *gptr() ); } bool sockstreambuf::ready( timeval * timeout, bool chk_read, bool chk_write ) throw( sockexception ) { // sanity check if ( _socket < 0 ) { throw sockexception( "sockstreambuf::ready(): invalid socket" ); } fd_set fds; fd_set * read_fds = 0; fd_set * write_fds = 0; // timespec structure timespec * t_spec = 0; // set the fd_set so we only check our socket memset( &fds, 0, sizeof( fds ) ); FD_SET( _socket, &fds ); // set the actions we want to check if ( chk_read ) { read_fds = &fds; } if ( chk_write ) { write_fds = &fds; } // reset timed-out status _timed_out = false; // create timespec structure from timeval structure if ( timeout ) { t_spec = new timespec; t_spec->tv_sec = timeout->tv_sec; t_spec->tv_nsec = ( timeout->tv_usec * 1000 ); } // select the socket int s_status = ::pselect( ( _socket + 1 ), read_fds, write_fds, 0, t_spec, 0 ); // cleanup if ( t_spec != 0 ) { delete t_spec; } // check status switch ( s_status ) { case 0: // timed-out _timed_out = true; break; case -1: throw sockexception(); break; default: break; } // sanity check if ( FD_ISSET( _socket, &fds ) ) { return true; } return false; } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/sockstreambuf.h000066400000000000000000000246351331043112200210450ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_SOCKSTREAMBUF_H #define PSOCKSXX_SOCKSTREAMBUF_H #include #include #include #include #include #include #ifndef SOCKSTREAMBUF_SIZE #define SOCKSTREAMBUF_SIZE 1024 #endif #ifndef SOCKSTREAMBUF_PUTBACK_SIZE #define SOCKSTREAMBUF_PUTBACK_SIZE 8 #endif namespace psocksxx { /** * @brief Socket stream buffer class * * This buffer class associates its both input and output * sequences with an external POSIX socket. */ class sockstreambuf : public std::streambuf { public: /** socket data type definition */ typedef int socket_t; /** socket end-of-file type */ enum eof_t { eof = -1 /*!< end of file */ }; /** socket domains type definition */ enum socket_domain_t { pf_local = PF_LOCAL, /*!< Host-internal protocols */ pf_inet = PF_INET, /*!< Internet version 4 protocols */ pf_route = PF_ROUTE, /*!< Internal Routing protocol */ pf_key = PF_KEY, /*!< Internal key-management function */ pf_inet6 = PF_INET6 /*!< Internet version 6 protocols */ }; /** socket types type definition */ enum socket_type_t { sock_stream = SOCK_STREAM, sock_dgram = SOCK_DGRAM, sock_raw = SOCK_RAW, sock_rdm = SOCK_RDM, sock_seqpacket = SOCK_SEQPACKET }; /** socket protocols type definition */ enum socket_protocol_t { proto_unspec = 0, /*!< Unspecified system default */ ipproto_ip = IPPROTO_IP, /*!< Internet protocol */ ipproto_ipv6 = IPPROTO_IPV6, /*!< Internet Protocol Version 6 */ ipproto_icmp = IPPROTO_ICMP, /*!< Control message protocol */ ipproto_raw = IPPROTO_RAW, /*!< Raw IP Packets Protocol */ ipproto_tcp = IPPROTO_TCP, /*!< Transmission control protocol */ ipproto_udp = IPPROTO_UDP /*!< User datagram protocol */ }; sockstreambuf() throw(); //!< constructor virtual ~sockstreambuf(); //!< destructor /** * @brief overloaded constructor * @param socket socket data * * Create an instance with the passed in sockstreambuf::socket_t * type socket. It is assumed that the socket is initialised and * ready to use. * */ sockstreambuf( socket_t socket ) throw(); /** * @brief get internal socket data * @return socket data * * Returns a read-only reference to the internal POSIX socket * data. * */ const socket_t & socket() const throw(); /** * @brief open a socket * @param domain communications domain for the socket * @param type socket communications type * @param proto socket communications protocol * @throw psocksxx::sockexception socket exception * * Open a socket and initialise socket communications. * */ void open( socket_domain_t domain, socket_type_t type, socket_protocol_t proto = proto_unspec ) throw( sockexception ); /** * @brief close open sockets * * Close any open socket connections used by this buffer. This * will also flush any data in the buffer before closing. * */ void close() throw(); /** * @brief flush the socket output buffer * @return number of characters flushed * @throw psocksxx::socktimeoutexception on socket timeout * * Flush the socket buffer by writing date into the * socket and returns the number of characters flushed. * If the output buffer is empty sockstreambuf::eof is returned. * */ virtual int flush() throw( socktimeoutexception ); /** * @brief initiate a connection on a socket * @param dest_addr destination address to connect to * @param timeout connection timeout value in seconds * @throw psocksxx::sockexception socket exception * @throw psocksxx::socktimeoutexception connection timeout * exception * * Initiate a connection on a socket previously opened using * open() method. If the timeout value is 0 (default) then * the timeouts are ignored. * */ void connect( const sockaddr * dest_addr, unsigned int timeout = 0 ) throw( sockexception, socktimeoutexception ); /** * @brief initiate a connection on a socket * @param dest_addr destination address to connect to * @param timeout connection timeout value as a reference to a * @c timeval structure * * @throw psocksxx::sockexception socket exception * @throw psocksxx::socktimeoutexception connection timeout * exception * * Initiate a connection on a socket previously opened using * open() method. * */ void connect( const sockaddr * dest_addr, timeval * timeout ) throw( sockexception, socktimeoutexception ); /** * @brief bind the socket to a specified address * @param bind_addr address to bind to * @param reuse_addr allow address to be re-used * @throw psocksxx::sockexception socket exception * * After a socket is configured using open() this method can * be used to assign an address to it. If @c reuse_addr is set * to @c true then this will try to re-use the address unless * the address is actively listening. * */ void bind( const sockaddr * bind_addr, bool reuse_addr = false ) throw( sockexception ); /** * @brief make the socket passive and capable of accepting connections * @param backlog maximum length of the queue for pending connections * and defaults to SOMAXCONN (128) defined in @c * * @throw psocksxx::sockexception socket exception * * This method will make the currently opened socket connection * to passive and capable of accepting client connections using accept() * method. * */ void listen( int backlog = SOMAXCONN ) throw( sockexception ); /** * @brief accept a connection on a listening (passive) socket * @throw psocksxx::sockexception socket exception * @return peer socket data structure * * This method will accept incoming connections on a socket * set to be passive using the listen() method. Upon success * this will return the peer socket data structure that can be used * to create a socket stream buffer instance to communicate * with the accepted socket connection. * */ socket_t accept() throw( sockexception ); /** * @brief set the timeout value for the socket * @param sec seconds * @param usec microseconds * @return a reference to the internal timeout structure * * This method will set the timeout for the socket and make this * a non-blocking socket. Note that you cannot clear the timeout * by passing in a 0 timeout, use clear_timeout() method instead. * */ const timeval * timeout( time_t sec, suseconds_t usec ) throw(); /** * @brief clear the timeout value for the socket * @return a reference to the internal timeout structure which will * always be a null-pointer (@c 0) after clearing the timeout * * This will clear any timeout values set for the socket affectively * making this a blocking socket by default. * */ void * clear_timeout() throw(); /** * @brief get the timed-out status * @return boolean @c true if timed-out flag is set or @c false * otherwise. * * Returns the timed-out status. * */ bool timedout() const throw(); protected: /** * @brief initialise internal buffers */ void init_buffers() throw(); /** * @brief cleanup internal buffers */ void cleanup_buffers() throw(); /** * @brief sync data with the socket * @return 0 or -1 to denote success or failure * * Synchronise the buffer with the associated socket * by flushing data from the buffer to the socket. * */ virtual int sync() throw(); /** * @brief consumes the buffer by writing the contents to * the socket * * @param c additional character to consume * @return sockstreambuf::eof to indicate failure or @a c * if successful. * * @throw psocksxx::socktimeoutexception on socket timeout * * * Consumes the buffer contents and writes to the opened socket. * If @a c is not sockstreambuf::eof then @a c is also written * out. * */ virtual int overflow( int c = eof ) throw( socktimeoutexception ); /** * @brief read more data into the buffer from the socket * @return the first character from the buffer or sockstreambuf::eof * if no data is available to read * * @throw psocksxx::socktimeoutexception on socket timeout * * * This reads more data into the buffer from the socket when * the input buffer is empty and returns the next readable * character from the buffer. If the buffer is empty and no * data is available through the socket, this returns sockstreambuf::eof. * */ virtual int underflow() throw( socktimeoutexception ); /** * @brief check for the read/write availability on the socket * @param timeout timeout value reference to a @c timeval structure * @param chk_read check for read availability * @param chk_write check for write availability * @throw psocksxx::sockexception socket exception * @return boolean @c true to denote availability or @c false * if none of the checked actions are available. * * This will check the socket for read and/or write availability. * */ bool ready( timeval * timeout, bool chk_read = true, bool chk_write = true ) throw( sockexception ); private: /** POSIX socket data */ socket_t _socket; size_t _bufsize; size_t _putbacksize; timeval * _timeout; bool _timed_out; void init_defaults() throw(); }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_SOCKSTREAMBUF_H */ psocksxx-1.1.1/lib/psocksxx/socktimeoutexception.cpp000066400000000000000000000025611331043112200230070ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "socktimeoutexception.h" #include namespace psocksxx { socktimeoutexception::socktimeoutexception( const char * message ) throw() { _message = message; } socktimeoutexception::socktimeoutexception( const timeval * t_val, const char * method ) throw() { // string stream std::stringstream ss; if ( method != 0 ) { ss << method << " "; } ss << "timed out (" << t_val->tv_sec << "." << t_val->tv_usec << "s)"; // update exception message _message = ss.str(); } socktimeoutexception::~socktimeoutexception() throw() { } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/socktimeoutexception.h000066400000000000000000000034271331043112200224560ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_SOCKTIMEOUTEXCEPTION_H #define PSOCKSXX_SOCKTIMEOUTEXCEPTION_H #include #include namespace psocksxx { /** * @brief Socket timeout exception * * This acts as the socket timeout exception class. * */ class socktimeoutexception : public sockexception { public: /** * @brief constructor * @param message exception message * * Create an timeout exception instance with the passed in exception * message. * */ socktimeoutexception( const char * message ) throw(); /** * @brief constructor * @param t_val timed-out value * @param method action/method that timed-out * * This will take the passed in timed-out value and the action * to construct the exception message. * */ socktimeoutexception( const timeval * t_val, const char * method = 0 ) throw(); virtual ~socktimeoutexception() throw(); //!< destructor }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_SOCKTIMEOUTEXCEPTION_H */ psocksxx-1.1.1/lib/psocksxx/tcpnsockstream.cpp000066400000000000000000000020501331043112200215530ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "tcpnsockstream.h" namespace psocksxx { tcpnsockstream::tcpnsockstream() throw( sockexception ) : nsockstream( sockstreambuf::sock_stream, sockstreambuf::ipproto_tcp ) { } tcpnsockstream::~tcpnsockstream() throw() { } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/tcpnsockstream.h000066400000000000000000000026271331043112200212320ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_TCPNSOCKSTREAM_H #define PSOCKSXX_TCPNSOCKSTREAM_H #include namespace psocksxx { /** * @brief TCP/IP controller class * * This acts as the controller for TCP/TP communication streams. * */ class tcpnsockstream : public nsockstream { public: /** * @brief constructor * @throw psocksxx::sockexception socket exception * * Initialise a TCP/IP communication stream. * */ tcpnsockstream() throw( sockexception ); /** * @brief destructor */ virtual ~tcpnsockstream() throw(); }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_TCPNSOCKSTREAM_H */ psocksxx-1.1.1/lib/psocksxx/udpnsockstream.cpp000066400000000000000000000020471331043112200215630ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "udpnsockstream.h" namespace psocksxx { udpnsockstream::udpnsockstream() throw( sockexception ) : nsockstream( sockstreambuf::sock_dgram, sockstreambuf::ipproto_udp ) { } udpnsockstream::~udpnsockstream() throw() { } } /* end of namespace psocksxx */ psocksxx-1.1.1/lib/psocksxx/udpnsockstream.h000066400000000000000000000026671331043112200212400ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef PSOCKSXX_UDPNSOCKSTREAM_H #define PSOCKSXX_UDPNSOCKSTREAM_H #include namespace psocksxx { /** * @brief UDP over IPv4 controller class * * This acts as the controller class for UDP over IPv4 communication * streams. * */ class udpnsockstream : public nsockstream { public: /** * @brief constructor * @throw psocksxx::sockexception socket exception * * Initialise a UDP communication stream over IPv4. * */ udpnsockstream() throw( sockexception ); /** * @brief destructor */ virtual ~udpnsockstream() throw(); }; } /* end of namespace psocksxx */ #endif /* !PSOCKSXX_UDPNSOCKSTREAM_H */ psocksxx-1.1.1/psocksxx.pc.in000066400000000000000000000004131331043112200161730ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: @PACKAGE@ Description: A C++ wrapper for POSIX sockets Version: @VERSION@ URL: https://github.com/uditha-atukorala/psocksxx Libs: -L${libdir} -lpsocksxx Cflags: -I${includedir} psocksxx-1.1.1/src/000077500000000000000000000000001331043112200141515ustar00rootroot00000000000000psocksxx-1.1.1/src/Makefile.am000066400000000000000000000000531331043112200162030ustar00rootroot00000000000000## [psocksxx] src/ SUBDIRS = \ examples psocksxx-1.1.1/src/examples/000077500000000000000000000000001331043112200157675ustar00rootroot00000000000000psocksxx-1.1.1/src/examples/Makefile.am000066400000000000000000000000601331043112200200170ustar00rootroot00000000000000## [psocksxx] src/examples/ SUBDIRS = \ echo psocksxx-1.1.1/src/examples/echo/000077500000000000000000000000001331043112200167055ustar00rootroot00000000000000psocksxx-1.1.1/src/examples/echo/Makefile.am000066400000000000000000000005211331043112200207370ustar00rootroot00000000000000## [psocksxx] src/examples/echo/ AM_CPPFLAGS = -I$(top_srcdir)/lib noinst_PROGRAMS = echo-server echo-client echo_server_LDADD = \ $(top_builddir)/lib/psocksxx/libpsocksxx.la echo_client_LDADD = \ $(top_builddir)/lib/psocksxx/libpsocksxx.la echo_server_SOURCES = \ server.cpp echo_client_SOURCES = \ client.cpp psocksxx-1.1.1/src/examples/echo/client.cpp000066400000000000000000000025611331043112200206730ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013-2015 Uditha Atukorala * * This file is part of psocksxx software library. * * psocksxx software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include #include #include int main() { // tcp socket stream psocksxx::tcpnsockstream ss; // connect try { ss.connect( "localhost", 21555 ); } catch ( psocksxx::sockexception &e ) { std::cerr << "[client] failed to connect to socket, exception" << e.what() << std::endl; return 1; } // send a message ss << "hello" << std::endl; // get the echo back from server std::string msg; ss >> msg; // print message std::cout << "[server] " << msg << std::endl; return 0; } psocksxx-1.1.1/src/examples/echo/server.cpp000066400000000000000000000034121331043112200207170ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013-2015 Uditha Atukorala * * This file is part of psocksxx software library. * * psocksxx software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include #include #include int main( int argc, char **argv ) { // tcp socket stream psocksxx::tcpnsockstream ss; // network address to bind to psocksxx::nsockaddr naddr( "localhost", "21555" ); // bind try { ss.bind( &naddr, true ); } catch( psocksxx::sockexception &e ) { std::cerr << "[server] failed to bind to socket, exception: " << e.what() << std::endl; return 1; } // listen try { ss.listen(); } catch( psocksxx::sockexception &e ) { std::cerr << "[server] failed to listen on socket, exception: " << e.what() << std::endl; return 1; } // client socket stream psocksxx::nsockstream * css; // message buffer std::string msg; for (;;) { // accept a new client css = ss.accept(); (* css) >> msg; std::cout << "[client] " << msg << std::endl; // echo back (* css) << msg << std::endl; // close/cleanup client delete css; } return 0; } psocksxx-1.1.1/test/000077500000000000000000000000001331043112200143415ustar00rootroot00000000000000psocksxx-1.1.1/test/Makefile.am000066400000000000000000000020071331043112200163740ustar00rootroot00000000000000## [psocksxx] test/ AUTOMAKE_OPTIONS = subdir-objects TESTS = TEST_EXTENSIONS = .tap TAP_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ $(top_srcdir)/aux-build/tap-driver.sh if HAVE_CPPUNIT check_PROGRAMS = tap-runner.tap TESTS += $(check_PROGRAMS) CPPUNIT_TEST_SOURCES = \ lecho.h lecho.cpp \ necho.h necho.cpp \ socktimeoutexception_test.h socktimeoutexception_test.cpp \ sockstreambuf_test.h sockstreambuf_test.cpp \ lsockstream_test.h lsockstream_test.cpp \ nsockaddr_test.h nsockaddr_test.cpp \ nsockstream_test.h nsockstream_test.cpp \ tcpnsockstream_test.h tcpnsockstream_test.cpp \ udpnsockstream_test.h udpnsockstream_test.cpp tap_runner_tap_SOURCES = \ tap-runner.cpp \ $(CPPUNIT_TEST_SOURCES) \ tap/tap_listener.h tap/tap_listener.cpp tap_runner_tap_CXXFLAGS = -I$(top_srcdir)/lib $(CPPUNIT_CFLAGS) tap_runner_tap_LDFLAGS = $(top_builddir)/lib/psocksxx/libpsocksxx.la $(CPPUNIT_LIBS) endif # remove xunit XML output files CLEANFILES = xunit.xml psocksxx-1.1.1/test/lecho.cpp000066400000000000000000000073551331043112200161510ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "lecho.h" #include #include #include #include #include #include lecho::lecho( const char * path ) : _sockfd( -1 ), _lsock_path( path ) { // fork _cpid = fork(); if ( _cpid == -1 ) { std::cerr << "failed to fork out child process" << std::endl; } else if ( _cpid == 0 ) { // child - initialise echo server on a local socket init_listener(); // serve requests serve_requests(); // exit - should never get here exit( 0 ); } else { // parent - wait for the child to create the socket and return wait_connect(); } } lecho::~lecho() { // cleanup shutdown(); } void lecho::init_listener() { // initialise socket if ( ( _sockfd = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 ) { std::cerr << "failed to setup local socket" << std::endl; exit( -1 ); } // socket address sockaddr_un saddr; bzero( (void *) &saddr, sizeof( saddr ) ); saddr.sun_family = AF_LOCAL; strcpy( saddr.sun_path, _lsock_path ); // bind if ( bind( _sockfd, (::sockaddr *) &saddr, sizeof( sockaddr_un ) ) != 0 ) { std::cerr << "failed to bind to local socket" << std::endl; exit( -1 ); } // listen if ( listen( _sockfd, 2 ) != 0 ) { std::cerr << "failed to listen on local socket" << std::endl; exit( -1 ); } } void lecho::serve_requests() { int peer_sockfd; sockaddr_un peer_addr; socklen_t addrlen = sizeof( peer_addr ); int n = 0; char cbuffer[64]; bool close_peer; for (;;) { if ( ( peer_sockfd = accept( _sockfd, (sockaddr *) &peer_addr, &addrlen ) ) == -1 ) { continue; } close_peer = false; do { // read from the socket n = recv( peer_sockfd, cbuffer, sizeof( cbuffer ), 0 ); // sanity check - did we receive anything? if ( n <= 0 ) { close_peer = true; } else { // send back what we received if ( send( peer_sockfd, cbuffer, n, 0 ) < 0 ) { close_peer = true; } } } while (! close_peer ); // close peer close( peer_sockfd ); } } void lecho::shutdown() { if ( _cpid == 0 ) { // child - should never get here } else { // parent - send kill to child kill( _cpid, SIGTERM ); } // unlink unlink( _lsock_path ); } void lecho::wait_connect() { int sockfd = -1; unsigned int max_tries = 10; sockaddr_un saddr; // initialise socket if ( ( sockfd = socket( PF_LOCAL, SOCK_STREAM, 0 ) ) < 0 ) { std::cerr << "failed to setup local socket" << std::endl; exit( -1 ); } // socket address structure bzero( (void *) &saddr, sizeof( saddr ) ); saddr.sun_family = AF_LOCAL; strcpy( saddr.sun_path, _lsock_path ); // loop until we can establish a connection or // we exhaust our attempts for ( int i = 0; i < max_tries; i++ ) { // try to connect if ( ( connect( sockfd, (sockaddr *) &saddr, sizeof( sockaddr_un ) ) == -1 ) ) { // connect failed - sleep for a bit usleep( 500 ); } else { // connect successful - break out of the loop break; } } // close socket close( sockfd ); } psocksxx-1.1.1/test/lecho.h000066400000000000000000000020751331043112200156100ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef LECHO_H #define LECHO_H #include class lecho { public: lecho( const char * path ); ~lecho(); private: int _sockfd; pid_t _cpid; const char * _lsock_path; void init_listener(); void serve_requests(); void shutdown(); void wait_connect(); }; #endif /* !LECHO_H */ psocksxx-1.1.1/test/lsockstream_test.cpp000066400000000000000000000051131331043112200204330ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "lsockstream_test.h" #include "lecho.h" #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( lsockstream_test ); // use namespace psocksxx using namespace psocksxx; void lsockstream_test::test_constructors() { // default constructor CPPUNIT_ASSERT_NO_THROW( lsockstream l ); } void lsockstream_test::test_connect_fail() { // local socket stream lsockstream l; // this should throw a file not found error CPPUNIT_ASSERT_THROW( l.connect( LOCAL_SOCK_PATH ), sockexception ); } void lsockstream_test::test_connect_addr_fail() { // local socket stream lsockstream l; // local (unix) socket address lsockaddr saddr( LOCAL_SOCK_PATH ); // this should throw a file not found error CPPUNIT_ASSERT_THROW( l.connect( &saddr ), sockexception ); } void lsockstream_test::test_connect() { // local socket stream lsockstream l; // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // connect CPPUNIT_ASSERT_NO_THROW( l.connect( LOCAL_LISTENER_SOCK_PATH ) ); } void lsockstream_test::test_connect_addr() { // local socket stream lsockstream l; // local (unix) socket address lsockaddr saddr( LOCAL_LISTENER_SOCK_PATH ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // connect CPPUNIT_ASSERT_NO_THROW( l.connect( &saddr ) ); } void lsockstream_test::test_read_timeout() { // local socket stream lsockstream l; // local (unix) socket address lsockaddr saddr( LOCAL_LISTENER_SOCK_PATH ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // connect try { l.connect( &saddr ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // set timeout l.timeout( 0, 200 ); // read char c = l.get(); // read - should timed out CPPUNIT_ASSERT( true == l.timedout() ); } psocksxx-1.1.1/test/lsockstream_test.h000066400000000000000000000031751331043112200201060ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef LSOCKSTREAM_TEST_H #define LSOCKSTREAM_TEST_H #include #ifndef LOCAL_LISTENER_SOCK_PATH #define LOCAL_LISTENER_SOCK_PATH "/tmp/psocksxx.listener.sock" #endif #ifndef LOCAL_SOCK_PATH #define LOCAL_SOCK_PATH "/tmp/psocksxx.sock" #endif class lsockstream_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( lsockstream_test ); CPPUNIT_TEST( test_constructors ); CPPUNIT_TEST( test_connect_fail ); CPPUNIT_TEST( test_connect_addr_fail ); CPPUNIT_TEST( test_connect ); CPPUNIT_TEST( test_connect_addr ); CPPUNIT_TEST( test_read_timeout ); CPPUNIT_TEST_SUITE_END(); public: void test_constructors(); void test_connect_fail(); void test_connect_addr_fail(); void test_connect(); void test_connect_addr(); void test_read_timeout(); }; #endif /* !LSOCKSTREAM_TEST_H */ psocksxx-1.1.1/test/necho.cpp000066400000000000000000000117561331043112200161530ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "necho.h" #include #include #include #include #include #include #include static int sockfd = -1; void sigterm_handler( int sig, siginfo_t *siginfo, void *context ) { // close any open sockets if ( sockfd > -1 ) { close( sockfd ); } exit( EXIT_SUCCESS ); } necho::necho( const char * node, const char * service, int socket_type ) : _sockfd( -1 ), _nsock_node( node ), _nsock_service( service ), _socket_type( socket_type ) { // fork _cpid = fork(); if ( _cpid == -1 ) { std::cerr << "failed to fork out child process" << std::endl; } else if ( _cpid == 0 ) { // child - initialise signal handlers init_signal_handlers(); // echo socket init_listener(); // serve requests serve_requests(); // exit - should never get here exit( 0 ); } else { // parent - wait for the child to create the socket and return wait_connect(); } } necho::~necho() { // cleanup shutdown(); } void necho::init_signal_handlers() { struct sigaction sa; sigfillset( &sa.sa_mask ); sa.sa_sigaction = &sigterm_handler; sa.sa_flags = SA_SIGINFO; if ( sigaction( SIGTERM, &sa, 0 ) < 0 ) { std::cerr << "sigaction() failed: " << strerror( errno ) << std::endl; exit( EXIT_FAILURE ); } } void necho::init_listener() { addrinfo hints, * saddr_info; int status = 0; // setup hints memset( &hints, 0, sizeof ( hints ) ); hints.ai_family = AF_INET; hints.ai_socktype = _socket_type; if ( ( status = getaddrinfo( _nsock_node, _nsock_service, &hints, &saddr_info ) ) != 0 ) { std::cerr << "getaddrinfo() failed: " << gai_strerror( status ) << std::endl; exit( EXIT_FAILURE ); } // initialise socket if ( ( _sockfd = socket( saddr_info->ai_family, saddr_info->ai_socktype, saddr_info->ai_protocol ) ) < 0 ) { std::cerr << "failed to setup network socket" << std::endl; exit( EXIT_FAILURE ); } // update static variable used by signal handlers sockfd = _sockfd; // set SO_REUSEADDR to true so we can reuse the socket int optval = 1; if ( setsockopt( _sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof( optval ) ) != 0 ) { std::cerr << "setsockopt() failed: " << strerror( errno ) << std::endl; exit( EXIT_FAILURE ); } // bind if ( bind( _sockfd, saddr_info->ai_addr, saddr_info->ai_addrlen ) != 0 ) { std::cerr << "bind() failed: " << strerror( errno ) << std::endl; exit( EXIT_FAILURE ); } // listen if ( listen( _sockfd, 5 ) != 0 ) { std::cerr << "listen() failed: " << strerror( errno ) << std::endl; exit( EXIT_FAILURE ); } // cleanup freeaddrinfo( saddr_info ); } void necho::serve_requests() { int peer_sockfd; int n = 0; char cbuffer[64]; bool close_peer; for (;;) { if ( ( peer_sockfd = accept( _sockfd, 0, 0 ) ) == -1 ) { continue; } close_peer = false; do { // read from the socket n = recv( peer_sockfd, cbuffer, sizeof( cbuffer ), 0 ); // sanity check - did we receive anything? if ( n <= 0 ) { close_peer = true; } else { // send back what we received if ( send( peer_sockfd, cbuffer, n, 0 ) < 0 ) { close_peer = true; } } } while (! close_peer ); // close peer close( peer_sockfd ); } } void necho::wait_connect() { int sockfd = -1; int status = 0; unsigned int max_tries = 10; addrinfo hints, * saddr_info; // setup hints memset( &hints, 0, sizeof ( hints ) ); hints.ai_family = AF_INET; hints.ai_socktype = _socket_type; if ( ( status = getaddrinfo( _nsock_node, _nsock_service, &hints, &saddr_info ) ) != 0 ) { std::cerr << "getaddrinfo() failed: " << gai_strerror( status ) << std::endl; exit( EXIT_FAILURE ); } // loop until we can establish a connection or // we exhaust our attempts for ( int i = 0; i < max_tries; i++ ) { // try to connect if ( ( connect( sockfd, saddr_info->ai_addr, saddr_info->ai_addrlen ) == -1 ) ) { // connect failed - sleep for a bit usleep( 500 ); } else { // connect successful - break out of the loop break; } } // close socket close( sockfd ); } void necho::shutdown() { if ( _cpid == 0 ) { // child - should never get here } else { // parent - send kill to child kill( _cpid, SIGTERM ); // wait for the child waitpid( _cpid, 0, 0 ); } } psocksxx-1.1.1/test/necho.h000066400000000000000000000023471331043112200156140ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef NECHO_H #define NECHO_H #include #include class necho { public: necho( const char * node, const char * service, int socket_type = SOCK_STREAM ); virtual ~necho(); protected: int _sockfd; pid_t _cpid; const char * _nsock_node; const char * _nsock_service; int _socket_type; void init_signal_handlers(); void init_listener(); void serve_requests(); void shutdown(); void wait_connect(); }; #endif /* !NECHO_H */ psocksxx-1.1.1/test/nsockaddr_test.cpp000066400000000000000000000037001331043112200200540ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "nsockaddr_test.h" #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( nsockaddr_test ); // use namespace psocksxx using namespace psocksxx; void nsockaddr_test::test_constructor_localhost() { CPPUNIT_ASSERT_NO_THROW( nsockaddr a( "localhost", 1234 ) ); CPPUNIT_ASSERT_NO_THROW( nsockaddr a( "127.0.0.1", 4321 ) ); } void nsockaddr_test::test_constructor_remote() { CPPUNIT_ASSERT_NO_THROW( nsockaddr a( "www.example.com", 1234 ) ); CPPUNIT_ASSERT_NO_THROW( nsockaddr a( "1.2.3.4", 80 ) ); } void nsockaddr_test::test_constructor_fail() { CPPUNIT_ASSERT_THROW( nsockaddr a( "invalid.domain", 1234 ), sockexception ); CPPUNIT_ASSERT_THROW( nsockaddr a( "1.2.3.", 1234 ), sockexception ); } void nsockaddr_test::test_constructor_local_any() { CPPUNIT_ASSERT_NO_THROW( nsockaddr a( 1234 ) ); } void nsockaddr_test::test_constructor_local_service() { CPPUNIT_ASSERT_NO_THROW( nsockaddr a( "localhost", "1234" ) ); CPPUNIT_ASSERT_NO_THROW( nsockaddr a( 0, "ftp" ) ); } void nsockaddr_test::test_constructor_remote_service() { CPPUNIT_ASSERT_NO_THROW( nsockaddr a( "www.example.com", "http" ) ); } psocksxx-1.1.1/test/nsockaddr_test.h000066400000000000000000000030351331043112200175220ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef NSOCKADDR_TEST_H #define NSOCKADDR_TEST_H #include class nsockaddr_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( nsockaddr_test ); CPPUNIT_TEST( test_constructor_localhost ); CPPUNIT_TEST( test_constructor_remote ); CPPUNIT_TEST( test_constructor_fail ); CPPUNIT_TEST( test_constructor_local_any ); CPPUNIT_TEST( test_constructor_local_service ); CPPUNIT_TEST( test_constructor_remote_service ); CPPUNIT_TEST_SUITE_END(); public: void test_constructor_localhost(); void test_constructor_remote(); void test_constructor_fail(); void test_constructor_local_any(); void test_constructor_local_service(); void test_constructor_remote_service(); }; #endif /* !NSOCKADDR_TEST_H */ psocksxx-1.1.1/test/nsockstream_test.cpp000066400000000000000000000045251331043112200204430ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "nsockstream_test.h" #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( nsockstream_test ); // use namespace psocksxx using namespace psocksxx; void nsockstream_test::test_constructor_tcp() { // TCP/IP CPPUNIT_ASSERT_NO_THROW( nsockstream n( sockstreambuf::sock_stream, sockstreambuf::ipproto_tcp ) ); } void nsockstream_test::test_constructor_udp() { // UDP CPPUNIT_ASSERT_NO_THROW( nsockstream n( sockstreambuf::sock_dgram, sockstreambuf::ipproto_udp ) ); } void nsockstream_test::test_constructor_streambuf() { // socket stream buffer sockstreambuf * ssb = new sockstreambuf(); // network socket stream nsockstream ss( ssb ); // assert CPPUNIT_ASSERT( ssb == ss.rdbuf() ); } void nsockstream_test::test_set_timeout() { // socket stream buffer sockstreambuf * ssb = new sockstreambuf(); // network socket stream nsockstream ss( ssb ); time_t sec = 1; suseconds_t usec = 500; // set timeout const timeval * t = ss.timeout( sec, usec ); // validate CPPUNIT_ASSERT( sec == t->tv_sec ); CPPUNIT_ASSERT( usec == t->tv_usec ); } void nsockstream_test::test_clear_timeout() { // socket stream buffer sockstreambuf * ssb = new sockstreambuf(); // network socket stream nsockstream ss( ssb ); // clear the timeout before a timeout is set CPPUNIT_ASSERT( 0 == ss.clear_timeout() ); time_t sec = 1; suseconds_t usec = 500; // set timeout const timeval * t = ss.timeout( sec, usec ); // clear the timeout after a timeout is set CPPUNIT_ASSERT( 0 == ss.clear_timeout() ); } psocksxx-1.1.1/test/nsockstream_test.h000066400000000000000000000026301331043112200201030ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef NSOCKSTREAM_TEST_H #define NSOCKSTREAM_TEST_H #include class nsockstream_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( nsockstream_test ); CPPUNIT_TEST( test_constructor_tcp ); CPPUNIT_TEST( test_constructor_udp ); CPPUNIT_TEST( test_constructor_streambuf ); CPPUNIT_TEST( test_set_timeout ); CPPUNIT_TEST( test_clear_timeout ); CPPUNIT_TEST_SUITE_END(); public: void test_constructor_tcp(); void test_constructor_udp(); void test_constructor_streambuf(); void test_set_timeout(); void test_clear_timeout(); }; #endif /* !NSOCKSTREAM_TEST_H */ psocksxx-1.1.1/test/sockstreambuf_test.cpp000066400000000000000000000275401331043112200207640ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "sockstreambuf_test.h" #include "lecho.h" #include #include #include #include #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( sockstreambuf_test ); // use namespace psocksxx using namespace psocksxx; sockstreambuf_test::sockstreambuf_test() { } sockstreambuf_test::~sockstreambuf_test() { } void sockstreambuf_test::connect_local() throw() { int csock; sockaddr_un saddr; const char * path = LOCAL_SOCK_PATH; bzero( (void *) &saddr, sizeof( saddr ) ); saddr.sun_family = AF_LOCAL; strcpy( saddr.sun_path, path ); // not worth having error handling here so we hope for the best csock = socket( AF_LOCAL, SOCK_STREAM, 0 ); connect( csock, (::sockaddr *) &saddr, sizeof( sockaddr_un ) ); } void sockstreambuf_test::setUp() { // initialise locals _sockaddr.sa_family = AF_LOCAL; } void sockstreambuf_test::tearDown() { } void sockstreambuf_test::test_constructors() { const sockstreambuf ssb; const sockstreambuf ssb_s( -1 ); // check the default constructor CPPUNIT_ASSERT( ssb.socket() == ssb_s.socket() ); } void sockstreambuf_test::test_open_close_local_ip() { sockstreambuf ssb; CPPUNIT_ASSERT_NO_THROW_MESSAGE( "Failed to open socket communication end-point", ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::ipproto_ip ) ); // close the opened socket end-point ssb.close(); } void sockstreambuf_test::test_flush_empty() { sockstreambuf ssb( -1 ); CPPUNIT_ASSERT( sockstreambuf::eof == ssb.flush() ); } void sockstreambuf_test::test_bad_flush() { // socket stream buffer sockstreambuf ssb( -1 ); // add a char into the buffer ssb.sputc( 'c' ); // flush buffer CPPUNIT_ASSERT( sockstreambuf::eof == ssb.flush() ); } void sockstreambuf_test::test_bad_connect_failure() { // socket stream buffer sockstreambuf ssb( -1 ); // this should throw a bad file descriptor error CPPUNIT_ASSERT_THROW( ssb.connect( &_sockaddr ), sockexception ); } void sockstreambuf_test::test_bad_bind_failure() { // socket stream buffer sockstreambuf ssb( -1 ); // this should throw a bad file descriptor error CPPUNIT_ASSERT_THROW( ssb.bind( &_sockaddr ), sockexception ); } void sockstreambuf_test::test_bad_listen_failure() { // socket stream buffer sockstreambuf ssb( -1 ); // this should throw a bad file descriptor error CPPUNIT_ASSERT_THROW( ssb.listen(), sockexception ); } void sockstreambuf_test::test_bad_accept_failure() { // socket stream buffer sockstreambuf ssb( -1 ); // this should throw a bad file descriptor error CPPUNIT_ASSERT_THROW( ssb.accept(), sockexception ); } void sockstreambuf_test::test_local_bind() { // socket stream buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_SOCK_PATH; lsockaddr saddr( path ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // bind to address CPPUNIT_ASSERT_NO_THROW( ssb.bind( &saddr ) ); // close socket ssb.close(); // unlink if ( unlink( path ) !=0 ) { CPPUNIT_FAIL( std::string( "failed to unlink socket: " ).append( path ) ); } } void sockstreambuf_test::test_local_listen() { // socket stream buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_SOCK_PATH; lsockaddr saddr( path ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // bind to address try { ssb.bind( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); } // listen CPPUNIT_ASSERT_NO_THROW( ssb.listen() ); // close socket ssb.close(); // unlink if ( unlink( path ) !=0 ) { CPPUNIT_FAIL( std::string( "failed to unlink socket: " ).append( path ) ); } } void sockstreambuf_test::test_local_connect() { // socket steam buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect CPPUNIT_ASSERT_NO_THROW( ssb.connect( &saddr ) ); // close socket ssb.close(); } void sockstreambuf_test::test_local_connect_timeout() { // socket steam buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect CPPUNIT_ASSERT_NO_THROW( ssb.connect( &saddr, 1 ) ); // close socket ssb.close(); } void sockstreambuf_test::test_local_accept() { // fork variables pid_t cpid, wpid; int wpid_status; // socket stream buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_SOCK_PATH; lsockaddr saddr( path ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // bind to address try { ssb.bind( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); } // listen try { ssb.listen(); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); } // fork cpid = fork(); if ( cpid == -1 ) { CPPUNIT_FAIL( "failed to fork" ); } else if ( cpid == 0 ) { // child - connect to the local socket created by the parent connect_local(); // exit exit( 0 ); } else { // parent - accept a connection from the child CPPUNIT_ASSERT( ssb.accept() != -1 ); // wait for child to exit if ( ( wpid = waitpid( cpid, &wpid_status, 0 ) ) == -1 ) { CPPUNIT_FAIL( "failed waiting for the child process to terminate" ); } } // close socket ssb.close(); // unlink if ( unlink( path ) !=0 ) { CPPUNIT_FAIL( std::string( "failed to unlink socket: " ).append( path ) ); } } void sockstreambuf_test::test_local_flush() { // socket stream buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect try { ssb.connect( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // put a char into the buffer and flush ssb.sputc( 'c' ); CPPUNIT_ASSERT( 1 == ssb.flush() ); // close socket ssb.close(); } void sockstreambuf_test::test_local_flush_read() { // socket stream buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect try { ssb.connect( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // put a char into the buffer ssb.sputc( 'c' ); // flush if ( ssb.flush() == 1 ) { // read back CPPUNIT_ASSERT( 'c' == ssb.sgetc() ); } else { CPPUNIT_FAIL( "failed to flush buffer" ); } // close socket ssb.close(); } void sockstreambuf_test::test_local_ostream() { // socket stream buffer sockstreambuf ssb; // ostream std::ostream output( &ssb ); // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect try { ssb.connect( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // use the output stream to send a char output << 'c' << std::endl; // read back using the socket stream buffer CPPUNIT_ASSERT( 'c' == ssb.sgetc() ); // close socket ssb.close(); } void sockstreambuf_test::test_local_istream() { // socket stream buffer sockstreambuf ssb; // istream std::istream input( &ssb ); // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect try { ssb.connect( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // put a char into the buffer ssb.sputc( 'c' ); // flush if ( ssb.flush() == 1 ) { // read back using istream char c; input >> c; // assert CPPUNIT_ASSERT( 'c' == c ); } else { CPPUNIT_FAIL( "failed to flush buffer" ); } // close socket ssb.close(); } void sockstreambuf_test::test_set_timeout() { // socket stream buffer sockstreambuf ssb; time_t sec = 1; suseconds_t usec = 500; // set timeout const timeval * t = ssb.timeout( sec, usec ); // validate CPPUNIT_ASSERT( sec == t->tv_sec ); CPPUNIT_ASSERT( usec == t->tv_usec ); } void sockstreambuf_test::test_clear_timeout() { // socket stream buffer sockstreambuf ssb; // clear the timeout before a timeout is set CPPUNIT_ASSERT( 0 == ssb.clear_timeout() ); time_t sec = 1; suseconds_t usec = 500; // set timeout const timeval * t = ssb.timeout( sec, usec ); // clear the timeout after a timeout is set CPPUNIT_ASSERT( 0 == ssb.clear_timeout() ); } void sockstreambuf_test::test_local_read_timeout() { // socket stream buffer sockstreambuf ssb; // local (unix) socket address const char * path = LOCAL_LISTENER_SOCK_PATH; lsockaddr saddr( path ); // local echo server lecho echo( LOCAL_LISTENER_SOCK_PATH ); // prepare the socket try { ssb.open( sockstreambuf::pf_local, sockstreambuf::sock_stream, sockstreambuf::proto_unspec ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // connect try { ssb.connect( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // set timeout ssb.timeout( 0, 200 ); // read - this should timeout and throw a timeout exception CPPUNIT_ASSERT_THROW( ssb.sgetc(), socktimeoutexception ); // should've set the timed-out flag as well CPPUNIT_ASSERT( true == ssb.timedout() ); // close socket ssb.close(); } psocksxx-1.1.1/test/sockstreambuf_test.h000066400000000000000000000056571331043112200204360ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef SOCKSTREAMBUF_TEST_H #define SOCKSTREAMBUF_TEST_H #include #include #define LOCAL_LISTENER_SOCK_PATH "/tmp/psocksxx.listener.sock" #define LOCAL_SOCK_PATH "/tmp/psocksxx.sock" class sockstreambuf_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( sockstreambuf_test ); CPPUNIT_TEST( test_constructors ); CPPUNIT_TEST( test_open_close_local_ip ); CPPUNIT_TEST( test_flush_empty ); CPPUNIT_TEST( test_bad_flush ); CPPUNIT_TEST( test_bad_connect_failure ); CPPUNIT_TEST( test_bad_bind_failure ); CPPUNIT_TEST( test_bad_listen_failure ); CPPUNIT_TEST( test_bad_accept_failure ); CPPUNIT_TEST( test_local_bind ); CPPUNIT_TEST( test_local_listen ); CPPUNIT_TEST( test_local_connect ); CPPUNIT_TEST( test_local_connect_timeout ); CPPUNIT_TEST( test_local_accept ); CPPUNIT_TEST( test_local_flush ); CPPUNIT_TEST( test_local_flush_read ); CPPUNIT_TEST( test_local_ostream ); CPPUNIT_TEST( test_local_istream ); CPPUNIT_TEST( test_set_timeout ); CPPUNIT_TEST( test_clear_timeout ); CPPUNIT_TEST( test_local_read_timeout ); CPPUNIT_TEST_SUITE_END(); public: sockstreambuf_test(); ~sockstreambuf_test(); void setUp(); void tearDown(); void test_constructors(); void test_open_close_local_ip(); void test_flush_empty(); void test_bad_flush(); void test_bad_connect_failure(); void test_bad_bind_failure(); void test_bad_listen_failure(); void test_bad_accept_failure(); void test_local_bind(); void test_local_listen(); void test_local_connect(); void test_local_connect_timeout(); void test_local_accept(); void test_local_flush(); void test_local_flush_read(); void test_local_ostream(); void test_local_istream(); void test_set_timeout(); void test_clear_timeout(); void test_local_read_timeout(); private: // base sockaddr class for negative testing purposes struct : public psocksxx::sockaddr, public sockaddr { socklen_t size() const throw() { return sizeof( ::sockaddr ); } ::sockaddr * psockaddr() const throw() { return (::sockaddr *) this; } } _sockaddr; void connect_local() throw(); }; #endif /* !SOCKSTREAMBUF_TEST_H */ psocksxx-1.1.1/test/socktimeoutexception_test.cpp000066400000000000000000000033141331043112200223720ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "socktimeoutexception_test.h" #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( socktimeoutexception_test ); // use namespace psocksxx using namespace psocksxx; void socktimeoutexception_test::test_constructor_message() { std::string message = "test exception message"; socktimeoutexception tex( message.c_str() ); CPPUNIT_ASSERT( message == std::string( tex.what() ) ); } void socktimeoutexception_test::test_constructor_timeout() { timeval t; t.tv_sec = 1; t.tv_usec = 500; socktimeoutexception tex( &t ); CPPUNIT_ASSERT( std::string( "timed out (1.500s)" ) == std::string( tex.what() ) ); } void socktimeoutexception_test::test_constructor_timeout_method() { timeval t; t.tv_sec = 5; t.tv_usec = 230; socktimeoutexception tex( &t, "test()" ); CPPUNIT_ASSERT( std::string( "test() timed out (5.230s)" ) == std::string( tex.what() ) ); } psocksxx-1.1.1/test/socktimeoutexception_test.h000066400000000000000000000025421331043112200220410ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef SOCKTIMEOUTEXCEPTION_TEST_H #define SOCKTIMEOUTEXCEPTION_TEST_H #include class socktimeoutexception_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( socktimeoutexception_test ); CPPUNIT_TEST( test_constructor_message ); CPPUNIT_TEST( test_constructor_timeout ); CPPUNIT_TEST( test_constructor_timeout_method ); CPPUNIT_TEST_SUITE_END(); public: void test_constructor_message(); void test_constructor_timeout(); void test_constructor_timeout_method(); }; #endif /* !SOCKTIMEOUTEXCEPTION_TEST_H */ psocksxx-1.1.1/test/tap-runner.cpp000066400000000000000000000034101331043112200171360ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include #include #include #include #include #include "tap/tap_listener.h" int main( int argc, char * argv[] ) { // Get the top level suite from the registry CppUnit::Test * suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); // the event manager and test controller CppUnit::TestResult controller; // TAP listener tap::TAPListener listener( suite ); controller.addListener( &listener ); // register listener for collecting the test-results CppUnit::TestResultCollector collectedresults; controller.addListener( &collectedresults ); // test runner CppUnit::TestRunner runner; runner.addTest( suite ); // run tests. runner.run( controller ); // output XML for Jenkins xunit plugin std::ofstream xmloutput( "xunit.xml" ); CppUnit::XmlOutputter xmloutputter( &collectedresults, xmloutput ); xmloutputter.write(); return 0; } psocksxx-1.1.1/test/tap/000077500000000000000000000000001331043112200151255ustar00rootroot00000000000000psocksxx-1.1.1/test/tap/tap_listener.cpp000066400000000000000000000047071331043112200203320ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "tap_listener.h" #include #include #include #include namespace tap { TAPListener::TAPListener( CppUnit::Test * factory_suite ) : _factory_suite( factory_suite ), _test_success( false ) { // defaults _failure_msg = 0; CppUnit::TestSuite * s = (CppUnit::TestSuite *) _factory_suite; CppUnit::TestSuite * c; int total_tests = 0; // calculate total number of tests for ( int i = 0; i < s->getChildTestCount(); i++ ) { c = (CppUnit::TestSuite *) s->getChildTestAt( i ); total_tests += c->getChildTestCount(); } // output tap header std::cout << "1.." << total_tests << std::endl; } TAPListener::~TAPListener() { // destructor } void TAPListener::startSuite( CppUnit::Test * suite ) { // start test suite } void TAPListener::startTest( CppUnit::Test * test ) { _test_success = true; } void TAPListener::addFailure( const CppUnit::TestFailure &failure ) { CppUnit::Exception * e = failure.thrownException(); _failure_msg = new CppUnit::Message ( e->message() ); _test_success = false; } void TAPListener::endTest( CppUnit::Test * test ) { if ( _test_success ) { std::cout << "ok " << test->getName() << std::endl; } else { std::cout << "not ok " << test->getName() << std::endl; std::cout << "# " << _failure_msg->shortDescription() << std::endl; for ( int i = 0; i < _failure_msg->detailCount(); i++ ) { std::cout << "# \t" << _failure_msg->detailAt( i ) << std::endl; } // cleanup delete _failure_msg; } } void TAPListener::endSuite( CppUnit::Test * suite ) { // end test suite } } /* end of namespace tap */ psocksxx-1.1.1/test/tap/tap_listener.h000066400000000000000000000026761331043112200200020ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef TAP_TAP_LISTENER_H #define TAP_TAP_LISTENER_H #include #include namespace tap { class TAPListener : public CppUnit::TestListener { public: TAPListener( CppUnit::Test * factory_suite ); ~TAPListener(); void startSuite( CppUnit::Test * suite ); void startTest( CppUnit::Test * test ); void addFailure( const CppUnit::TestFailure &failure ); void endTest( CppUnit::Test * test); void endSuite( CppUnit::Test * suite ); private: CppUnit::Test * _factory_suite; CppUnit::Message * _failure_msg; bool _test_success; }; } /* end of namespace tap */ #endif /* !TAP_TAP_LISTENER_H */ psocksxx-1.1.1/test/tcpnsockstream_test.cpp000066400000000000000000000107751331043112200211560ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "tcpnsockstream_test.h" #include "necho.h" #include #include #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( tcpnsockstream_test ); // use namespace psocksxx using namespace psocksxx; void tcpnsockstream_test::connect_naddr( nsockaddr * naddr ) throw() { int csock; // not worth having error handling here so we hope for the best csock = socket( AF_INET, SOCK_STREAM, 0 ); connect( csock, naddr->psockaddr(), naddr->size() ); } void tcpnsockstream_test::test_constructors() { // default constructor CPPUNIT_ASSERT_NO_THROW( tcpnsockstream ss ); } void tcpnsockstream_test::test_connect_addr() { // tcp socket stream tcpnsockstream ss; // network echo server necho n( NSOCK_NODE, NSOCK_SERVICE ); // network address to connect to nsockaddr saddr( NSOCK_NODE, NSOCK_SERVICE ); // connect CPPUNIT_ASSERT_NO_THROW( ss.connect( &saddr ) ); } void tcpnsockstream_test::test_connect_host_port() { // tcp socket stream tcpnsockstream ss; // network echo server necho n( NSOCK_NODE, NSOCK_SERVICE_2 ); // connect CPPUNIT_ASSERT_NO_THROW( ss.connect( NSOCK_NODE, atoi( NSOCK_SERVICE_2 ) ) ); } void tcpnsockstream_test::test_bind_addr() { // tcp socket stream tcpnsockstream ss; // network address to bind to nsockaddr naddr( NSOCK_NODE, NSOCK_BIND_SERVICE ); // bind CPPUNIT_ASSERT_NO_THROW( ss.bind( &naddr, true ) ); } void tcpnsockstream_test::test_listen_addr() { // tcp socket stream tcpnsockstream ss; // network address to bind to nsockaddr naddr( NSOCK_NODE, NSOCK_BIND_SERVICE ); // bind try { ss.bind( &naddr, true ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // listen CPPUNIT_ASSERT_NO_THROW( ss.listen( 1 ) ); } void tcpnsockstream_test::test_accept_addr() { // fork variables pid_t cpid, wpid; int wpid_status; // tcp socket stream tcpnsockstream ss; // network socket pointer nsockstream * nsock = 0; // network address to bind to nsockaddr naddr( NSOCK_NODE, NSOCK_BIND_SERVICE ); // bind try { ss.bind( &naddr, true ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // listen try { ss.listen( 1 ); } catch( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // fork cpid = fork(); if ( cpid == -1 ) { CPPUNIT_FAIL( "failed to fork" ); } else if ( cpid == 0 ) { // child - connect to the network socket created by the parent connect_naddr( &naddr ); // exit exit( 0 ); } else { // parent - accept a connection from the child CPPUNIT_ASSERT_NO_THROW( nsock = ss.accept() ); CPPUNIT_ASSERT( nsock != 0 ); // cleanup if ( nsock != 0 ) { delete nsock; } // wait for child to exit if ( ( wpid = waitpid( cpid, &wpid_status, 0 ) ) == -1 ) { CPPUNIT_FAIL( "failed waiting for the child process to terminate" ); } } } void tcpnsockstream_test::test_bind_addr_fail() { // tcp socket stream tcpnsockstream ss, ssf; // network address to bind to nsockaddr naddr( NSOCK_NODE, NSOCK_BIND_SERVICE + 1 ); try { ss.bind( &naddr, true ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // bind - this should fail with address already in use error CPPUNIT_ASSERT_THROW( ssf.bind( &naddr ), sockexception ); } void tcpnsockstream_test::test_io_addr() { // tcp socket stream tcpnsockstream ss; // network echo server necho n( NSOCK_NODE, NSOCK_SERVICE ); // network address to connect to nsockaddr saddr( NSOCK_NODE, NSOCK_SERVICE ); // connect try { ss.connect( &saddr ); } catch ( sockexception &e ) { CPPUNIT_FAIL( e.what() ); return; } // write ss << 'c' << std::endl; // read char c; ss >> c; // assert CPPUNIT_ASSERT( c == 'c' ); } psocksxx-1.1.1/test/tcpnsockstream_test.h000066400000000000000000000036441331043112200206200ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef TCPNSOCKSTREAM_TEST_H #define TCPNSOCKSTREAM_TEST_H #include #include #ifndef NSOCK_NODE #define NSOCK_NODE "localhost" #endif #ifndef NSOCK_SERVICE #define NSOCK_SERVICE "21234" #endif #ifndef NSOCK_SERVICE_2 #define NSOCK_SERVICE_2 "21236" #endif #ifndef NSOCK_BIND_SERVICE #define NSOCK_BIND_SERVICE "21235" #endif class tcpnsockstream_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( tcpnsockstream_test ); CPPUNIT_TEST( test_constructors ); CPPUNIT_TEST( test_connect_addr ); CPPUNIT_TEST( test_connect_host_port ); CPPUNIT_TEST( test_bind_addr ); CPPUNIT_TEST( test_listen_addr ); CPPUNIT_TEST( test_accept_addr ); CPPUNIT_TEST( test_bind_addr_fail ); CPPUNIT_TEST( test_io_addr ); CPPUNIT_TEST_SUITE_END(); public: void test_constructors(); void test_connect_addr(); void test_connect_host_port(); void test_bind_addr(); void test_listen_addr(); void test_accept_addr(); void test_bind_addr_fail(); void test_io_addr(); private: void connect_naddr( psocksxx::nsockaddr * naddr ) throw(); }; #endif /* !TCPNSOCKSTREAM_TEST_H */ psocksxx-1.1.1/test/udpnsockstream_test.cpp000066400000000000000000000021631331043112200211500ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #include "udpnsockstream_test.h" #include // register the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( udpnsockstream_test ); // use namespace psocksxx using namespace psocksxx; void udpnsockstream_test::test_constructors() { // default constructor CPPUNIT_ASSERT_NO_THROW( udpnsockstream ss ); } psocksxx-1.1.1/test/udpnsockstream_test.h000066400000000000000000000022151331043112200206130ustar00rootroot00000000000000/* * psocksxx - A C++ wrapper for POSIX sockets * Copyright (C) 2013 Uditha Atukorala * * This software library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This software library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this software library. If not, see . * */ #ifndef UDPNSOCKSTREAM_TEST_H #define UDPNSOCKSTREAM_TEST_H #include class udpnsockstream_test : public CppUnit::TestFixture { // setup the test suite CPPUNIT_TEST_SUITE( udpnsockstream_test ); CPPUNIT_TEST( test_constructors ); CPPUNIT_TEST_SUITE_END(); public: void test_constructors(); }; #endif /* !UDPNSOCKSTREAM_TEST_H */