Exemple #1
0
    void operator()(const boost::system::error_code& ec,
        std::size_t bytes_transferred, int start = 0)
    {
      const std::size_t not_found = (std::numeric_limits<std::size_t>::max)();
      std::size_t bytes_to_read;
      switch (start_ = start)
      {
      case 1:
        for (;;)
        {
          {
            // Determine the range of the data to be searched.
            typedef typename boost::asio::basic_streambuf<
              Allocator>::const_buffers_type const_buffers_type;
            typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
            const_buffers_type buffers = streambuf_.data();
            iterator begin = iterator::begin(buffers);
            iterator start_pos = begin + search_position_;
            iterator end = iterator::end(buffers);

            // Look for a match.
            iterator iter = std::find(start_pos, end, delim_);
            if (iter != end)
            {
              // Found a match. We're done.
              search_position_ = iter - begin + 1;
              bytes_to_read = 0;
            }

            // No match yet. Check if buffer is full.
            else if (streambuf_.size() == streambuf_.max_size())
            {
              search_position_ = not_found;
              bytes_to_read = 0;
            }

            // Need to read some more data.
            else
            {
              // Next search can start with the new data.
              search_position_ = end - begin;
              bytes_to_read = read_size_helper(streambuf_, 65536);
            }
          }

          // Check if we're done.
          if (!start && bytes_to_read == 0)
            break;

          // Start a new asynchronous read operation to obtain more data.
          stream_.async_read_some(streambuf_.prepare(bytes_to_read),
              BOOST_ASIO_MOVE_CAST(read_until_delim_op)(*this));
          return; default:
          streambuf_.commit(bytes_transferred);
          if (ec || bytes_transferred == 0)
            break;
        }

        const boost::system::error_code result_ec =
          (search_position_ == not_found)
          ? error::not_found : ec;

        const std::size_t result_n =
          (ec || search_position_ == not_found)
          ? 0 : search_position_;

        handler_(result_ec, result_n);
      }
    }
 reactive_null_buffers_op(Handler& handler)
     : reactor_op(&reactive_null_buffers_op::do_perform,
                  &reactive_null_buffers_op::do_complete),
       handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
 {
 }
 wait_handler(Handler& h)
   : wait_op(&wait_handler::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(h))
 {
 }
   * the signalled state. Copies will be made of the handler as required. The
   * function signature of the handler must be:
   * @code void handler(
   *   const boost::system::error_code& error // Result of operation.
   * ); @endcode
   * Regardless of whether the asynchronous operation completes immediately or
   * not, the handler will not be invoked from within this function. Invocation
   * of the handler will be performed in a manner equivalent to using
   * boost::asio::io_service::post().
   */
  template <typename WaitHandler>
  BOOST_ASIO_INITFN_RESULT_TYPE(WaitHandler,
      void (boost::system::error_code))
  async_wait(BOOST_ASIO_MOVE_ARG(WaitHandler) handler)
  {
    return this->get_service().async_wait(this->get_implementation(),
        BOOST_ASIO_MOVE_CAST(WaitHandler)(handler));
  }
};

} // namespace windows
} // namespace asio
} // namespace boost

#include <boost/asio/detail/pop_options.hpp>

#endif // defined(BOOST_ASIO_HAS_WINDOWS_OBJECT_HANDLE)
       //   || defined(GENERATING_DOCUMENTATION)

