Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Add basic TCP socket APIs.
Browse files Browse the repository at this point in the history
This is based on @npmccullum's [wasi-snapshot-preview2 draft] which is
in turn based on the [wasi-sockets proposal], though for simplify for
now it omits UDP sockets and some other features.

It's also based on the [pseudo-streams PR]; so that should proceed
first before this.

[draft wasi-snapshot-preview2]: https://github.com/npmccallum/wasi-snapshot-preview2
[wasi-sockets proposal]: https://github.com/WebAssembly/wasi-sockets
[pseudo-streams PR]: #29
  • Loading branch information
sunfishcode committed Dec 21, 2022
1 parent 345ee9c commit e059e75
Show file tree
Hide file tree
Showing 2 changed files with 593 additions and 31 deletions.
127 changes: 123 additions & 4 deletions host/src/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,136 @@
#![allow(unused_variables)]

use crate::{
wasi_tcp::{self, BytesResult, Socket, WasiTcp},
HostResult, WasiCtx,
wasi_tcp::{
self, ConnectionFlags, Errno, IpSocketAddress, ListenerFlags, Network, Size, TcpConnection,
TcpListener, WasiTcp,
},
HostResult, WasiCtx, WasiStream,
};

#[async_trait::async_trait]
impl WasiTcp for WasiCtx {
async fn bytes_readable(&mut self, socket: Socket) -> HostResult<BytesResult, wasi_tcp::Error> {
async fn listen(
&mut self,
network: Network,
address: IpSocketAddress,
backlog: Option<Size>,
flags: ListenerFlags,
) -> HostResult<TcpListener, Errno> {
todo!()
}

async fn accept(
&mut self,
listener: TcpListener,
flags: ConnectionFlags,
) -> HostResult<(TcpConnection, IpSocketAddress), Errno> {
todo!()
}

async fn connect(
&mut self,
network: Network,
local_address: IpSocketAddress,
remote_address: IpSocketAddress,
flags: ConnectionFlags,
) -> HostResult<TcpConnection, Errno> {
todo!()
}

async fn send(&mut self, connection: TcpConnection, bytes: Vec<u8>) -> HostResult<Size, Errno> {
todo!()
}

async fn receive(
&mut self,
connection: TcpConnection,
length: Size,
) -> HostResult<(Vec<u8>, bool), Errno> {
todo!()
}

async fn get_listener_local_address(
&mut self,
listener: TcpListener,
) -> HostResult<IpSocketAddress, Errno> {
todo!()
}

async fn get_tcp_connection_local_address(
&mut self,
connection: TcpConnection,
) -> HostResult<IpSocketAddress, Errno> {
todo!()
}

async fn get_remote_address(
&mut self,
connection: TcpConnection,
) -> HostResult<IpSocketAddress, Errno> {
todo!()
}

async fn get_flags(&mut self, connection: TcpConnection) -> HostResult<ConnectionFlags, Errno> {
todo!()
}

async fn set_flags(
&mut self,
connection: TcpConnection,
flags: ConnectionFlags,
) -> HostResult<(), Errno> {
todo!()
}

async fn get_receive_buffer_size(
&mut self,
connection: TcpConnection,
) -> HostResult<Size, Errno> {
todo!()
}

async fn set_receive_buffer_size(
&mut self,
connection: TcpConnection,
value: Size,
) -> HostResult<(), Errno> {
todo!()
}

async fn get_send_buffer_size(&mut self, connection: TcpConnection) -> HostResult<Size, Errno> {
todo!()
}

async fn set_send_buffer_size(
&mut self,
connection: TcpConnection,
value: Size,
) -> HostResult<(), Errno> {
todo!()
}

async fn bytes_readable(&mut self, socket: TcpConnection) -> HostResult<Size, Errno> {
drop(socket);
todo!()
}

async fn bytes_writable(&mut self, socket: Socket) -> HostResult<BytesResult, wasi_tcp::Error> {
async fn bytes_writable(&mut self, socket: TcpConnection) -> HostResult<Size, Errno> {
drop(socket);
todo!()
}

async fn read_via_stream(
&mut self,
fd: wasi_tcp::TcpConnection,
) -> HostResult<WasiStream, wasi_tcp::Errno> {
todo!()
}

async fn write_via_stream(
&mut self,
fd: wasi_tcp::TcpConnection,
) -> HostResult<WasiStream, wasi_tcp::Errno> {
todo!()
}
}
Loading

0 comments on commit e059e75

Please sign in to comment.