@@ -88,6 +88,46 @@ impl Tcp4 {
8888 }
8989 }
9090
91+ pub ( crate ) fn write ( & self , buf : & [ u8 ] ) -> io:: Result < usize > {
92+ let evt = unsafe { self . create_evt ( ) } ?;
93+ let completion_token =
94+ tcp4:: CompletionToken { event : evt. as_ptr ( ) , status : Status :: SUCCESS } ;
95+ let data_len = crate :: cmp:: min ( u32:: MAX as u64 , buf. len ( ) as u64 ) as u32 ;
96+
97+ let fragment = tcp4:: FragmentData {
98+ fragment_length : data_len,
99+ fragment_buffer : buf. as_ptr ( ) . cast :: < crate :: ffi:: c_void > ( ) . cast_mut ( ) ,
100+ } ;
101+ let mut tx_data = tcp4:: TransmitData {
102+ push : r_efi:: efi:: Boolean :: FALSE ,
103+ urgent : r_efi:: efi:: Boolean :: FALSE ,
104+ data_length : data_len,
105+ fragment_count : 1 ,
106+ fragment_table : [ fragment] ,
107+ } ;
108+
109+ let protocol = self . protocol . as_ptr ( ) ;
110+ let mut token = tcp4:: IoToken {
111+ completion_token,
112+ packet : tcp4:: IoTokenPacket {
113+ tx_data : & mut tx_data as * mut tcp4:: TransmitData < 1 > as * mut tcp4:: TransmitData ,
114+ } ,
115+ } ;
116+
117+ let r = unsafe { ( ( * protocol) . transmit ) ( protocol, & mut token) } ;
118+ if r. is_error ( ) {
119+ return Err ( io:: Error :: from_raw_os_error ( r. as_usize ( ) ) ) ;
120+ }
121+
122+ self . wait_for_flag ( ) ;
123+
124+ if completion_token. status . is_error ( ) {
125+ Err ( io:: Error :: from_raw_os_error ( completion_token. status . as_usize ( ) ) )
126+ } else {
127+ Ok ( data_len as usize )
128+ }
129+ }
130+
91131 unsafe fn create_evt ( & self ) -> io:: Result < helpers:: OwnedEvent > {
92132 self . flag . store ( false , Ordering :: Relaxed ) ;
93133 helpers:: OwnedEvent :: new (
0 commit comments