00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ASIO_BASIC_STREAM_SOCKET_HPP
00012 #define ASIO_BASIC_STREAM_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/error.hpp"
00027 #include "asio/stream_socket_service.hpp"
00028 #include "asio/detail/throw_error.hpp"
00029
00030 namespace asio {
00031
00033
00044 template <typename Protocol,
00045 typename StreamSocketService = stream_socket_service<Protocol> >
00046 class basic_stream_socket
00047 : public basic_socket<Protocol, StreamSocketService>
00048 {
00049 public:
00051 typedef typename StreamSocketService::native_type native_type;
00052
00054 typedef Protocol protocol_type;
00055
00057 typedef typename Protocol::endpoint endpoint_type;
00058
00060
00068 explicit basic_stream_socket(asio::io_service& io_service)
00069 : basic_socket<Protocol, StreamSocketService>(io_service)
00070 {
00071 }
00072
00074
00085 basic_stream_socket(asio::io_service& io_service,
00086 const protocol_type& protocol)
00087 : basic_socket<Protocol, StreamSocketService>(io_service, protocol)
00088 {
00089 }
00090
00093
00106 basic_stream_socket(asio::io_service& io_service,
00107 const endpoint_type& endpoint)
00108 : basic_socket<Protocol, StreamSocketService>(io_service, endpoint)
00109 {
00110 }
00111
00113
00126 basic_stream_socket(asio::io_service& io_service,
00127 const protocol_type& protocol, const native_type& native_socket)
00128 : basic_socket<Protocol, StreamSocketService>(
00129 io_service, protocol, native_socket)
00130 {
00131 }
00132
00134
00158 template <typename ConstBufferSequence>
00159 std::size_t send(const ConstBufferSequence& buffers)
00160 {
00161 asio::error_code ec;
00162 std::size_t s = this->service.send(
00163 this->implementation, buffers, 0, ec);
00164 asio::detail::throw_error(ec);
00165 return s;
00166 }
00167
00169
00195 template <typename ConstBufferSequence>
00196 std::size_t send(const ConstBufferSequence& buffers,
00197 socket_base::message_flags flags)
00198 {
00199 asio::error_code ec;
00200 std::size_t s = this->service.send(
00201 this->implementation, buffers, flags, ec);
00202 asio::detail::throw_error(ec);
00203 return s;
00204 }
00205
00207
00224 template <typename ConstBufferSequence>
00225 std::size_t send(const ConstBufferSequence& buffers,
00226 socket_base::message_flags flags, asio::error_code& ec)
00227 {
00228 return this->service.send(this->implementation, buffers, flags, ec);
00229 }
00230
00232
00266 template <typename ConstBufferSequence, typename WriteHandler>
00267 void async_send(const ConstBufferSequence& buffers, WriteHandler handler)
00268 {
00269 this->service.async_send(this->implementation, buffers, 0, handler);
00270 }
00271
00273
00309 template <typename ConstBufferSequence, typename WriteHandler>
00310 void async_send(const ConstBufferSequence& buffers,
00311 socket_base::message_flags flags, WriteHandler handler)
00312 {
00313 this->service.async_send(this->implementation, buffers, flags, handler);
00314 }
00315
00317
00344 template <typename MutableBufferSequence>
00345 std::size_t receive(const MutableBufferSequence& buffers)
00346 {
00347 asio::error_code ec;
00348 std::size_t s = this->service.receive(this->implementation, buffers, 0, ec);
00349 asio::detail::throw_error(ec);
00350 return s;
00351 }
00352
00354
00383 template <typename MutableBufferSequence>
00384 std::size_t receive(const MutableBufferSequence& buffers,
00385 socket_base::message_flags flags)
00386 {
00387 asio::error_code ec;
00388 std::size_t s = this->service.receive(
00389 this->implementation, buffers, flags, ec);
00390 asio::detail::throw_error(ec);
00391 return s;
00392 }
00393
00395
00412 template <typename MutableBufferSequence>
00413 std::size_t receive(const MutableBufferSequence& buffers,
00414 socket_base::message_flags flags, asio::error_code& ec)
00415 {
00416 return this->service.receive(this->implementation, buffers, flags, ec);
00417 }
00418
00420
00456 template <typename MutableBufferSequence, typename ReadHandler>
00457 void async_receive(const MutableBufferSequence& buffers, ReadHandler handler)
00458 {
00459 this->service.async_receive(this->implementation, buffers, 0, handler);
00460 }
00461
00463
00501 template <typename MutableBufferSequence, typename ReadHandler>
00502 void async_receive(const MutableBufferSequence& buffers,
00503 socket_base::message_flags flags, ReadHandler handler)
00504 {
00505 this->service.async_receive(this->implementation, buffers, flags, handler);
00506 }
00507
00509
00535 template <typename ConstBufferSequence>
00536 std::size_t write_some(const ConstBufferSequence& buffers)
00537 {
00538 asio::error_code ec;
00539 std::size_t s = this->service.send(this->implementation, buffers, 0, ec);
00540 asio::detail::throw_error(ec);
00541 return s;
00542 }
00543
00545
00560 template <typename ConstBufferSequence>
00561 std::size_t write_some(const ConstBufferSequence& buffers,
00562 asio::error_code& ec)
00563 {
00564 return this->service.send(this->implementation, buffers, 0, ec);
00565 }
00566
00568
00602 template <typename ConstBufferSequence, typename WriteHandler>
00603 void async_write_some(const ConstBufferSequence& buffers,
00604 WriteHandler handler)
00605 {
00606 this->service.async_send(this->implementation, buffers, 0, handler);
00607 }
00608
00610
00637 template <typename MutableBufferSequence>
00638 std::size_t read_some(const MutableBufferSequence& buffers)
00639 {
00640 asio::error_code ec;
00641 std::size_t s = this->service.receive(this->implementation, buffers, 0, ec);
00642 asio::detail::throw_error(ec);
00643 return s;
00644 }
00645
00647
00663 template <typename MutableBufferSequence>
00664 std::size_t read_some(const MutableBufferSequence& buffers,
00665 asio::error_code& ec)
00666 {
00667 return this->service.receive(this->implementation, buffers, 0, ec);
00668 }
00669
00671
00706 template <typename MutableBufferSequence, typename ReadHandler>
00707 void async_read_some(const MutableBufferSequence& buffers,
00708 ReadHandler handler)
00709 {
00710 this->service.async_receive(this->implementation, buffers, 0, handler);
00711 }
00712 };
00713
00714 }
00715
00716 #include "asio/detail/pop_options.hpp"
00717
00718 #endif // ASIO_BASIC_STREAM_SOCKET_HPP