@@ -81,18 +81,37 @@ pub async fn read_auth_message<S: AsyncRead + Unpin>(
8181 Authentication :: try_from ( & bytes)
8282}
8383
84+ ///
85+ /// Reads a Postgres message from client with an optional timeout
86+ ///
87+ /// Timeout values are in config
88+ ///
89+ ///
90+ pub async fn read_message < S : AsyncRead + Unpin > (
91+ mut stream : S ,
92+ client_id : i32 ,
93+ connection_timeout : Option < Duration > ,
94+ ) -> Result < ( Code , BytesMut ) , Error > {
95+ match connection_timeout {
96+ Some ( duration) => read_message_with_timeout ( stream, client_id, duration) . await ,
97+ None => read ( & mut stream, client_id) . await ,
98+ }
99+ }
100+
84101///
85102/// Reads a Postgres message from client with a timeout
86103///
87104/// Timeout values are in config
88105///
89106///
90- pub async fn read_message_with_timeout < S : AsyncRead + Unpin > (
107+ async fn read_message_with_timeout < S : AsyncRead + Unpin > (
91108 mut stream : S ,
92109 client_id : i32 ,
93- connection_timeout : Duration ,
110+ duration : Duration ,
94111) -> Result < ( Code , BytesMut ) , Error > {
95- timeout ( connection_timeout, read_message ( & mut stream, client_id) ) . await ?
112+ timeout ( duration, read ( & mut stream, client_id) )
113+ . await
114+ . map_err ( |_| Error :: ConnectionTimeout { duration } ) ?
96115}
97116
98117///
@@ -102,7 +121,7 @@ pub async fn read_message_with_timeout<S: AsyncRead + Unpin>(
102121/// Byte is then passed as `code` to this function to preserve the message structure
103122///
104123///
105- pub async fn read_message < S : AsyncRead + Unpin > (
124+ async fn read < S : AsyncRead + Unpin > (
106125 mut stream : S ,
107126 client_id : i32 ,
108127) -> Result < ( Code , BytesMut ) , Error > {
0 commit comments