Skip to content
This repository was archived by the owner on Apr 2, 2020. It is now read-only.

Commit df6fd24

Browse files
committed
async_connection::write_impl implemented via write_vec_impl
1 parent e919844 commit df6fd24

File tree

1 file changed

+39
-69
lines changed

1 file changed

+39
-69
lines changed

boost/network/protocol/http/server/async_connection.hpp

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -218,29 +218,7 @@ namespace boost { namespace network { namespace http {
218218
template <class ConstBufferSeq, class Callback>
219219
void write_vec(ConstBufferSeq const & seq, Callback const & callback)
220220
{
221-
lock_guard lock(headers_mutex);
222-
if (error_encountered)
223-
boost::throw_exception(boost::system::system_error(*error_encountered));
224-
225-
boost::function<void()> continuation = boost::bind(
226-
&async_connection<Tag,Handler>::write_vec<ConstBufferSeq, Callback>
227-
,async_connection<Tag,Handler>::shared_from_this()
228-
,seq, callback
229-
);
230-
231-
if (!headers_already_sent && !headers_in_progress) {
232-
write_headers_only(continuation);
233-
return;
234-
} else if (headers_in_progress && !headers_already_sent) {
235-
pending_actions.push_back(continuation);
236-
return;
237-
}
238-
239-
asio::async_write(
240-
socket_
241-
,seq
242-
,boost::bind(callback, asio::placeholders::error)
243-
);
221+
write_vec_impl(seq, callback, shared_array_list(), shared_buffers());
244222
}
245223

246224
private:
@@ -537,15 +515,6 @@ namespace boost { namespace network { namespace http {
537515

538516
void do_nothing() {}
539517

540-
template <class Range>
541-
void continue_write(Range range, boost::function<void(boost::system::error_code)> callback) {
542-
thread_pool().post(
543-
boost::bind(
544-
&async_connection<Tag,Handler>::write_impl<Range>
545-
, async_connection<Tag,Handler>::shared_from_this()
546-
, range, callback));
547-
}
548-
549518
template <class Callback>
550519
void write_first_line(Callback callback) {
551520
lock_guard lock(headers_mutex);
@@ -630,27 +599,6 @@ namespace boost { namespace network { namespace http {
630599

631600
template <class Range>
632601
void write_impl(Range range, boost::function<void(boost::system::error_code)> callback) {
633-
lock_guard lock(headers_mutex);
634-
boost::function<void(boost::system::error_code)> callback_function =
635-
callback;
636-
637-
if (!headers_already_sent && !headers_in_progress) {
638-
write_headers_only(
639-
boost::bind(
640-
&async_connection<Tag,Handler>::continue_write<Range>
641-
, async_connection<Tag,Handler>::shared_from_this()
642-
, range, callback_function
643-
));
644-
return;
645-
} else if (headers_in_progress && !headers_already_sent) {
646-
pending_actions.push_back(
647-
boost::bind(
648-
&async_connection<Tag,Handler>::continue_write<Range>
649-
, async_connection<Tag,Handler>::shared_from_this()
650-
, range, callback_function));
651-
return;
652-
}
653-
654602
// linearize the whole range into a vector
655603
// of fixed-sized buffers, then schedule an asynchronous
656604
// write of these buffers -- make sure they are live
@@ -697,25 +645,47 @@ namespace boost { namespace network { namespace http {
697645
}
698646

699647
if (!buffers->empty()) {
700-
boost::function<void(boost::system::error_code const &)> f = callback;
701-
asio::async_write(
702-
socket_
703-
, *buffers
704-
, strand.wrap(
705-
boost::bind(
706-
&async_connection<Tag,Handler>::handle_write
707-
, async_connection<Tag,Handler>::shared_from_this()
708-
, f
709-
, temporaries
710-
, buffers // keep these alive until the handler is called!
711-
, boost::asio::placeholders::error
712-
, boost::asio::placeholders::bytes_transferred
713-
)
714-
)
715-
);
648+
write_vec_impl(*buffers, callback, temporaries, buffers);
716649
}
717650
}
718651

652+
template <class ConstBufferSeq, class Callback>
653+
void write_vec_impl(ConstBufferSeq const & seq
654+
,Callback const & callback
655+
,shared_array_list temporaries
656+
,shared_buffers buffers)
657+
{
658+
lock_guard lock(headers_mutex);
659+
if (error_encountered)
660+
boost::throw_exception(boost::system::system_error(*error_encountered));
661+
662+
boost::function<void()> continuation = boost::bind(
663+
&async_connection<Tag,Handler>::write_vec_impl<ConstBufferSeq, Callback>
664+
,async_connection<Tag,Handler>::shared_from_this()
665+
,seq, callback, temporaries, buffers
666+
);
667+
668+
if (!headers_already_sent && !headers_in_progress) {
669+
write_headers_only(continuation);
670+
return;
671+
} else if (headers_in_progress && !headers_already_sent) {
672+
pending_actions.push_back(continuation);
673+
return;
674+
}
675+
676+
asio::async_write(
677+
socket_
678+
,seq
679+
,boost::bind(
680+
&async_connection<Tag,Handler>::handle_write
681+
,async_connection<Tag,Handler>::shared_from_this()
682+
,callback
683+
,temporaries
684+
,buffers
685+
,asio::placeholders::error
686+
,asio::placeholders::bytes_transferred)
687+
);
688+
}
719689
};
720690

721691
} /* http */

0 commit comments

Comments
 (0)