checkpoint, need to fix something else

This commit is contained in:
bunnie 2022-01-29 16:09:59 +08:00
parent 8592224af2
commit 2b7e428340
4 changed files with 44 additions and 34 deletions

View file

@ -38,6 +38,7 @@ pub(crate) enum Opcode {
/// Calls for TCP implementation
TcpConnect,
TcpTx,
TcpClose,
// The DNS server can hook the Net crate for notifications on config updates
/// Adds an Ipv4 as a DNS server

View file

@ -5,7 +5,7 @@ use com::api::NET_MTU;
pub(crate) const TCP_BUFFER_SIZE: usize = NET_MTU;
#[derive(Debug, Archive, Serialize, Deserialize, Copy, Clone)]
pub(crate) struct NetTcpConnect {
pub(crate) struct NetTcpManage {
pub(crate) cb_sid: [u32; 4],
pub(crate) ip_addr: NetIpAddr,
pub(crate) remote_port: u16,
@ -40,7 +40,9 @@ pub(crate) struct NetTcpResponse {
pub(crate) struct NetTcpTransmit {
pub remote_addr: NetIpAddr,
pub remote_port: u16,
pub local_port: u16, // this was given back in the connect, we need this to distinguish between multiple connections to the same server
// this was given back in the connect, we need this to distinguish between multiple connections to the same server
pub local_port: u16,
// this is changed to the number of bytes actually sent on return
pub len: u16,
pub data: [u8; TCP_BUFFER_SIZE],
pub result: Option<NetMemResponse>,

View file

@ -402,7 +402,7 @@ fn xmain() -> ! {
}),
Some(Opcode::TcpConnect) => {
let mut buf = unsafe{Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())};
let mut tcpspec = buf.to_original::<NetTcpConnect, _>().unwrap(); // need to define this
let mut tcpspec = buf.to_original::<NetTcpManage, _>().unwrap(); // need to define this
let address = IpAddress::from(tcpspec.ip_addr);
let remote_port = tcpspec.remote_port;
@ -455,9 +455,12 @@ fn xmain() -> ! {
};
if let Some(tcp_state) = tcp_handles.get(&connection) {
let mut socket = sockets.get::<TcpSocket>(tcp_state.handle);
if socket.may_send() {
if socket.can_send() {
tcp_tx.result = match socket.send_slice(&tcp_tx.data) {
Ok(_) => Some(NetMemResponse::Ok),
Ok(octets) => {
tcp_tx.len = octets as u16;
Some(NetMemResponse::Ok)
},
Err(_) => Some(NetMemResponse::LibraryError),
}
} else {
@ -469,6 +472,28 @@ fn xmain() -> ! {
}
buf.replace(tcp_tx).unwrap();
},
Some(Opcode::TcpClose) => {
let mut buf = unsafe{Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())};
let mut tcpspec = buf.to_original::<NetTcpManage, _>().unwrap(); // need to define this
let address = IpAddress::from(tcpspec.ip_addr);
let remote_port = tcpspec.remote_port;
if let Some(local_port) = tcpspec.local_port {
let connection = TcpConnection {
remote: IpAddress::from(tcpspec.ip_addr),
remote_port: tcpspec.remote_port,
local_port,
};
if let Some(tcp_state) = tcp_handles.remove(&connection) {
sockets.get::<TcpSocket>(tcp_state.handle).close();
tcpspec.result = Some(NetMemResponse::Ok);
} else {
tcpspec.result = Some(NetMemResponse::Invalid);
}
} else {
tcpspec.result = Some(NetMemResponse::Invalid);
}
buf.replace(tcpspec).unwrap();
}
Some(Opcode::UdpBind) => {
let mut buf = unsafe{Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())};
let udpspec = buf.to_original::<NetUdpBind, _>().unwrap();

View file

@ -89,30 +89,6 @@ impl TcpStream {
unimplemented!()
}
pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
unimplemented!()
}
pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
unimplemented!()
}
pub fn is_read_vectored(&self) -> bool {
unimplemented!()
}
pub fn write(&self, _: &[u8]) -> io::Result<usize> {
unimplemented!()
}
pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
unimplemented!()
}
pub fn is_write_vectored(&self) -> bool {
unimplemented!()
}
pub fn peer_addr(&self) -> io::Result<SocketAddr> {
unimplemented!()
}
@ -167,13 +143,19 @@ impl fmt::Debug for TcpStream {
unimplemented!()
}
}
/*
impl Drop for TcpStream {
// do the close message here
}
impl Read for TcpStream {
fn read(&self, _: &mut [u8]) -> io::Result<usize> {
unimplemented!()
}
}
impl Write for TcpStream {
fn write(&self, _: &[u8]) -> io::Result<usize> {
unimplemented!()
}
}
*/