@@ -73,7 +73,7 @@ impl Server {
7373 }
7474
7575 #[ napi]
76- pub async unsafe fn abort ( & mut self ) {
76+ pub async fn abort ( & self ) {
7777 self . endpoint . close ( 0u8 . into ( ) , b"" ) ;
7878 self . endpoint . wait_idle ( ) . await ;
7979 self . socket . unbind ( ) . await ;
@@ -245,31 +245,35 @@ impl Stream {
245245 }
246246
247247 #[ napi]
248- pub async unsafe fn read ( & mut self , mut buf : Uint8Array ) -> Result < Option < u32 > > {
249- let chunk = self . recv . lock ( ) . await . read ( buf. as_mut ( ) ) . await . map_err ( to_err) ?;
248+ pub async fn read ( & self , max_len : u32 ) -> Result < Option < Uint8Array > > {
249+ let mut buf = vec ! [ 0u8 ; max_len as usize ] ;
250+ let chunk = self . recv . lock ( ) . await . read ( & mut buf) . await . map_err ( to_err) ?;
250251 match chunk {
251- Some ( len) => Ok ( Some ( len as u32 ) ) ,
252+ Some ( len) => {
253+ buf. truncate ( len) ;
254+ Ok ( Some ( buf. into ( ) ) )
255+ } ,
252256 None => Ok ( None ) ,
253257 }
254258 }
255259
256260 #[ napi]
257- pub async unsafe fn write ( & mut self , data : Uint8Array ) -> Result < ( ) > {
261+ pub async fn write ( & self , data : Uint8Array ) -> Result < ( ) > {
258262 self . send . lock ( ) . await . write_all ( & data) . await . map_err ( to_err)
259263 }
260264
261265 #[ napi]
262- pub async unsafe fn finish_write ( & mut self ) {
266+ pub async fn finish_write ( & self ) {
263267 let _ = self . send . lock ( ) . await . finish ( ) ;
264268 }
265269
266270 #[ napi]
267- pub async unsafe fn reset_write ( & mut self ) {
271+ pub async fn reset_write ( & self ) {
268272 let _ = self . send . lock ( ) . await . reset ( 0u8 . into ( ) ) ;
269273 }
270274
271275 #[ napi]
272- pub async unsafe fn stop_read ( & mut self ) {
276+ pub async fn stop_read ( & self ) {
273277 let _ = self . recv . lock ( ) . await . stop ( 0u8 . into ( ) ) ;
274278 }
275279}
0 commit comments