$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r49200 - trunk/libs/asio/example/local
From: chris_at_[hidden]
Date: 2008-10-09 02:32:01
Author: chris_kohlhoff
Date: 2008-10-09 02:32:00 EDT (Thu, 09 Oct 2008)
New Revision: 49200
URL: http://svn.boost.org/trac/boost/changeset/49200
Log:
Add example showing use of local::stream_protocol::iostream.
Added:
   trunk/libs/asio/example/local/iostream_client.cpp   (contents, props changed)
Text files modified: 
   trunk/libs/asio/example/local/Jamfile    |    12 ++++++++++++                            
   trunk/libs/asio/example/local/Jamfile.v2 |    15 +++++++++++++++                         
   2 files changed, 27 insertions(+), 0 deletions(-)
Modified: trunk/libs/asio/example/local/Jamfile
==============================================================================
--- trunk/libs/asio/example/local/Jamfile	(original)
+++ trunk/libs/asio/example/local/Jamfile	2008-10-09 02:32:00 EDT (Thu, 09 Oct 2008)
@@ -33,6 +33,18 @@
     $(SOCKET_LIBS)
   ;
 
+exe iostream_client
+  : <lib>@boost/libs/system/build/boost_system
+    iostream_client.cpp
+  : <include>$(BOOST_ROOT)
+    <include>../../../..
+    <define>BOOST_ALL_NO_LIB=1
+    <threading>multi
+    <mingw><*><find-library>ws2_32
+    <mingw><*><find-library>mswsock
+    $(SOCKET_LIBS)
+  ;
+
 exe stream_client
   : <lib>@boost/libs/system/build/boost_system
     stream_client.cpp
Modified: trunk/libs/asio/example/local/Jamfile.v2
==============================================================================
--- trunk/libs/asio/example/local/Jamfile.v2	(original)
+++ trunk/libs/asio/example/local/Jamfile.v2	2008-10-09 02:32:00 EDT (Thu, 09 Oct 2008)
@@ -38,6 +38,21 @@
     <os>HPUX:<library>ipv6
   ;
 
+exe iostream_client
+  : iostream_client.cpp
+    /boost/system//boost_system
+  : <define>BOOST_ALL_NO_LIB=1
+    <threading>multi
+    <os>SOLARIS:<library>socket
+    <os>SOLARIS:<library>nsl
+    <os>NT:<define>_WIN32_WINNT=0x0501
+    <os>NT,<toolset>gcc:<library>ws2_32
+    <os>NT,<toolset>gcc:<library>mswsock
+    <os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
+    <os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
+    <os>HPUX:<library>ipv6
+  ;
+
 exe stream_client
   : stream_client.cpp
     /boost/system//boost_system
Added: trunk/libs/asio/example/local/iostream_client.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/asio/example/local/iostream_client.cpp	2008-10-09 02:32:00 EDT (Thu, 09 Oct 2008)
@@ -0,0 +1,59 @@
+//
+// stream_client.cpp
+// ~~~~~~~~~~~~~~~~~
+//
+// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <cstring>
+#include <iostream>
+#include <boost/asio.hpp>
+
+#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+
+using boost::asio::local::stream_protocol;
+
+enum { max_length = 1024 };
+
+int main(int argc, char* argv[])
+{
+  try
+  {
+    if (argc != 2)
+    {
+      std::cerr << "Usage: iostream_client <file>\n";
+      return 1;
+    }
+
+    boost::asio::io_service io_service;
+
+    stream_protocol::endpoint ep(argv[1]);
+    stream_protocol::iostream s(ep);
+
+    using namespace std; // For strlen.
+    std::cout << "Enter message: ";
+    char request[max_length];
+    std::cin.getline(request, max_length);
+    size_t length = strlen(request);
+    s << request;
+
+    char reply[max_length];
+    s.read(reply, length);
+    std::cout << "Reply is: ";
+    std::cout.write(reply, length);
+    std::cout << "\n";
+  }
+  catch (std::exception& e)
+  {
+    std::cerr << "Exception: " << e.what() << "\n";
+  }
+
+  return 0;
+}
+
+#else // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
+# error Local sockets not available on this platform.
+#endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)