Skip to content

Commit bc4199d

Browse files
committed
implement sendto for unix sockets
1 parent 4388408 commit bc4199d

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/net/sops.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ where
9595
buf: UA,
9696
count: usize,
9797
) -> libkernel::error::Result<usize> {
98-
self.recv(ctx, buf, count, RecvFlags::empty()).await
98+
self.recv(ctx, buf, count, RecvFlags::empty())
99+
.await
99100
.map(|(len, _)| len)
100101
}
101102

src/net/unix.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,20 +349,43 @@ impl SocketOps for UnixSocket {
349349
let Some(peer) = self.peer_inbox.lock_save_irq().clone() else {
350350
return Err(KernelError::InvalidValue);
351351
};
352-
let local_addr = { self.local_addr.lock_save_irq().unwrap() };
352+
let local_addr = {
353+
self.local_addr.lock_save_irq().unwrap_or(SockAddrUn {
354+
family: crate::net::AF_UNIX as u16,
355+
path: [0; 108],
356+
})
357+
};
353358
peer.send(local_addr, buf, count).await
354359
}
355360

356361
async fn sendto(
357362
&mut self,
358363
_ctx: &mut FileCtx,
359-
_buf: UA,
360-
_count: usize,
364+
buf: UA,
365+
count: usize,
361366
_flags: SendFlags,
362-
_addr: SockAddr,
367+
addr: SockAddr,
363368
) -> Result<usize> {
364-
todo!();
365-
// self.send(ctx, buf, count, flags).await
369+
let peer_inbox = match addr {
370+
SockAddr::Un(saun) => {
371+
let Some(path) = UnixSocket::path_bytes(&saun) else {
372+
return Err(KernelError::InvalidValue);
373+
};
374+
let reg = endpoints().lock_save_irq();
375+
let Some(ep) = reg.get(&path) else {
376+
return Err(KernelError::Fs(FsError::NotFound));
377+
};
378+
ep.inbox.clone()
379+
}
380+
_ => return Err(KernelError::InvalidValue),
381+
};
382+
let local_addr = {
383+
self.local_addr.lock_save_irq().unwrap_or(SockAddrUn {
384+
family: crate::net::AF_UNIX as u16,
385+
path: [0; 108],
386+
})
387+
};
388+
peer_inbox.send(local_addr, buf, count).await
366389
}
367390

368391
async fn shutdown(&self, how: crate::net::ShutdownHow) -> Result<()> {

0 commit comments

Comments
 (0)