5 #include <boost/asio.hpp>
6 #include <boost/bind.hpp>
7 #include <boost/thread.hpp>
26 void operator()(
const boost::system::error_code& ec,
size_t bytes_transferred);
35 const std::shared_ptr<const char>& buffer);
36 void operator()(
const boost::system::error_code& ec,
size_t bytes_transferred);
39 std::shared_ptr<const char> _buffer;
46 boost::system::error_code* oec,
47 const boost::system::error_code& ec,
48 size_t bytes_transferred );
50 const boost::system::error_code& ec );
52 const boost::system::error_code& ec );
57 bool operator()( C& c,
bool s ) { c.non_blocking(s);
return true; }
60 #if WIN32 // windows stream handles do not support non blocking!
62 struct non_blocking<boost::asio::windows::stream_handle> {
63 typedef boost::asio::windows::stream_handle C;
81 boost::asio::io_service*
io;
83 std::vector<boost::thread*> asio_threads;
84 boost::asio::io_service::work* the_work;
102 template<
typename AsyncReadStream,
typename MutableBufferSequence>
103 size_t read( AsyncReadStream& s,
const MutableBufferSequence& buf ) {
121 template<
typename AsyncReadStream,
typename MutableBufferSequence>
126 return completion_promise;
129 template<
typename AsyncReadStream>
133 s.async_read_some(boost::asio::buffer(buffer + offset, length),
135 return completion_promise;
138 template<
typename AsyncReadStream>
142 s.async_read_some(boost::asio::buffer(buffer.get() + offset, length),
144 return completion_promise;
147 template<
typename AsyncReadStream,
typename MutableBufferSequence>
153 template<
typename AsyncReadStream>
160 template<
typename AsyncReadStream>
167 template<
typename AsyncReadStream>
168 size_t read_some( AsyncReadStream& s, boost::asio::streambuf& buf )
171 size_t bytes_read =
read_some( s, boost::asio::buffer( buffer,
sizeof(buffer) ) );
172 buf.sputn( buffer, bytes_read );
179 template<
typename AsyncWriteStream,
typename ConstBufferSequence>
180 size_t write( AsyncWriteStream& s,
const ConstBufferSequence& buf ) {
191 template<
typename AsyncWriteStream,
typename ConstBufferSequence>
198 template<
typename AsyncWriteStream>
200 size_t length,
size_t offset = 0) {
206 template<
typename AsyncWriteStream>
208 size_t length,
size_t offset ) {
219 template<
typename AsyncWriteStream,
typename ConstBufferSequence>
224 template<
typename AsyncWriteStream>
227 s.async_write_some(boost::asio::buffer(buffer, length),
231 template<
typename AsyncWriteStream>
234 s.async_write_some(boost::asio::buffer(buffer.get() + offset, length),
242 std::vector<endpoint>
resolve(
const std::string& hostname,
const std::string& port );
249 template<
typename SocketType,
typename AcceptorType>
250 void accept( AcceptorType& acc, SocketType& sock ) {
261 template<
typename AsyncSocket,
typename Endpo
intType>
262 void connect( AsyncSocket& sock,
const EndpointType& ep ) {
274 std::vector<endpoint>
resolve(
resolver& r,
const std::string& hostname,
275 const std::string& port );
278 template<
typename AsyncReadStream>
282 istream( std::shared_ptr<AsyncReadStream> str )
283 :_stream(
std::move(str) ){}
289 virtual size_t readsome(
const std::shared_ptr<char>& buf,
size_t len,
size_t offset )
295 std::shared_ptr<AsyncReadStream> _stream;
298 template<
typename AsyncWriteStream>
302 ostream( std::shared_ptr<AsyncWriteStream> str )
303 :_stream(
std::move(str) ){}
310 virtual size_t writesome(
const std::shared_ptr<const char>& buf,
size_t len,
size_t offset )
315 virtual void close(){ _stream->close(); }
318 std::shared_ptr<AsyncWriteStream> _stream;