Skip to content

How to make 'seastar::connected_socket' and RAII work together? #2718

Open
@kelbon

Description

@kelbon

Same question about seastar::sharded etc.

I have seastar::connected_socket.
It requires, that its .close must be called AND awaited before destructor. I dont see how it may work with RAII, i run into endless asserions in socket destructor / memory leaks on program end when in destructor i start future with "correct" socket destruction and move socket into it

Also, i dont see any example how to close seastar socket correctly. Is this code correctly closes seastar::connected_socket ?

seastar::future<> close_socket(socket_its_input_and_its_output impl) {
try {
  co_await impl->input.close();
  while (!impl->input.eof()) {
    co_await impl->input.read();
  }
  co_await impl->output.close();
  impl->sock.shutdown_input();
  impl->sock.shutdown_output();
  co_await impl->sock.wait_input_shutdown();
catch(...) {
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions