@@ -116,7 +116,10 @@ where
116116
117117/// Send the startup packet the server. We're pretending we're a Pg client.
118118/// This tells the server which user we are and what database we want.
119- pub async fn startup ( stream : & mut TcpStream , user : & str , database : & str ) -> Result < ( ) , Error > {
119+ pub async fn startup < S > ( stream : & mut S , user : & str , database : & str ) -> Result < ( ) , Error >
120+ where
121+ S : tokio:: io:: AsyncWrite + std:: marker:: Unpin ,
122+ {
120123 let mut bytes = BytesMut :: with_capacity ( 25 ) ;
121124
122125 bytes. put_i32 ( 196608 ) ; // Protocol number
@@ -150,6 +153,21 @@ pub async fn startup(stream: &mut TcpStream, user: &str, database: &str) -> Resu
150153 }
151154}
152155
156+ pub async fn ssl_request ( stream : & mut TcpStream ) -> Result < ( ) , Error > {
157+ let mut bytes = BytesMut :: with_capacity ( 12 ) ;
158+
159+ bytes. put_i32 ( 8 ) ;
160+ bytes. put_i32 ( 80877103 ) ;
161+
162+ match stream. write_all ( & bytes) . await {
163+ Ok ( _) => Ok ( ( ) ) ,
164+ Err ( err) => Err ( Error :: SocketError ( format ! (
165+ "Error writing SSLRequest to server socket - Error: {:?}" ,
166+ err
167+ ) ) ) ,
168+ }
169+ }
170+
153171/// Parse the params the server sends as a key/value format.
154172pub fn parse_params ( mut bytes : BytesMut ) -> Result < HashMap < String , String > , Error > {
155173 let mut result = HashMap :: new ( ) ;
@@ -505,6 +523,29 @@ where
505523 }
506524}
507525
526+ pub async fn write_all_flush < S > ( stream : & mut S , buf : & [ u8 ] ) -> Result < ( ) , Error >
527+ where
528+ S : tokio:: io:: AsyncWrite + std:: marker:: Unpin ,
529+ {
530+ match stream. write_all ( buf) . await {
531+ Ok ( _) => match stream. flush ( ) . await {
532+ Ok ( _) => Ok ( ( ) ) ,
533+ Err ( err) => {
534+ return Err ( Error :: SocketError ( format ! (
535+ "Error flushing socket - Error: {:?}" ,
536+ err
537+ ) ) )
538+ }
539+ } ,
540+ Err ( err) => {
541+ return Err ( Error :: SocketError ( format ! (
542+ "Error writing to socket - Error: {:?}" ,
543+ err
544+ ) ) )
545+ }
546+ }
547+ }
548+
508549/// Read a complete message from the socket.
509550pub async fn read_message < S > ( stream : & mut S ) -> Result < BytesMut , Error >
510551where
0 commit comments