#endif // BOOST_ASIO_WINDOWS_BASIC_OBJECT_HANDLE_HPP
Exemple #5
0
 winrt_socket_send_op(const ConstBufferSequence& buffers, Handler& handler)
   : winrt_async_op<unsigned int>(&winrt_socket_send_op::do_complete),
     buffers_(buffers),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
 {
 }
  }

  /// Start an asynchronous write. The data being written must be valid for the
  /// lifetime of the asynchronous operation.
  template <typename ConstBufferSequence, typename WriteHandler>
  BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
      void (boost::system::error_code, std::size_t))
  async_write_some(const ConstBufferSequence& buffers,
      BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
  {
    detail::async_result_init<
      WriteHandler, void (boost::system::error_code, std::size_t)> init(
        BOOST_ASIO_MOVE_CAST(WriteHandler)(handler));

    next_layer_.async_write_some(buffers,
        BOOST_ASIO_MOVE_CAST(BOOST_ASIO_HANDLER_TYPE(WriteHandler,
            void (boost::system::error_code, std::size_t)))(init.handler));

    return init.result.get();
  }

  /// Fill the buffer with some data. Returns the number of bytes placed in the
  /// buffer as a result of the operation. Throws an exception on failure.
  std::size_t fill();

  /// Fill the buffer with some data. Returns the number of bytes placed in the
  /// buffer as a result of the operation, or 0 if an error occurred.
  std::size_t fill(boost::system::error_code& ec);

  /// Start an asynchronous fill.
  template <typename ReadHandler>
  BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler,
Exemple #7
0
  void operator()(lslboost::system::error_code ec,
      std::size_t bytes_transferred = ~std::size_t(0), int start = 0)
  {
    switch (start_ = start)
    {
    case 1: // Called after at least one async operation.
      do
      {
        switch (want_ = op_(core_.engine_, ec_, bytes_transferred_))
        {
        case engine::want_input_and_retry:

          // If the input buffer already has data in it we can pass it to the
          // engine and then retry the operation immediately.
          if (lslboost::asio::buffer_size(core_.input_) != 0)
          {
            core_.input_ = core_.engine_.put_input(core_.input_);
            continue;
          }

          // The engine wants more data to be read from input. However, we
          // cannot allow more than one read operation at a time on the
          // underlying transport. The pending_read_ timer's expiry is set to
          // pos_infin if a read is in progress, and neg_infin otherwise.
          if (core_.pending_read_.expires_at() == core_.neg_infin())
          {
            // Prevent other read operations from being started.
            core_.pending_read_.expires_at(core_.pos_infin());

            // Start reading some data from the underlying transport.
            next_layer_.async_read_some(
                lslboost::asio::buffer(core_.input_buffer_),
                BOOST_ASIO_MOVE_CAST(io_op)(*this));
          }
          else
          {
            // Wait until the current read operation completes.
            core_.pending_read_.async_wait(BOOST_ASIO_MOVE_CAST(io_op)(*this));
          }

          // Yield control until asynchronous operation completes. Control
          // resumes at the "default:" label below.
          return;

        case engine::want_output_and_retry:
        case engine::want_output:

          // The engine wants some data to be written to the output. However, we
          // cannot allow more than one write operation at a time on the
          // underlying transport. The pending_write_ timer's expiry is set to
          // pos_infin if a write is in progress, and neg_infin otherwise.
          if (core_.pending_write_.expires_at() == core_.neg_infin())
          {
            // Prevent other write operations from being started.
            core_.pending_write_.expires_at(core_.pos_infin());

            // Start writing all the data to the underlying transport.
            lslboost::asio::async_write(next_layer_,
                core_.engine_.get_output(core_.output_buffer_),
                BOOST_ASIO_MOVE_CAST(io_op)(*this));
          }
          else
          {
            // Wait until the current write operation completes.
            core_.pending_write_.async_wait(BOOST_ASIO_MOVE_CAST(io_op)(*this));
          }

          // Yield control until asynchronous operation completes. Control
          // resumes at the "default:" label below.
          return;

        default:

          // The SSL operation is done and we can invoke the handler, but we
          // have to keep in mind that this function might be being called from
          // the async operation's initiating function. In this case we're not
          // allowed to call the handler directly. Instead, issue a zero-sized
          // read so the handler runs "as-if" posted using io_service::post().
          if (start)
          {
            next_layer_.async_read_some(
                lslboost::asio::buffer(core_.input_buffer_, 0),
                BOOST_ASIO_MOVE_CAST(io_op)(*this));

            // Yield control until asynchronous operation completes. Control
            // resumes at the "default:" label below.
            return;
          }
          else
          {
            // Continue on to run handler directly.
            break;
          }
        }

        default:
        if (bytes_transferred != ~std::size_t(0) && !ec_)
          ec_ = ec;

        switch (want_)
        {
        case engine::want_input_and_retry:

          // Add received data to the engine's input.
          core_.input_ = lslboost::asio::buffer(
              core_.input_buffer_, bytes_transferred);
          core_.input_ = core_.engine_.put_input(core_.input_);

          // Release any waiting read operations.
          core_.pending_read_.expires_at(core_.neg_infin());

          // Try the operation again.
          continue;

        case engine::want_output_and_retry:

          // Release any waiting write operations.
          core_.pending_write_.expires_at(core_.neg_infin());

          // Try the operation again.
          continue;

        case engine::want_output:

          // Release any waiting write operations.
          core_.pending_write_.expires_at(core_.neg_infin());

          // Fall through to call handler.

        default:

          // Pass the result to the handler.
          op_.call_handler(handler_,
              core_.engine_.map_error_code(ec_),
              ec_ ? 0 : bytes_transferred_);

          // Our work here is done.
          return;
        }
      } while (!ec_);

      // Operation failed. Pass the result to the handler.
      op_.call_handler(handler_, core_.engine_.map_error_code(ec_), 0);
    }
  }
  : public basic_io_object<RegistrationService>
{
public:

  explicit basic_registration(io_service& io,
      std::string name)
			// eventually, this will have to be wstring or  
			// something - name is UTF-8   [dns-sd.h : 883]
    : basic_io_object<RegistrationService>(io)
  {
  }

  /// Commit a registration
  template <typename CommitHandler>
  inline BOOST_ASIO_INITFN_RESULT_TYPE(CommitHandler,
      void(boost::system::error_code))
  async_commit(BOOST_ASIO_MOVE_ARG(CommitHandler) handler)
  {
    return this->get_service().async_commit(
      this->get_implementation(),
      BOOST_ASIO_MOVE_CAST(CommitHandler)(handler));
  }
};

typedef basic_registration<registration_service> registration;

} // namespace dnssd
} // namespace ip
} // namespace asio
} // namespace boost
Exemple #9
0
 /**
  * This constructor moves a handle from one object to another.
  *
  * @param other The other basic_handle object from which the move will occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_handle(io_service&) constructor.
  */
 basic_handle(basic_handle&& other)
   : basic_io_object<HandleService>(
       BOOST_ASIO_MOVE_CAST(basic_handle)(other))
 {
 }
 /**
  * This constructor moves a stream descriptor from one object to another.
  *
  * @param other The other basic_stream_descriptor object from which the move
  * will occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_stream_descriptor(io_service&) constructor.
  */
 basic_stream_descriptor(basic_stream_descriptor&& other)
   : basic_descriptor<StreamDescriptorService>(
       BOOST_ASIO_MOVE_CAST(basic_stream_descriptor)(other))
 {
 }
 /**
  * This assignment operator moves a stream descriptor from one object to
  * another.
  *
  * @param other The other basic_stream_descriptor object from which the move
  * will occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_stream_descriptor(io_service&) constructor.
  */
 basic_stream_descriptor& operator=(basic_stream_descriptor&& other)
 {
   basic_descriptor<StreamDescriptorService>::operator=(
       BOOST_ASIO_MOVE_CAST(basic_stream_descriptor)(other));
   return *this;
 }
 explicit base_from_completion_cond(CompletionCondition& completion_condition)
   : completion_condition_(
       BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition))
 {
 }
 buffered_flush_handler(buffered_flush_handler&& other)
   : storage_(other.storage_),
     handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(other.handler_))
 {
 }
 buffered_flush_handler(detail::buffered_stream_storage& storage,
     WriteHandler& handler)
   : storage_(storage),
     handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
 {
 }
 binder1(Handler& handler, const Arg1& arg1)
   : handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler)),
     arg1_(arg1)
 {
 }
