<commit_before>/*
 * LocalStreamAsyncServer.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_SERVER_HPP
#define CORE_HTTP_LOCAL_STREAM_ASYNC_SERVER_HPP

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

#include <core/system/PosixUser.hpp>

namespace core {
namespace http {

class LocalStreamAsyncServer
   : public AsyncServerImpl<boost::asio::local::stream_protocol>
{
public:
   LocalStreamAsyncServer(const std::string& serverName,
                          const std::string& baseUri,
                          core::system::FileMode fileMode)
      : AsyncServerImpl<boost::asio::local::stream_protocol>(serverName, baseUri),
        fileMode_(fileMode)
   {
   }
   
   virtual ~LocalStreamAsyncServer()
   {
      try
      {
         Error error = removeLocalStream();
         if (error)
            LOG_ERROR(error);
      }
      catch(...)
      {
      }
   }
   
   
public:
   Error init(const core::FilePath& localStreamPath)
   {
      // set stream path
      localStreamPath_ = localStreamPath;
      
      // remove any existing stream
      Error error = removeLocalStream();
      if (error)
         return error ;
      
      // initialize stream dir
      error = initializeStreamDir(localStreamPath_.parent());
      if (error)
         return error;

      // initialize acceptor<commit_msg>don't log permission related errors on local stream destruction<commit_after>/*
 * LocalStreamAsyncServer.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_SERVER_HPP
#define CORE_HTTP_LOCAL_STREAM_ASYNC_SERVER_HPP

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

#include <core/system/PosixUser.hpp>

namespace core {
namespace http {

class LocalStreamAsyncServer
   : public AsyncServerImpl<boost::asio::local::stream_protocol>
{
public:
   LocalStreamAsyncServer(const std::string& serverName,
                          const std::string& baseUri,
                          core::system::FileMode fileMode)
      : AsyncServerImpl<boost::asio::local::stream_protocol>(serverName, baseUri),
        fileMode_(fileMode)
   {
   }
   
   virtual ~LocalStreamAsyncServer()
   {
      try
      {
         Error error = removeLocalStream();

         // log error, but not for permission denied (because this could be
         // a stream created by root and then torn down after yielding
         // privilege to a different user)
         if (error && (error.code() != boost::system::errc::permission_denied))
            LOG_ERROR(error);
      }
      catch(...)
      {
      }
   }
   
   
public:
   Error init(const core::FilePath& localStreamPath)
   {
      // set stream path
      localStreamPath_ = localStreamPath;
      
      // remove any existing stream
      Error error = removeLocalStream();
      if (error)
         return error ;
      
      // initialize stream dir
      error = initializeStreamDir(localStreamPath_.parent());
      if (error)
         return error;

      // initialize acceptor
{'fraction_non_alphanumeric': 0.08597723419714216, 'fraction_numerical': 0.004359409057883265, 'mean_word_length': 2.831168831168831, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2978545', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1116, 'n_words': 336}