]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/seastar/demos/websocket_demo.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / seastar / demos / websocket_demo.cc
index 7ea612a7c59f29a4404fba505fc86b40fa2b28c8..c19cb0fc2b009a0b18e869b896d9bce2dcfbbb14 100644 (file)
@@ -36,8 +36,25 @@ int main(int argc, char** argv) {
     seastar::app_template app;
     app.run(argc, argv, [] () -> seastar::future<> {
         return async([] {
-            websocket::server ws;
-            auto d = defer([&ws] () noexcept {
+            static websocket::server ws;
+            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);
+                                });
+                            });
+                        }
+                    });
+                });
+            });
+            auto d = defer([] () noexcept {
                 ws.stop().get();
             });
             ws.listen(socket_address(ipv4_addr("127.0.0.1", 8123)));