Skip to content

Commit abc905f

Browse files
syscall::net: add listen syscall
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 9389db6 commit abc905f

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

patches/mlibc/mlibc.patch

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From f76727cfa3db5f15b030a3cdc4535ea1eea31ac4 Mon Sep 17 00:00:00 2001
1+
From 5d484b1a17191d7ce795a2d773e4a72d8fc7490e Mon Sep 17 00:00:00 2001
22
From: Andy-Python-Programmer <[email protected]>
33
Date: Thu, 10 Feb 2022 19:12:25 +1100
44
Subject: [PATCH] yes
@@ -10,9 +10,9 @@ Signed-off-by: Andy-Python-Programmer <[email protected]>
1010
sysdeps/aero/generic/aero.cpp | 12 ++++-
1111
sysdeps/aero/generic/filesystem.cpp | 79 ++++++++++++++++++++++++++---
1212
sysdeps/aero/generic/signals.cpp | 8 ++-
13-
sysdeps/aero/generic/sockets.cpp | 38 ++++++++++++++
13+
sysdeps/aero/generic/sockets.cpp | 48 ++++++++++++++++++
1414
sysdeps/aero/include/aero/syscall.h | 12 +++++
15-
7 files changed, 141 insertions(+), 13 deletions(-)
15+
7 files changed, 151 insertions(+), 13 deletions(-)
1616

1717
diff --git a/.gitignore b/.gitignore
1818
index dbb35e8b..20c8d4c3 100644
@@ -210,10 +210,10 @@ index 3527370c..a6f69fff 100644
210210
} // namespace mlibc
211211
\ No newline at end of file
212212
diff --git a/sysdeps/aero/generic/sockets.cpp b/sysdeps/aero/generic/sockets.cpp
213-
index e69de29b..c1375859 100644
213+
index e69de29b..4e6bd608 100644
214214
--- a/sysdeps/aero/generic/sockets.cpp
215215
+++ b/sysdeps/aero/generic/sockets.cpp
216-
@@ -0,0 +1,38 @@
216+
@@ -0,0 +1,48 @@
217217
+#include <mlibc/all-sysdeps.hpp>
218218
+#include <mlibc/thread-entry.hpp>
219219
+
@@ -251,6 +251,16 @@ index e69de29b..c1375859 100644
251251
+
252252
+ return 0;
253253
+}
254+
+
255+
+int sys_listen(int fd, int backlog) {
256+
+ auto result = syscall(SYS_LISTEN, fd, backlog);
257+
+
258+
+ if (result < 0) {
259+
+ return -result;
260+
+ }
261+
+
262+
+ return 0;
263+
+}
254264
+} // namespace mlibc
255265
diff --git a/sysdeps/aero/include/aero/syscall.h b/sysdeps/aero/include/aero/syscall.h
256266
index 07b1b51b..ef797e40 100644

src/aero_kernel/src/fs/inode.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ pub trait INodeInterface: Send + Sync + Downcastable {
145145
Err(FileSystemError::NotSupported)
146146
}
147147

148-
// Socket operations
148+
// Socket operations:
149149
fn bind(&self, _address: SocketAddr, _length: usize) -> Result<()> {
150150
Err(FileSystemError::NotSocket)
151151
}
152152

153153
fn connect(&self, _address: SocketAddr, _length: usize) -> Result<()> {
154154
Err(FileSystemError::NotSocket)
155155
}
156+
157+
fn listen(&self, _backlog: usize) -> Result<()> {
158+
Err(FileSystemError::NotSocket)
159+
}
156160
}
157161

158162
/// Structure representing the curcial, characteristics of an inode. The metadata

src/aero_kernel/src/socket/unix.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ impl INodeInterface for UnixSocket {
8989
}
9090

9191
fn connect(&self, _address: SocketAddr, _length: usize) -> Result<()> {
92-
todo!("{_address:?}")
92+
log::error!("UnixSocket::connect() is not implemented");
93+
Ok(())
94+
}
95+
96+
fn listen(&self, _backlog: usize) -> Result<()> {
97+
log::error!("UnixSocket::listen() not implemented");
98+
Ok(())
9399
}
94100
}

src/aero_kernel/src/syscall/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub fn generic_do_syscall(
211211
SYS_SOCKET => net::socket(b, c, d),
212212
SYS_BIND => net::bind(b, c, d),
213213
SYS_CONNECT => net::connect(b, c, d),
214+
SYS_LISTEN => net::listen(b, c),
214215

215216
SYS_GETTIME => time::gettime(b, c),
216217
SYS_SLEEP => time::sleep(b),

src/aero_kernel/src/syscall/net.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn socket_addr_from_addr<'sys>(address: VirtAddr) -> Result<SocketAddr<'sys>, Ae
1919
Ok(SocketAddr::from_family(address, family).ok_or(AeroSyscallError::EINVAL)?)
2020
}
2121

22-
/// Connects the socket referred to by the file descriptor, to the specified address.
22+
/// Connects the socket to the specified address.
2323
#[aero_proc::syscall]
2424
pub fn connect(fd: usize, address: usize, length: usize) -> Result<usize, AeroSyscallError> {
2525
let address = socket_addr_from_addr(VirtAddr::new(address as u64))?;
@@ -33,6 +33,20 @@ pub fn connect(fd: usize, address: usize, length: usize) -> Result<usize, AeroSy
3333
Ok(0)
3434
}
3535

36+
/// Marks the socket as a passive socket (i.e. as a socket that will be used to accept incoming
37+
/// connection requests).
38+
#[aero_proc::syscall]
39+
pub fn listen(fd: usize, backlog: usize) -> Result<usize, AeroSyscallError> {
40+
let file = scheduler::get_scheduler()
41+
.current_task()
42+
.file_table
43+
.get_handle(fd)
44+
.ok_or(AeroSyscallError::EINVAL)?;
45+
46+
file.inode().listen(backlog)?;
47+
Ok(0)
48+
}
49+
3650
#[aero_proc::syscall]
3751
pub fn socket(
3852
domain: usize,

0 commit comments

Comments
 (0)