$search
00001 // 00002 // basic_raw_socket.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_BASIC_RAW_SOCKET_HPP 00012 #define ASIO_BASIC_RAW_SOCKET_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/basic_socket.hpp" 00026 #include "asio/raw_socket_service.hpp" 00027 #include "asio/error.hpp" 00028 #include "asio/detail/throw_error.hpp" 00029 00030 namespace asio { 00031 00033 00041 template <typename Protocol, 00042 typename RawSocketService = raw_socket_service<Protocol> > 00043 class basic_raw_socket 00044 : public basic_socket<Protocol, RawSocketService> 00045 { 00046 public: 00048 typedef typename RawSocketService::native_type native_type; 00049 00051 typedef Protocol protocol_type; 00052 00054 typedef typename Protocol::endpoint endpoint_type; 00055 00057 00065 explicit basic_raw_socket(asio::io_service& io_service) 00066 : basic_socket<Protocol, RawSocketService>(io_service) 00067 { 00068 } 00069 00071 00082 basic_raw_socket(asio::io_service& io_service, 00083 const protocol_type& protocol) 00084 : basic_socket<Protocol, RawSocketService>(io_service, protocol) 00085 { 00086 } 00087 00090 00104 basic_raw_socket(asio::io_service& io_service, 00105 const endpoint_type& endpoint) 00106 : basic_socket<Protocol, RawSocketService>(io_service, endpoint) 00107 { 00108 } 00109 00111 00125 basic_raw_socket(asio::io_service& io_service, 00126 const protocol_type& protocol, const native_type& native_socket) 00127 : basic_socket<Protocol, RawSocketService>( 00128 io_service, protocol, native_socket) 00129 { 00130 } 00131 00133 00153 template <typename ConstBufferSequence> 00154 std::size_t send(const ConstBufferSequence& buffers) 00155 { 00156 asio::error_code ec; 00157 std::size_t s = this->service.send(this->implementation, buffers, 0, ec); 00158 asio::detail::throw_error(ec); 00159 return s; 00160 } 00161 00163 00178 template <typename ConstBufferSequence> 00179 std::size_t send(const ConstBufferSequence& buffers, 00180 socket_base::message_flags flags) 00181 { 00182 asio::error_code ec; 00183 std::size_t s = this->service.send( 00184 this->implementation, buffers, flags, ec); 00185 asio::detail::throw_error(ec); 00186 return s; 00187 } 00188 00190 00205 template <typename ConstBufferSequence> 00206 std::size_t send(const ConstBufferSequence& buffers, 00207 socket_base::message_flags flags, asio::error_code& ec) 00208 { 00209 return this->service.send(this->implementation, buffers, flags, ec); 00210 } 00211 00213 00247 template <typename ConstBufferSequence, typename WriteHandler> 00248 void async_send(const ConstBufferSequence& buffers, WriteHandler handler) 00249 { 00250 this->service.async_send(this->implementation, buffers, 0, handler); 00251 } 00252 00254 00281 template <typename ConstBufferSequence, typename WriteHandler> 00282 void async_send(const ConstBufferSequence& buffers, 00283 socket_base::message_flags flags, WriteHandler handler) 00284 { 00285 this->service.async_send(this->implementation, buffers, flags, handler); 00286 } 00287 00289 00313 template <typename ConstBufferSequence> 00314 std::size_t send_to(const ConstBufferSequence& buffers, 00315 const endpoint_type& destination) 00316 { 00317 asio::error_code ec; 00318 std::size_t s = this->service.send_to( 00319 this->implementation, buffers, destination, 0, ec); 00320 asio::detail::throw_error(ec); 00321 return s; 00322 } 00323 00325 00340 template <typename ConstBufferSequence> 00341 std::size_t send_to(const ConstBufferSequence& buffers, 00342 const endpoint_type& destination, socket_base::message_flags flags) 00343 { 00344 asio::error_code ec; 00345 std::size_t s = this->service.send_to( 00346 this->implementation, buffers, destination, flags, ec); 00347 asio::detail::throw_error(ec); 00348 return s; 00349 } 00350 00352 00367 template <typename ConstBufferSequence> 00368 std::size_t send_to(const ConstBufferSequence& buffers, 00369 const endpoint_type& destination, socket_base::message_flags flags, 00370 asio::error_code& ec) 00371 { 00372 return this->service.send_to(this->implementation, 00373 buffers, destination, flags, ec); 00374 } 00375 00377 00413 template <typename ConstBufferSequence, typename WriteHandler> 00414 void async_send_to(const ConstBufferSequence& buffers, 00415 const endpoint_type& destination, WriteHandler handler) 00416 { 00417 this->service.async_send_to(this->implementation, buffers, destination, 0, 00418 handler); 00419 } 00420 00422 00448 template <typename ConstBufferSequence, typename WriteHandler> 00449 void async_send_to(const ConstBufferSequence& buffers, 00450 const endpoint_type& destination, socket_base::message_flags flags, 00451 WriteHandler handler) 00452 { 00453 this->service.async_send_to(this->implementation, buffers, destination, 00454 flags, handler); 00455 } 00456 00458 00481 template <typename MutableBufferSequence> 00482 std::size_t receive(const MutableBufferSequence& buffers) 00483 { 00484 asio::error_code ec; 00485 std::size_t s = this->service.receive( 00486 this->implementation, buffers, 0, ec); 00487 asio::detail::throw_error(ec); 00488 return s; 00489 } 00490 00492 00509 template <typename MutableBufferSequence> 00510 std::size_t receive(const MutableBufferSequence& buffers, 00511 socket_base::message_flags flags) 00512 { 00513 asio::error_code ec; 00514 std::size_t s = this->service.receive( 00515 this->implementation, buffers, flags, ec); 00516 asio::detail::throw_error(ec); 00517 return s; 00518 } 00519 00521 00538 template <typename MutableBufferSequence> 00539 std::size_t receive(const MutableBufferSequence& buffers, 00540 socket_base::message_flags flags, asio::error_code& ec) 00541 { 00542 return this->service.receive(this->implementation, buffers, flags, ec); 00543 } 00544 00546 00581 template <typename MutableBufferSequence, typename ReadHandler> 00582 void async_receive(const MutableBufferSequence& buffers, ReadHandler handler) 00583 { 00584 this->service.async_receive(this->implementation, buffers, 0, handler); 00585 } 00586 00588 00615 template <typename MutableBufferSequence, typename ReadHandler> 00616 void async_receive(const MutableBufferSequence& buffers, 00617 socket_base::message_flags flags, ReadHandler handler) 00618 { 00619 this->service.async_receive(this->implementation, buffers, flags, handler); 00620 } 00621 00623 00648 template <typename MutableBufferSequence> 00649 std::size_t receive_from(const MutableBufferSequence& buffers, 00650 endpoint_type& sender_endpoint) 00651 { 00652 asio::error_code ec; 00653 std::size_t s = this->service.receive_from( 00654 this->implementation, buffers, sender_endpoint, 0, ec); 00655 asio::detail::throw_error(ec); 00656 return s; 00657 } 00658 00660 00675 template <typename MutableBufferSequence> 00676 std::size_t receive_from(const MutableBufferSequence& buffers, 00677 endpoint_type& sender_endpoint, socket_base::message_flags flags) 00678 { 00679 asio::error_code ec; 00680 std::size_t s = this->service.receive_from( 00681 this->implementation, buffers, sender_endpoint, flags, ec); 00682 asio::detail::throw_error(ec); 00683 return s; 00684 } 00685 00687 00702 template <typename MutableBufferSequence> 00703 std::size_t receive_from(const MutableBufferSequence& buffers, 00704 endpoint_type& sender_endpoint, socket_base::message_flags flags, 00705 asio::error_code& ec) 00706 { 00707 return this->service.receive_from(this->implementation, buffers, 00708 sender_endpoint, flags, ec); 00709 } 00710 00712 00747 template <typename MutableBufferSequence, typename ReadHandler> 00748 void async_receive_from(const MutableBufferSequence& buffers, 00749 endpoint_type& sender_endpoint, ReadHandler handler) 00750 { 00751 this->service.async_receive_from(this->implementation, buffers, 00752 sender_endpoint, 0, handler); 00753 } 00754 00756 00784 template <typename MutableBufferSequence, typename ReadHandler> 00785 void async_receive_from(const MutableBufferSequence& buffers, 00786 endpoint_type& sender_endpoint, socket_base::message_flags flags, 00787 ReadHandler handler) 00788 { 00789 this->service.async_receive_from(this->implementation, buffers, 00790 sender_endpoint, flags, handler); 00791 } 00792 }; 00793 00794 } // namespace asio 00795 00796 #include "asio/detail/pop_options.hpp" 00797 00798 #endif // ASIO_BASIC_RAW_SOCKET_HPP