11use crate :: * ;
22
3+ /// Implementation of TCP request operations.
34impl TcpRequest {
5+ /// Sends data through the TCP connection.
6+ ///
7+ /// # Arguments
8+ ///
9+ /// - `&mut TcpStream` - The TCP stream to send data through.
10+ /// - `&[u8]` - The data to be sent.
11+ ///
12+ /// # Returns
13+ ///
14+ /// - `Result<BoxResponseTrait, RequestError>` - The response or error.
415 fn send_request (
516 & mut self ,
617 stream : & mut TcpStream ,
@@ -15,6 +26,15 @@ impl TcpRequest {
1526 self . read_response ( stream)
1627 }
1728
29+ /// Reads response from the TCP connection.
30+ ///
31+ /// # Arguments
32+ ///
33+ /// - `&mut TcpStream` - The TCP stream to read from.
34+ ///
35+ /// # Returns
36+ ///
37+ /// - `Result<BoxResponseTrait, RequestError>` - The response or error.
1838 fn read_response ( & mut self , stream : & mut TcpStream ) -> Result < BoxResponseTrait , RequestError > {
1939 let cfg_buffer_size: usize = self
2040 . config
@@ -36,6 +56,16 @@ impl TcpRequest {
3656 ) ) ;
3757 }
3858
59+ /// Establishes a TCP connection to the specified host and port.
60+ ///
61+ /// # Arguments
62+ ///
63+ /// - `String` - The host address to connect to.
64+ /// - `usize` - The port number to connect to.
65+ ///
66+ /// # Returns
67+ ///
68+ /// - `Result<TcpStream, RequestError>` - The TCP stream or error.
3969 fn get_connection_stream ( & self , host : String , port : usize ) -> Result < TcpStream , RequestError > {
4070 let host_port: ( String , u16 ) = ( host. clone ( ) , port as u16 ) ;
4171 let cfg_timeout: u64 = self
@@ -56,9 +86,19 @@ impl TcpRequest {
5686 }
5787}
5888
89+ /// RequestTrait implementation for TcpRequest.
5990impl RequestTrait for TcpRequest {
6091 type RequestResult = RequestResult ;
6192
93+ /// Sends data through the TCP request.
94+ ///
95+ /// # Arguments
96+ ///
97+ /// - `&[u8]` - The data to be sent.
98+ ///
99+ /// # Returns
100+ ///
101+ /// - `RequestResult` - The result of the send operation.
62102 fn send ( & mut self , data : & [ u8 ] ) -> Self :: RequestResult {
63103 let cfg_timeout: Config = self
64104 . config
@@ -74,7 +114,13 @@ impl RequestTrait for TcpRequest {
74114 }
75115}
76116
117+ /// Default implementation for TcpRequest.
77118impl Default for TcpRequest {
119+ /// Creates a default TcpRequest instance.
120+ ///
121+ /// # Returns
122+ ///
123+ /// - `TcpRequest` - A new TcpRequest instance with default configuration.
78124 fn default ( ) -> Self {
79125 Self {
80126 config : Arc :: new ( RwLock :: new ( Config :: default ( ) ) ) ,
0 commit comments