@@ -3,9 +3,31 @@ use crate::fs::open_file::FileCtx;
33use crate :: socket:: { ShutdownHow , SockAddr } ;
44use alloc:: boxed:: Box ;
55use async_trait:: async_trait;
6+ use bitflags:: bitflags;
67use libkernel:: error:: KernelError ;
78use libkernel:: memory:: address:: UA ;
89
10+ bitflags ! {
11+ #[ derive( Copy , Clone ) ]
12+ pub struct SendFlags : u32 {
13+ const MSG_CONFIRM = 0x800 ;
14+ const MSG_DONT_ROUTE = 0x4 ;
15+ const MSG_DONT_WAIT = 0x40 ;
16+ const MSG_EOR = 0x80 ;
17+ const MSG_MORE = 0x8000 ;
18+ const MSG_NO_SIGNAL = 0x4000 ;
19+ const MSG_OOB = 0x1 ;
20+ }
21+ }
22+
23+ bitflags ! {
24+ #[ derive( Copy , Clone ) ]
25+ pub struct RecvFlags : u32 {
26+ // TODO: rest of flags
27+ const MSG_DONTWAIT = 0x40 ;
28+ }
29+ }
30+
931#[ async_trait]
1032pub trait SocketOps : Send + Sync {
1133 async fn bind ( & self , _addr : SockAddr ) -> libkernel:: error:: Result < ( ) > {
@@ -24,17 +46,35 @@ pub trait SocketOps: Send + Sync {
2446 Err ( KernelError :: NotSupported )
2547 }
2648
27- async fn read (
49+ async fn recv (
2850 & mut self ,
2951 ctx : & mut FileCtx ,
3052 buf : UA ,
3153 count : usize ,
54+ flags : RecvFlags ,
3255 ) -> libkernel:: error:: Result < usize > ;
33- async fn write (
56+ async fn recvfrom (
57+ & mut self ,
58+ ctx : & mut FileCtx ,
59+ buf : UA ,
60+ count : usize ,
61+ flags : RecvFlags ,
62+ addr : Option < SockAddr > ,
63+ ) -> libkernel:: error:: Result < ( usize , Option < SockAddr > ) > ;
64+ async fn send (
65+ & mut self ,
66+ ctx : & mut FileCtx ,
67+ buf : UA ,
68+ count : usize ,
69+ flags : SendFlags ,
70+ ) -> libkernel:: error:: Result < usize > ;
71+ async fn sendto (
3472 & mut self ,
3573 ctx : & mut FileCtx ,
3674 buf : UA ,
3775 count : usize ,
76+ flags : SendFlags ,
77+ addr : SockAddr ,
3878 ) -> libkernel:: error:: Result < usize > ;
3979
4080 async fn shutdown ( & self , _how : ShutdownHow ) -> libkernel:: error:: Result < ( ) > {
5595 buf : UA ,
5696 count : usize ,
5797 ) -> libkernel:: error:: Result < usize > {
58- self . read ( ctx, buf, count) . await
98+ self . recv ( ctx, buf, count, RecvFlags :: empty ( ) ) . await
5999 }
60100
61101 async fn readat (
73113 buf : UA ,
74114 count : usize ,
75115 ) -> libkernel:: error:: Result < usize > {
76- self . write ( ctx, buf, count) . await
116+ self . send ( ctx, buf, count, SendFlags :: empty ( ) ) . await
77117 }
78118
79119 async fn writeat (
0 commit comments