33use std:: net:: SocketAddr ;
44use std:: time:: { Duration , Instant } ;
55
6- use bytes:: BytesMut ;
76use timeouts:: Timeouts ;
87use tokio:: { select, spawn, time:: timeout} ;
98use tracing:: { debug, enabled, error, info, trace, Level as LogLevel } ;
@@ -21,8 +20,8 @@ use crate::net::messages::{
2120 Authentication , BackendKeyData , ErrorResponse , FromBytes , Message , Password , Protocol ,
2221 ReadyForQuery , ToBytes ,
2322} ;
24- use crate :: net:: ProtocolMessage ;
2523use crate :: net:: { parameter:: Parameters , Stream } ;
24+ use crate :: net:: { MessageBuffer , ProtocolMessage } ;
2625use crate :: state:: State ;
2726use crate :: stats:: memory:: MemoryUsage ;
2827use crate :: util:: user_database_from_params;
@@ -47,7 +46,7 @@ pub struct Client {
4746 transaction : Option < TransactionType > ,
4847 timeouts : Timeouts ,
4948 client_request : ClientRequest ,
50- stream_buffer : BytesMut ,
49+ stream_buffer : MessageBuffer ,
5150 passthrough_password : Option < String > ,
5251}
5352
@@ -86,7 +85,7 @@ impl MemoryUsage for Client {
8685 + std:: mem:: size_of :: < bool > ( ) * 5
8786 + self . prepared_statements . memory_used ( )
8887 + std:: mem:: size_of :: < Timeouts > ( )
89- + self . stream_buffer . memory_usage ( )
88+ + self . stream_buffer . capacity ( )
9089 + self . client_request . memory_usage ( )
9190 + self
9291 . passthrough_password
@@ -301,7 +300,7 @@ impl Client {
301300 transaction : None ,
302301 timeouts : Timeouts :: from_config ( & config. config . general ) ,
303302 client_request : ClientRequest :: new ( ) ,
304- stream_buffer : BytesMut :: new ( ) ,
303+ stream_buffer : MessageBuffer :: new ( ) ,
305304 shutdown : false ,
306305 passthrough_password,
307306 } ) )
@@ -328,7 +327,7 @@ impl Client {
328327 transaction : None ,
329328 timeouts : Timeouts :: from_config ( & config ( ) . config . general ) ,
330329 client_request : ClientRequest :: new ( ) ,
331- stream_buffer : BytesMut :: new ( ) ,
330+ stream_buffer : MessageBuffer :: new ( ) ,
332331 shutdown : false ,
333332 passthrough_password : None ,
334333 }
@@ -491,7 +490,7 @@ impl Client {
491490 . client_idle_timeout ( & state, & self . client_request ) ;
492491
493492 let message =
494- match timeout ( idle_timeout, self . stream . read_buf ( & mut self . stream_buffer ) ) . await {
493+ match timeout ( idle_timeout, self . stream_buffer . read ( & mut self . stream ) ) . await {
495494 Err ( _) => {
496495 self . stream
497496 . fatal ( ErrorResponse :: client_idle_timeout ( idle_timeout) )
0 commit comments