Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/server/sse_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ void SseServerWrapper::send_event_to_session(const std::string& session_id,

void SseServerWrapper::run_server()
{
// Just run the server - routes are already set up
svr_->listen(host_.c_str(), port_);
// Just run the server - bind was already done in start()
svr_->listen_after_bind();
running_ = false;
}

Expand Down Expand Up @@ -557,6 +557,21 @@ bool SseServerWrapper::start()
}
});

// Bind synchronously to get actual port (supports port 0 / OS auto-assign).
// bind_to_any_port() returns the assigned port; bind_to_port() returns bool.
if (port_ == 0)
{
int bound_port = svr_->bind_to_any_port(host_);
if (bound_port <= 0)
return false;
port_ = bound_port;
}
else
{
if (!svr_->bind_to_port(host_, port_))
return false;
}

running_ = true;

thread_ = std::thread([this]() { run_server(); });
Expand Down