Skip to content

Instantly share code, notes, and snippets.

@PeterCorless
Created August 11, 2022 15:51
Show Gist options
  • Save PeterCorless/436e3ee3eceb948e59564cb2834a7a9f to your computer and use it in GitHub Desktop.
Save PeterCorless/436e3ee3eceb948e59564cb2834a7a9f to your computer and use it in GitHub Desktop.
WebSocket in Seastar
ws.register_handler("echo", [] (input_stream<char>& in,
output_stream<char>& out) {
return repeat([&in, &out]() {
return in.read().then([&out](temporary_buffer<char> f) {
std::cerr << "f.size(): " << f.size() << "\n";
if (f.empty()) {
return make_ready_future<stop_iteration>(stop_iteration::yes);
} else {
return out.write(std::move(f)).then([&out]() {
return out.flush().then([] {
return make_ready_future<stop_iteration>(stop_iteration::no);
});
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment