Add on_write_buffer_drained
This commit is contained in:
@@ -485,6 +485,7 @@ void Server::process_connection_writes(std::unique_ptr<Connection> &conn,
|
||||
// Send immediately if we have outgoing messages (either from EPOLLOUT or
|
||||
// after reading)
|
||||
if ((events & EPOLLOUT) || ((events & EPOLLIN) && conn->hasMessages())) {
|
||||
bool had_messages = conn->hasMessages();
|
||||
bool error = conn->writeBytes();
|
||||
if (error) {
|
||||
conn.reset(); // Connection should be closed
|
||||
@@ -499,8 +500,17 @@ void Server::process_connection_writes(std::unique_ptr<Connection> &conn,
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if buffer became empty (transition from non-empty -> empty)
|
||||
if (had_messages && !conn->hasMessages()) {
|
||||
handler_.on_write_buffer_drained(conn);
|
||||
// If handler took ownership (conn is now null), return
|
||||
if (!conn) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should close the connection according to application
|
||||
if (!conn->hasMessages() && conn->closeConnection_) {
|
||||
if (!conn->hasMessages() && conn->shouldClose()) {
|
||||
conn.reset(); // Connection should be closed
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user