second-state / wasmedge_wasi_socket

A Rust lib for socket on WasmEdge.
https://second-state.github.io/wasmedge_wasi_socket/
Apache License 2.0
70 stars 29 forks source link

[Proposal] Implement missing functions. #51

Open MediosZ opened 2 years ago

MediosZ commented 2 years ago

There are many functions need to implemented for TcpListener and TcpStream. We need to implement as many as possible, so that wasmedge_wasi_socket can be a substitute of std version.

Here is the list of them:

TcpListener:

fn local_addr(&self) -> io::Result<SocketAddr>;
fn try_clone(&self) -> io::Result<TcpListener>;
fn set_ttl(&self, ttl: u32) -> io::Result<()>;
fn ttl(&self) -> io::Result<u32>;
fn take_error(&self) -> io::Result<Option<io::Error>>;
fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()>;

TcpStream:

fn connect_timeout(addr: &SocketAddr, timeout: Duration) -> io::Result<TcpStream>;
fn try_clone(&self) -> io::Result<TcpStream>;
fn set_ttl(&self, ttl: u32) -> io::Result<()>;
fn ttl(&self) -> io::Result<u32>;
fn take_error(&self) -> io::Result<Option<io::Error>>;
fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()>;
fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>;
fn read_timeout(&self) -> io::Result<Option<Duration>>;
fn write_timeout(&self) -> io::Result<Option<Duration>>;
fn peek(&self, buf: &mut [u8]) -> io::Result<usize>;
fn set_nodelay(&self, nodelay: bool) -> io::Result<()>;
fn nodelay(&self) -> io::Result<bool>;
fn set_linger(&self, linger: Option<Duration>) -> io::Result<()>;
fn linger(&self) -> io::Result<Option<Duration>>;
L-jasmine commented 2 years ago

TcpListener:

fn local_addr(&self) -> io::Result<SocketAddr>; // ok
fn try_clone(&self) -> io::Result<TcpListener>; // ok
fn set_ttl(&self, ttl: u32) -> io::Result<()>; // not supported now,but I think it is not a core feature. I will implement an empty api.
fn ttl(&self) -> io::Result<u32>; // 
fn take_error(&self) -> io::Result<Option<io::Error>>; // ok
fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()>; // ok

TcpStream:

fn connect_timeout(addr: &SocketAddr, timeout: Duration) -> io::Result<TcpStream>; // ok
fn try_clone(&self) -> io::Result<TcpStream>; // ok
fn set_ttl(&self, ttl: u32) -> io::Result<()>; //  implement an empty api.
fn ttl(&self) -> io::Result<u32>; //
fn take_error(&self) -> io::Result<Option<io::Error>>; // ok
fn set_read_timeout(&self, dur: Option<Duration>) -> io::Result<()>; // ok
fn set_write_timeout(&self, dur: Option<Duration>) -> io::Result<()>; // ok
fn read_timeout(&self) -> io::Result<Option<Duration>>; // ok
fn write_timeout(&self) -> io::Result<Option<Duration>>; // ok
fn peek(&self, buf: &mut [u8]) -> io::Result<usize>; // ok
fn set_nodelay(&self, nodelay: bool) -> io::Result<()>; //  implement an empty api.
fn nodelay(&self) -> io::Result<bool>; // 
fn set_linger(&self, linger: Option<Duration>) -> io::Result<()>; // ok
fn linger(&self) -> io::Result<Option<Duration>>; // ok
MediosZ commented 2 years ago

I am willing to help.