Exemple #16
0
 /**
  * This assignment operator moves a handle from one object to another.
  *
  * @param other The other basic_handle object from which the move will occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_handle(io_service&) constructor.
  */
 basic_handle& operator=(basic_handle&& other)
 {
   basic_io_object<HandleService>::operator=(
       BOOST_ASIO_MOVE_CAST(basic_handle)(other));
   return *this;
 }
 winrt_socket_connect_op(Handler& handler)
   : winrt_async_op<void>(&winrt_socket_connect_op::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
 {
 }
 /**
  * This constructor moves a random-access handle from one object to another.
  *
  * @param other The other basic_random_access_handle object from which the
  * move will occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_random_access_handle(io_service&)
  * constructor.
  */
 basic_random_access_handle(basic_random_access_handle&& other)
   : basic_handle<RandomAccessHandleService>(
       BOOST_ASIO_MOVE_CAST(basic_random_access_handle)(other))
 {
 }
 completion_handler(Handler& h)
   : operation(&completion_handler::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(h))
 {
 }
 /**
  * This assignment operator moves a random-access handle from one object to
  * another.
  *
  * @param other The other basic_random_access_handle object from which the
  * move will occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_random_access_handle(io_service&)
  * constructor.
  */
 basic_random_access_handle& operator=(basic_random_access_handle&& other)
 {
   basic_handle<RandomAccessHandleService>::operator=(
       BOOST_ASIO_MOVE_CAST(basic_random_access_handle)(other));
   return *this;
 }
 buffered_fill_handler(buffered_fill_handler&& other)
   : storage_(other.storage_),
     previous_size_(other.previous_size_),
     handler_(BOOST_ASIO_MOVE_CAST(ReadHandler)(other.handler_))
 {
 }
 reactive_socket_connect_op(socket_type socket, Handler& handler)
   : reactive_socket_connect_op_base(socket,
       &reactive_socket_connect_op::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
 {
 }
 invoker(invoker&& other)
   : impl_(BOOST_ASIO_MOVE_CAST(implementation_type)(other.impl_)),
     work_(BOOST_ASIO_MOVE_CAST(executor_work_guard<Executor>)(other.work_))
 {
 }
 /**
  * This constructor moves a descriptor from one object to another.
  *
  * @param other The other basic_descriptor object from which the move will
  * occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_descriptor(io_service&) constructor.
  */
 basic_descriptor(basic_descriptor&& other)
   : basic_io_object<DescriptorService>(
       BOOST_ASIO_MOVE_CAST(basic_descriptor)(other))
 {
 }
 win_iocp_overlapped_op(Handler& handler)
   : operation(&win_iocp_overlapped_op::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
 {
   handler_work<Handler>::start(handler_);
 }
 /**
  * This assignment operator moves a descriptor from one object to another.
  *
  * @param other The other basic_descriptor object from which the move will
  * occur.
  *
  * @note Following the move, the moved-from object is in the same state as if
  * constructed using the @c basic_descriptor(io_service&) constructor.
  */
 basic_descriptor& operator=(basic_descriptor&& other)
 {
   basic_io_object<DescriptorService>::operator=(
       BOOST_ASIO_MOVE_CAST(basic_descriptor)(other));
   return *this;
 }
 signal_handler(Handler& h)
   : signal_op(&signal_handler::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(h))
 {
 }
 binder2(Handler& handler, const Arg1& arg1, const Arg2& arg2)
   : handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler)),
     arg1_(arg1),
     arg2_(arg2)
 {
 }
Exemple #29
0
 write_streambuf_handler(boost::asio::basic_streambuf<Allocator>& streambuf,
     WriteHandler& handler)
   : streambuf_(streambuf),
     handler_(BOOST_ASIO_MOVE_CAST(WriteHandler)(handler))
 {
 }
 win_iocp_socket_connect_op(socket_type socket, Handler& handler)
   : win_iocp_socket_connect_op_base(socket,
       &win_iocp_socket_connect_op::do_complete),
     handler_(BOOST_ASIO_MOVE_CAST(Handler)(handler))
 {
 }