Skip to content

Commit

Permalink
Merge pull request qicosmos#204 from KidContainer/master
Browse files Browse the repository at this point in the history
fix keep alive
  • Loading branch information
qicosmos authored Nov 5, 2021
2 parents ef0ba57 + 7aef6d0 commit 9b1b350
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/cinatra/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ class connection : public base_connection,

auto &get_tag() { return tag_; }

bool get_keep_alive(){
return keep_alive_;
}

template <typename... Fs> void send_ws_string(std::string msg, Fs &&...fs) {
send_ws_msg(std::move(msg), opcode::text, std::forward<Fs>(fs)...);
}
Expand Down Expand Up @@ -253,6 +257,9 @@ class connection : public base_connection,
}

call_back();
if(keep_alive_){
do_read();
}
});
}

Expand Down
3 changes: 2 additions & 1 deletion include/cinatra/http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ class http_server_ : private noncopyable {
} break;
case cinatra::data_proc_state::data_end: {
auto conn = req.get_conn<ScoketType>();
conn->on_close();
if(!conn->get_keep_alive())
conn->on_close();
} break;
case cinatra::data_proc_state::data_all_end: {
// network error
Expand Down

0 comments on commit 9b1b350

Please sign in to comment.