This
example is input into the
transpiler, the extra python-like syntax is optimized for c++14 and
Seastar. Seastar is optimized for OSv for the best IO performance possible.
with stack:
def handle_connection(s:connected_socket, a:socket_address) -> future<>:
output = s.output()
input = s.input()
return do_with( s, output, input ):
return repeat() and then( callback=lambda:output.close() ):
return input.read() and then( capture=[output], future=[buf] ):
if buf:
return output.write( move(buf) ) and then():
return next
else:
return stop
output
the transpiled c++14 output.
future<> handle_connection(connected_socket s, socket_address a) {
auto output = s.output();
auto input = s.input();
return do_with(std::move(s),std::move(output),std::move(input), [] (auto& s,auto& output,auto& input) {
return repeat([&] {
return input.read().then([&output] (auto buf){
if (buf==true) {
return output.write(std::move(buf)).then([] (){
return stop_iteration::no;
});
} else {
return make_ready_future(stop_iteration::yes);
}
});
}).then([&](){ return output.close(); });
});
}
No comments:
Post a Comment