Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAMD authored Apr 2, 2021
1 parent 3f67b03 commit f7ed294
Show file tree
Hide file tree
Showing 50 changed files with 5,920 additions and 0 deletions.
32 changes: 32 additions & 0 deletions asio/include/asio/detail/reactor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// detail/reactor.hpp
// ~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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)
//

#ifndef ASIO_DETAIL_REACTOR_HPP
#define ASIO_DETAIL_REACTOR_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include "asio/detail/reactor_fwd.hpp"

#if defined(ASIO_HAS_EPOLL)
# include "asio/detail/epoll_reactor.hpp"
#elif defined(ASIO_HAS_KQUEUE)
# include "asio/detail/kqueue_reactor.hpp"
#elif defined(ASIO_HAS_DEV_POLL)
# include "asio/detail/dev_poll_reactor.hpp"
#elif defined(ASIO_HAS_IOCP) || defined(ASIO_WINDOWS_RUNTIME)
# include "asio/detail/null_reactor.hpp"
#else
# include "asio/detail/select_reactor.hpp"
#endif

#endif // ASIO_DETAIL_REACTOR_HPP
40 changes: 40 additions & 0 deletions asio/include/asio/detail/reactor_fwd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// detail/reactor_fwd.hpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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)
//

#ifndef ASIO_DETAIL_REACTOR_FWD_HPP
#define ASIO_DETAIL_REACTOR_FWD_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include "asio/detail/config.hpp"

namespace asio {
namespace detail {

#if defined(ASIO_HAS_IOCP) || defined(ASIO_WINDOWS_RUNTIME)
typedef class null_reactor reactor;
#elif defined(ASIO_HAS_IOCP)
typedef class select_reactor reactor;
#elif defined(ASIO_HAS_EPOLL)
typedef class epoll_reactor reactor;
#elif defined(ASIO_HAS_KQUEUE)
typedef class kqueue_reactor reactor;
#elif defined(ASIO_HAS_DEV_POLL)
typedef class dev_poll_reactor reactor;
#else
typedef class select_reactor reactor;
#endif

} // namespace detail
} // namespace asio

#endif // ASIO_DETAIL_REACTOR_FWD_HPP
67 changes: 67 additions & 0 deletions asio/include/asio/detail/reactor_op.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// detail/reactor_op.hpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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)
//

#ifndef ASIO_DETAIL_REACTOR_OP_HPP
#define ASIO_DETAIL_REACTOR_OP_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include "asio/detail/config.hpp"
#include "asio/detail/operation.hpp"

#include "asio/detail/push_options.hpp"

namespace asio {
namespace detail {

class reactor_op
: public operation
{
public:
// The error code to be passed to the completion handler.
asio::error_code ec_;

// The number of bytes transferred, to be passed to the completion handler.
std::size_t bytes_transferred_;

// Status returned by perform function. May be used to decide whether it is
// worth performing more operations on the descriptor immediately.
enum status { not_done, done, done_and_exhausted };

// Perform the operation. Returns true if it is finished.
status perform()
{
return perform_func_(this);
}

protected:
typedef status (*perform_func_type)(reactor_op*);

reactor_op(const asio::error_code& success_ec,
perform_func_type perform_func, func_type complete_func)
: operation(complete_func),
ec_(success_ec),
bytes_transferred_(0),
perform_func_(perform_func)
{
}

private:
perform_func_type perform_func_;
};

} // namespace detail
} // namespace asio

#include "asio/detail/pop_options.hpp"

#endif // ASIO_DETAIL_REACTOR_OP_HPP
168 changes: 168 additions & 0 deletions asio/include/asio/detail/reactor_op_queue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
//
// detail/reactor_op_queue.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2020 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)
//

#ifndef ASIO_DETAIL_REACTOR_OP_QUEUE_HPP
#define ASIO_DETAIL_REACTOR_OP_QUEUE_HPP

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)

