raw_socket_service.hpp
Go to the documentation of this file.
00001 //
00002 // raw_socket_service.hpp
00003 // ~~~~~~~~~~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef ASIO_RAW_SOCKET_SERVICE_HPP
00012 #define ASIO_RAW_SOCKET_SERVICE_HPP
00013 
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017 
00018 #include "asio/detail/push_options.hpp"
00019 
00020 #include "asio/detail/push_options.hpp"
00021 #include <cstddef>
00022 #include <boost/config.hpp>
00023 #include "asio/detail/pop_options.hpp"
00024 
00025 #include "asio/error.hpp"
00026 #include "asio/io_service.hpp"
00027 #include "asio/detail/epoll_reactor.hpp"
00028 #include "asio/detail/kqueue_reactor.hpp"
00029 #include "asio/detail/select_reactor.hpp"
00030 #include "asio/detail/service_base.hpp"
00031 #include "asio/detail/reactive_socket_service.hpp"
00032 #include "asio/detail/win_iocp_socket_service.hpp"
00033 
00034 namespace asio {
00035 
00037 template <typename Protocol>
00038 class raw_socket_service
00039 #if defined(GENERATING_DOCUMENTATION)
00040   : public asio::io_service::service
00041 #else
00042   : public asio::detail::service_base<raw_socket_service<Protocol> >
00043 #endif
00044 {
00045 public:
00046 #if defined(GENERATING_DOCUMENTATION)
00047 
00048   static asio::io_service::id id;
00049 #endif
00050 
00052   typedef Protocol protocol_type;
00053 
00055   typedef typename Protocol::endpoint endpoint_type;
00056 
00057 private:
00058   // The type of the platform-specific implementation.
00059 #if defined(ASIO_HAS_IOCP)
00060   typedef detail::win_iocp_socket_service<Protocol> service_impl_type;
00061 #elif defined(ASIO_HAS_EPOLL)
00062   typedef detail::reactive_socket_service<
00063       Protocol, detail::epoll_reactor<false> > service_impl_type;
00064 #elif defined(ASIO_HAS_KQUEUE)
00065   typedef detail::reactive_socket_service<
00066       Protocol, detail::kqueue_reactor<false> > service_impl_type;
00067 #elif defined(ASIO_HAS_DEV_POLL)
00068   typedef detail::reactive_socket_service<
00069       Protocol, detail::dev_poll_reactor<false> > service_impl_type;
00070 #else
00071   typedef detail::reactive_socket_service<
00072       Protocol, detail::select_reactor<false> > service_impl_type;
00073 #endif
00074 
00075 public:
00077 #if defined(GENERATING_DOCUMENTATION)
00078   typedef implementation_defined implementation_type;
00079 #else
00080   typedef typename service_impl_type::implementation_type implementation_type;
00081 #endif
00082 
00084 #if defined(GENERATING_DOCUMENTATION)
00085   typedef implementation_defined native_type;
00086 #else
00087   typedef typename service_impl_type::native_type native_type;
00088 #endif
00089 
00091   explicit raw_socket_service(asio::io_service& io_service)
00092     : asio::detail::service_base<
00093         raw_socket_service<Protocol> >(io_service),
00094       service_impl_(asio::use_service<service_impl_type>(io_service))
00095   {
00096   }
00097 
00099   void shutdown_service()
00100   {
00101   }
00102 
00104   void construct(implementation_type& impl)
00105   {
00106     service_impl_.construct(impl);
00107   }
00108 
00110   void destroy(implementation_type& impl)
00111   {
00112     service_impl_.destroy(impl);
00113   }
00114 
00115   // Open a new raw socket implementation.
00116   asio::error_code open(implementation_type& impl,
00117       const protocol_type& protocol, asio::error_code& ec)
00118   {
00119     if (protocol.type() == SOCK_RAW)
00120       service_impl_.open(impl, protocol, ec);
00121     else
00122       ec = asio::error::invalid_argument;
00123     return ec;
00124   }
00125 
00127   asio::error_code assign(implementation_type& impl,
00128       const protocol_type& protocol, const native_type& native_socket,
00129       asio::error_code& ec)
00130   {
00131     return service_impl_.assign(impl, protocol, native_socket, ec);
00132   }
00133 
00135   bool is_open(const implementation_type& impl) const
00136   {
00137     return service_impl_.is_open(impl);
00138   }
00139 
00141   asio::error_code close(implementation_type& impl,
00142       asio::error_code& ec)
00143   {
00144     return service_impl_.close(impl, ec);
00145   }
00146 
00148   native_type native(implementation_type& impl)
00149   {
00150     return service_impl_.native(impl);
00151   }
00152 
00154   asio::error_code cancel(implementation_type& impl,
00155       asio::error_code& ec)
00156   {
00157     return service_impl_.cancel(impl, ec);
00158   }
00159 
00161   bool at_mark(const implementation_type& impl,
00162       asio::error_code& ec) const
00163   {
00164     return service_impl_.at_mark(impl, ec);
00165   }
00166 
00168   std::size_t available(const implementation_type& impl,
00169       asio::error_code& ec) const
00170   {
00171     return service_impl_.available(impl, ec);
00172   }
00173 
00174   // Bind the raw socket to the specified local endpoint.
00175   asio::error_code bind(implementation_type& impl,
00176       const endpoint_type& endpoint, asio::error_code& ec)
00177   {
00178     return service_impl_.bind(impl, endpoint, ec);
00179   }
00180 
00182   asio::error_code connect(implementation_type& impl,
00183       const endpoint_type& peer_endpoint, asio::error_code& ec)
00184   {
00185     return service_impl_.connect(impl, peer_endpoint, ec);
00186   }
00187 
00189   template <typename ConnectHandler>
00190   void async_connect(implementation_type& impl,
00191       const endpoint_type& peer_endpoint, ConnectHandler handler)
00192   {
00193     service_impl_.async_connect(impl, peer_endpoint, handler);
00194   }
00195 
00197   template <typename SettableSocketOption>
00198   asio::error_code set_option(implementation_type& impl,
00199       const SettableSocketOption& option, asio::error_code& ec)
00200   {
00201     return service_impl_.set_option(impl, option, ec);
00202   }
00203 
00205   template <typename GettableSocketOption>
00206   asio::error_code get_option(const implementation_type& impl,
00207       GettableSocketOption& option, asio::error_code& ec) const
00208   {
00209     return service_impl_.get_option(impl, option, ec);
00210   }
00211 
00213   template <typename IoControlCommand>
00214   asio::error_code io_control(implementation_type& impl,
00215       IoControlCommand& command, asio::error_code& ec)
00216   {
00217     return service_impl_.io_control(impl, command, ec);
00218   }
00219 
00221   endpoint_type local_endpoint(const implementation_type& impl,
00222       asio::error_code& ec) const
00223   {
00224     return service_impl_.local_endpoint(impl, ec);
00225   }
00226 
00228   endpoint_type remote_endpoint(const implementation_type& impl,
00229       asio::error_code& ec) const
00230   {
00231     return service_impl_.remote_endpoint(impl, ec);
00232   }
00233 
00235   asio::error_code shutdown(implementation_type& impl,
00236       socket_base::shutdown_type what, asio::error_code& ec)
00237   {
00238     return service_impl_.shutdown(impl, what, ec);
00239   }
00240 
00242   template <typename ConstBufferSequence>
00243   std::size_t send(implementation_type& impl,
00244       const ConstBufferSequence& buffers,
00245       socket_base::message_flags flags, asio::error_code& ec)
00246   {
00247     return service_impl_.send(impl, buffers, flags, ec);
00248   }
00249 
00251   template <typename ConstBufferSequence, typename WriteHandler>
00252   void async_send(implementation_type& impl, const ConstBufferSequence& buffers,
00253       socket_base::message_flags flags, WriteHandler handler)
00254   {
00255     service_impl_.async_send(impl, buffers, flags, handler);
00256   }
00257 
00259   template <typename ConstBufferSequence>
00260   std::size_t send_to(implementation_type& impl,
00261       const ConstBufferSequence& buffers, const endpoint_type& destination,
00262       socket_base::message_flags flags, asio::error_code& ec)
00263   {
00264     return service_impl_.send_to(impl, buffers, destination, flags, ec);
00265   }
00266 
00268   template <typename ConstBufferSequence, typename WriteHandler>
00269   void async_send_to(implementation_type& impl,
00270       const ConstBufferSequence& buffers, const endpoint_type& destination,
00271       socket_base::message_flags flags, WriteHandler handler)
00272   {
00273     service_impl_.async_send_to(impl, buffers, destination, flags, handler);
00274   }
00275 
00277   template <typename MutableBufferSequence>
00278   std::size_t receive(implementation_type& impl,
00279       const MutableBufferSequence& buffers,
00280       socket_base::message_flags flags, asio::error_code& ec)
00281   {
00282     return service_impl_.receive(impl, buffers, flags, ec);
00283   }
00284 
00286   template <typename MutableBufferSequence, typename ReadHandler>
00287   void async_receive(implementation_type& impl,
00288       const MutableBufferSequence& buffers,
00289       socket_base::message_flags flags, ReadHandler handler)
00290   {
00291     service_impl_.async_receive(impl, buffers, flags, handler);
00292   }
00293 
00295   template <typename MutableBufferSequence>
00296   std::size_t receive_from(implementation_type& impl,
00297       const MutableBufferSequence& buffers, endpoint_type& sender_endpoint,
00298       socket_base::message_flags flags, asio::error_code& ec)
00299   {
00300     return service_impl_.receive_from(impl, buffers, sender_endpoint, flags,
00301         ec);
00302   }
00303 
00305   template <typename MutableBufferSequence, typename ReadHandler>
00306   void async_receive_from(implementation_type& impl,
00307       const MutableBufferSequence& buffers, endpoint_type& sender_endpoint,
00308       socket_base::message_flags flags, ReadHandler handler)
00309   {
00310     service_impl_.async_receive_from(impl, buffers, sender_endpoint, flags,
00311         handler);
00312   }
00313 
00314 private:
00315   // The service that provides the platform-specific implementation.
00316   service_impl_type& service_impl_;
00317 };
00318 
00319 } // namespace asio
00320 
00321 #include "asio/detail/pop_options.hpp"
00322 
00323 #endif // ASIO_RAW_SOCKET_SERVICE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:39