Added close() method to stream classes. master
authorArjen Baart <arjen@andromeda.nl>
Fri, 16 Nov 2012 16:07:14 +0000 (17:07 +0100)
committerArjen Baart <arjen@andromeda.nl>
Fri, 16 Nov 2012 16:07:14 +0000 (17:07 +0100)
include/sockstream.h
src/service.cpp
test/Makefile.am
test/revd.cpp

index d6352af..8953e53 100644 (file)
@@ -9,6 +9,8 @@
 **
 **  DESCRIPTION      :  sockbuf and sockstream classes.
 **
+**                      Special thanks to Marc Groenewegen <marcg@dinkum.nl>
+**
 **  EXPORTED OBJECTS : class sockbuf, class isockstream,
 **                     class osockstream, class sockstream
 **  LOCAL    OBJECTS : 
@@ -18,7 +20,7 @@
 ********************************
 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
 **      CREATION DATE   : Aug 16, 2012
-**      LAST UPDATE     : Oct 19, 2012
+**      LAST UPDATE     : Nov 13, 2012
 **      MODIFICATIONS   : 
 **************************************************************************/
 
@@ -125,7 +127,7 @@ public:
 **
 **  RELATIONS      : 
 **  SEE ALSO       : 
-**  LAST MODIFIED  : Oct 19, 2012
+**  LAST MODIFIED  : Nov 13, 2012
 **+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
 
@@ -141,6 +143,11 @@ public:
       this->init(&_M_sockbuf);
       _M_sockbuf.connect(_s);
    }
+
+   void close()
+   {
+      _M_sockbuf.close();
+   }
 };
 
 
@@ -155,7 +162,7 @@ public:
 **
 **  RELATIONS      : 
 **  SEE ALSO       : 
-**  LAST MODIFIED  : Oct 19, 2012
+**  LAST MODIFIED  : Nov 13, 2012
 **+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
 
@@ -171,6 +178,11 @@ public:
       this->init(&_M_sockbuf);
       _M_sockbuf.connect(_s);
    }
+
+   void close()
+   {
+      _M_sockbuf.close();
+   }
 };
 
 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -184,7 +196,7 @@ public:
 **
 **  RELATIONS      : 
 **  SEE ALSO       : 
-**  LAST MODIFIED  : Oct 19, 2012
+**  LAST MODIFIED  : Nov 13, 2012
 **+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 */
 
@@ -200,6 +212,11 @@ public:
       this->init(&_M_sockbuf);
       _M_sockbuf.connect(_s);
    }
+
+   void close()
+   {
+      _M_sockbuf.close();
+   }
 };
 
 
index 94cd891..7fba74f 100644 (file)
@@ -60,7 +60,6 @@ std::list<Port> Service::FindAddress()
    {
       struct sockaddr_in *sa;
       sa = (struct sockaddr_in *)rp->ai_addr;
-      std::cout << "Port " << htons(sa->sin_port) << " socket " << rp->ai_socktype << "\n";
 
       Port p(sa->sin_port, rp->ai_socktype);
       ports.push_back(p);
index 24b5c6c..99cd48a 100644 (file)
@@ -4,7 +4,7 @@ iptest_SOURCES = iptest.cpp
 iptest_CPPFLAGS = -I$(top_srcdir)/include
 iptest_LDADD = $(top_builddir)/src/libsockstream.la
 
-http_get_SOURCES = iptest.cpp
+http_get_SOURCES = http_get.cpp
 http_get_CPPFLAGS = -I$(top_srcdir)/include
 http_get_LDADD = $(top_builddir)/src/libsockstream.la
 
index 4ab1326..03f8ff3 100644 (file)
@@ -22,7 +22,7 @@
 **************************************************************************/
 
 
-#include "socket.h"
+#include "sockstream.h"
 
 
 /*=========================================================================
@@ -54,30 +54,29 @@ int main()
    StreamSocket s;
    s.Listen(sa);
 
-   while (true)
-   {
-      char buf[1000];
+   //while (true)
+   //{
       int  len;
 
-      StreamSocket client = s.Accept();
+      sockstream client(s.Accept());
       std::cout << "Socket connected.\n";
 
       do
       {
-         char reverse[1000];
+         String buf, reverse;
 
-         buf[0] = '\0';
-         len = client.Read(buf, 1000);
-         buf[len] = '\0';
+         client >> buf;
+         len = ~buf;
+         reverse = "";
          std::cout << "\nLEN = " << len << "\n" << buf << "\n";
          for (int i = 0; i < len; i++)
          {
-            reverse[i] = buf[len-i-1];
+            reverse += buf(len-i-1, 1);
          }
-         client.Write(reverse, len);
+         client << reverse << std::endl;
       }
-      while (len > 0);
-      client.Close();
-   }
+      while (len > 2);
+      client.close();
+   //}
 }