#include "asio/detail/config.hpp"
#include "asio/detail/hash_map.hpp"
#include "asio/detail/noncopyable.hpp"
#include "asio/detail/op_queue.hpp"
#include "asio/detail/reactor_op.hpp"
#include "asio/error.hpp"

#include "asio/detail/push_options.hpp"

namespace asio {
namespace detail {

template <typename Descriptor>
class reactor_op_queue
: private noncopyable
{
public:
typedef Descriptor key_type;

struct mapped_type : op_queue<reactor_op>
{
mapped_type() {}
mapped_type(const mapped_type&) {}
void operator=(const mapped_type&) {}
};

typedef typename hash_map<key_type, mapped_type>::value_type value_type;
typedef typename hash_map<key_type, mapped_type>::iterator iterator;

// Constructor.
reactor_op_queue()
: operations_()
{
}

// Obtain iterators to all registered descriptors.
iterator begin() { return operations_.begin(); }
iterator end() { return operations_.end(); }

// Add a new operation to the queue. Returns true if this is the only
// operation for the given descriptor, in which case the reactor's event
// demultiplexing function call may need to be interrupted and restarted.
bool enqueue_operation(Descriptor descriptor, reactor_op* op)
{
std::pair<iterator, bool> entry =
operations_.insert(value_type(descriptor, mapped_type()));
entry.first->second.push(op);
return entry.second;
}

// Cancel all operations associated with the descriptor identified by the
// supplied iterator. Any operations pending for the descriptor will be
// cancelled. Returns true if any operations were cancelled, in which case
// the reactor's event demultiplexing function may need to be interrupted and
// restarted.
bool cancel_operations(iterator i, op_queue<operation>& ops,
const asio::error_code& ec =
asio::error::operation_aborted)
{
if (i != operations_.end())
{
while (reactor_op* op = i->second.front())
{
op->ec_ = ec;
i->second.pop();
ops.push(op);
}
operations_.erase(i);
return true;
}

return false;
}

// Cancel all operations associated with the descriptor. Any operations
// pending for the descriptor will be cancelled. Returns true if any
// operations were cancelled, in which case the reactor's event
// demultiplexing function may need to be interrupted and restarted.
bool cancel_operations(Descriptor descriptor, op_queue<operation>& ops,
const asio::error_code& ec =
asio::error::operation_aborted)
{
return this->cancel_operations(operations_.find(descriptor), ops, ec);
}

// Whether there are no operations in the queue.
bool empty() const
{
return operations_.empty();
}

// Determine whether there are any operations associated with the descriptor.
bool has_operation(Descriptor descriptor) const
{
return operations_.find(descriptor) != operations_.end();
}

// Perform the operations corresponding to the descriptor identified by the
// supplied iterator. Returns true if there are still unfinished operations
// queued for the descriptor.
bool perform_operations(iterator i, op_queue<operation>& ops)
{
if (i != operations_.end())
{
while (reactor_op* op = i->second.front())
{
if (op->perform())
{
i->second.pop();
ops.push(op);
}
else
{
return true;
}
}
operations_.erase(i);
}
return false;
}

// Perform the operations corresponding to the descriptor. Returns true if
// there are still unfinished operations queued for the descriptor.
bool perform_operations(Descriptor descriptor, op_queue<operation>& ops)
{
return this->perform_operations(operations_.find(descriptor), ops);
}

// Get all operations owned by the queue.
void get_all_operations(op_queue<operation>& ops)
{
iterator i = operations_.begin();
while (i != operations_.end())
{
iterator op_iter = i++;
ops.push(op_iter->second);
operations_.erase(op_iter);
}
}

private:
// The operations that are currently executing asynchronously.
hash_map<key_type, mapped_type> operations_;
};

} // namespace detail
} // namespace asio

#include "asio/detail/pop_options.hpp"

#endif // ASIO_DETAIL_REACTOR_OP_QUEUE_HPP
Loading

0 comments on commit f7ed294

Please sign in to comment.