<commit_before>/*
 * LocalStreamAsyncClient.hpp
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#ifndef CORE_HTTP_LOCAL_STREAM_ASYNC_CLIENT_HPP
#define CORE_HTTP_LOCAL_STREAM_ASYNC_CLIENT_HPP

#include <boost/function.hpp>

#include <boost/asio/local/stream_protocol.hpp>

#include <core/Error.hpp>
#include <core/FilePath.hpp>

#include <core/http/AsyncClient.hpp>
#include <core/http/LocalStreamSocketUtils.hpp>

namespace core {
namespace http {  

class LocalStreamAsyncClient
   : public AsyncClient<boost::asio::local::stream_protocol::socket>
{
public:
   LocalStreamAsyncClient(boost::asio::io_service& ioService,
                          const FilePath localStreamPath)
     : AsyncClient<boost::asio::local::stream_protocol::socket>(ioService),
       socket_(ioService),
       localStreamPath_(localStreamPath)
   {
   }

protected:

   virtual boost::asio::local::stream_protocol::socket& socket()
   {
      return socket_;
   }

private:

   virtual void connectAndWriteRequest()
   {
      // establish endpoint
      using boost::asio::local::stream_protocol;
      stream_protocol::endpoint endpoint(localStreamPath_.absolutePath());

      // connect
      socket().async_connect(
         endpoint,
         boost::bind(&LocalStreamAsyncClient::handleConnect,
                     sharedFromThis(),
                     boost::asio::placeholders::error));
   }

   void handleConnect(const boost::system::error_code& ec)
   {
      try
      {
         if (!ec)<commit_msg>add retry profile parameter to local stream async client<commit_after>/*
 * LocalStreamAsyncClient.hpp
 *
 * Copyright (C) 2009-12 by RStudio, Inc.
 *
 * Unless you have received this program directly from RStudio pursuant
 * to the terms of a commercial license agreement with RStudio, then
 * this program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */

#ifndef CORE_HTTP_LOCAL_STREAM_ASYNC_CLIENT_HPP
#define CORE_HTTP_LOCAL_STREAM_ASYNC_CLIENT_HPP

#include <boost/function.hpp>

#include <boost/asio/local/stream_protocol.hpp>

#include <core/Error.hpp>
#include <core/FilePath.hpp>

#include <core/http/AsyncClient.hpp>
#include <core/http/LocalStreamSocketUtils.hpp>

namespace core {
namespace http {  

class LocalStreamAsyncClient
   : public AsyncClient<boost::asio::local::stream_protocol::socket>
{
public:
   LocalStreamAsyncClient(boost::asio::io_service& ioService,
                          const FilePath localStreamPath,
                          const http::ConnectionRetryProfile& retryProfile =
                                                http::ConnectionRetryProfile())
     : AsyncClient<boost::asio::local::stream_protocol::socket>(ioService),
       socket_(ioService),
       localStreamPath_(localStreamPath)
   {
      setConnectionRetryProfile(retryProfile);
   }

protected:

   virtual boost::asio::local::stream_protocol::socket& socket()
   {
      return socket_;
   }

private:

   virtual void connectAndWriteRequest()
   {
      // establish endpoint
      using boost::asio::local::stream_protocol;
      stream_protocol::endpoint endpoint(localStreamPath_.absolutePath());

      // connect
      socket().async_connect(
         endpoint,
         boost::bind(&LocalStreamAsyncClient::handleConnect,
                     sharedFromThis(),
                     boost::asio::placeholders::error));
   }

   void handleConnect(const boost::system::error_code& ec)
   {
      try
      {
         if (!ec)
{'fraction_non_alphanumeric': 0.09626672927917351, 'fraction_numerical': 0.004226344212256398, 'mean_word_length': 3.432882414151925, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6740828', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1151, 'n_words': 292}