<commit_before>////////////////////////////////////////////////////////////////////////////////
/// @brief base class for input-output tasks from sockets
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. <NAME>
/// @author <NAME>
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#ifndef ARANGODB_SCHEDULER_SOCKET_TASK_H
#define ARANGODB_SCHEDULER_SOCKET_TASK_H 1

#include "Basics/Common.h"

#include "Scheduler/Task.h"

#include "Basics/Mutex.h"
#include "Basics/Thread.h"
#include "Statistics/StatisticsAgent.h"

#ifdef _WIN32
#include "Basics/win-utils.h"
#endif

#include "Basics/socket-utils.h"

// -----------------------------------------------------------------------------
// --SECTION--                                              forward declarations
// -----------------------------------------------------------------------------

namespace triagens {
  namespace basics {
    class StringBuffer;
  }

// -----------------------------------------------------------------------------
// --SECTION--                                                  class SocketTask
// -----------------------------------------------------------------------------

  namespace rest {

////////////////////////////////////////////////////////////////////////////////
/// @brief base class for input-output tasks from sockets
////////////////////////////////////////////////////////////////////////////////

    class SocketTask : virtual public Task,
                       public ConnectionStatisticsAgent {
      private:
        SocketTask (SocketTask const&);
        SocketTask& operator= (SocketTask const&);

      private:
        static size_t const READ_BLOCK_SIZE = 10000;

// -----------------------------------------------------------------------------
// --SECTION--                                      constructors and destructors
// -----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// @brief constructs a new task with a given socket
////////////////////////////////////////////////////////////////////////////////

      public:

        explicit
        SocketTask (TRI_socket_t, double);

////////////////////////////////////////////////////////////////////////////////
/// @brief deletes a socket task
///
/// This method will close the underlying socket.
////////////////////////////////////////////////////////////////////////////////

      protected:

        ~SocketTask ();

// -----------------------------------------------------------------------------
// --SECTION--                                                    public methods
// -----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// set a request timeout
////////////////////////////////////////////////////////////////////////////////

    public:

        void setKeepAliveTimeout (double);

// -----------------------------------------------------------------------------
// --SECTION--                                         protected virtual methods
// -----------------------------------------------------------------------------

      protected:

////////////////////////////////////////////////////////////////////////////////
/// @brief fills the read buffer
///
/// The function should be called by the input task if the scheduler has
/// indicated that new data is available. It will return true, if data could
/// be read and false if the connection has been closed.
////////////////////////////////////////////////////////////////////////////////

        virtual bool fillReadBuffer ();

////////////////////////////////////////////////////////////////////////////////
/// @brief handles a read
////////////////////////////////////////////////////////////////////////////////

        virtual bool handleRead () = 0;

////////////////////////////////////////////////////////////////////////////////
/// @brief handles a write
////////////////////////////////////////////////////////////////////////////////

        virtual bool handleWrite ();

////////////////////////////////////////////////////////////////////////////////
/// @brief called if write buffer has been sent
///
/// This called is called if the current write buffer has been sent
/// completly to the client.
////////////////////////////////////////////////////////////////////////////////

        virtual void completedWriteBuffer () = 0;

////////////////////////////////////////////////////////////////////////////////
/// @brief handles a keep-alive timeout
////////////////////////////////////////////////////////////////////////////////

        virtual void handleTimeout () = 0;

// -----------------------------------------------------------------------------
// --SECTION--                                                 protected methods
// -----------------------------------------------------------------------------

      protected:

////////////////////////////////////////////////////////////////////////////////
/// @brief sets an active write buffer
////////////////////////////////////////////////////////////////////////////////

        void setWriteBuffer (basics::StringBuffer*,
                             TRI_request_statistics_t*);

////////////////////////////////////////////////////////////////////////////////
/// @brief checks for presence of an active write buffer
////////////////////////////////////////////////////////////////////////////////

        bool hasWriteBuffer () const;

// -----------------------------------------------------------------------------
// --SECTION--                                                      Task methods
// -----------------------------------------------------------------------------

      protected:

////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////

        bool setup (Scheduler*, EventLoop) override;

////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////

        void cleanup () override;

////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////

        bool handleEvent (EventToken token, EventType) override;

// -----------------------------------------------------------------------------
// --SECTION--                                               protected variables
// -----------------------------------------------------------------------------<commit_msg>added comment<commit_after>////////////////////////////////////////////////////////////////////////////////
/// @brief base class for input-output tasks from sockets
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author Dr. <NAME>
/// @author <NAME>
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2009-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#ifndef ARANGODB_SCHEDULER_SOCKET_TASK_H
#define ARANGODB_SCHEDULER_SOCKET_TASK_H 1

#include "Basics/Common.h"

#include "Scheduler/Task.h"

#include "Basics/Mutex.h"
#include "Basics/Thread.h"
#include "Statistics/StatisticsAgent.h"

#ifdef _WIN32
#include "Basics/win-utils.h"
#endif

#include "Basics/socket-utils.h"

// -----------------------------------------------------------------------------
// --SECTION--                                              forward declarations
// -----------------------------------------------------------------------------

namespace triagens {
  namespace basics {
    class StringBuffer;
  }

// -----------------------------------------------------------------------------
// --SECTION--                                                  class SocketTask
// -----------------------------------------------------------------------------

  namespace rest {

////////////////////////////////////////////////////////////////////////////////
/// @brief base class for input-output tasks from sockets
////////////////////////////////////////////////////////////////////////////////

    class SocketTask : virtual public Task,
                       public ConnectionStatisticsAgent {
      private:
        SocketTask (SocketTask const&);
        SocketTask& operator= (SocketTask const&);

      private:
        static size_t const READ_BLOCK_SIZE = 10000;

// -----------------------------------------------------------------------------
// --SECTION--                                      constructors and destructors
// -----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// @brief constructs a new task with a given socket
////////////////////////////////////////////////////////////////////////////////

      public:

        explicit
        SocketTask (TRI_socket_t, double);

////////////////////////////////////////////////////////////////////////////////
/// @brief deletes a socket task
///
/// This method will close the underlying socket.
////////////////////////////////////////////////////////////////////////////////

      protected:

        ~SocketTask ();

// -----------------------------------------------------------------------------
// --SECTION--                                                    public methods
// -----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// set a request timeout
////////////////////////////////////////////////////////////////////////////////

    public:

        void setKeepAliveTimeout (double);

// -----------------------------------------------------------------------------
// --SECTION--                                         protected virtual methods
// -----------------------------------------------------------------------------

      protected:

////////////////////////////////////////////////////////////////////////////////
/// @brief fills the read buffer
///
/// The function should be called by the input task if the scheduler has
/// indicated that new data is available. It will return true, if data could
/// be read and false if the connection has been closed.
////////////////////////////////////////////////////////////////////////////////

        virtual bool fillReadBuffer ();

////////////////////////////////////////////////////////////////////////////////
/// @brief handles a read
////////////////////////////////////////////////////////////////////////////////

        virtual bool handleRead () = 0;

////////////////////////////////////////////////////////////////////////////////
/// @brief handles a write
////////////////////////////////////////////////////////////////////////////////

        virtual bool handleWrite ();

////////////////////////////////////////////////////////////////////////////////
/// @brief called if write buffer has been sent
///
/// This called is called if the current write buffer has been sent
/// completly to the client.
////////////////////////////////////////////////////////////////////////////////

        virtual void completedWriteBuffer () = 0;

////////////////////////////////////////////////////////////////////////////////
/// @brief handles a keep-alive timeout
////////////////////////////////////////////////////////////////////////////////

        virtual void handleTimeout () = 0;

// -----------------------------------------------------------------------------
// --SECTION--                                                 protected methods
// -----------------------------------------------------------------------------

      protected:

////////////////////////////////////////////////////////////////////////////////
/// @brief sets an active write buffer
////////////////////////////////////////////////////////////////////////////////

        void setWriteBuffer (basics::StringBuffer*,
                             TRI_request_statistics_t*);

////////////////////////////////////////////////////////////////////////////////
/// @brief checks for presence of an active write buffer
////////////////////////////////////////////////////////////////////////////////

        bool hasWriteBuffer () const;

// -----------------------------------------------------------------------------
// --SECTION--                                                      Task methods
// -----------------------------------------------------------------------------

      protected:

////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////

        bool setup (Scheduler*, EventLoop) override;

////////////////////////////////////////////////////////////////////////////////
/// @brief cleans up the task by unregistering all watchers
////////////////////////////////////////////////////////////////////////////////

        void cleanup () override;

////////////////////////////////////////////////////////////////////////////////
/// {@inheritDoc}
////////////////////////////////////////////////////////////////////////////////

        bool handleEvent (EventToken token, EventType) override;

// -----------------------------------------------------------------------------
// --SECTION--                                               protected variables
// -----------------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.5242705912729151, 'fraction_numerical': 0.005034856700232378, 'mean_word_length': 0.5192194547950578, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5293957', 'n_tokens_mistral': 2326, 'n_tokens_neox': 2166, 'n_words': 781}