summaryrefslogtreecommitdiff
path: root/scalls/recvfrom.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-30 22:12:14 +0100
committerAnton Kling <anton@kling.gg>2023-10-31 00:18:38 +0100
commit8a9208612eec8ddae4c418485d848ecfa0613699 (patch)
tree2f4b29200c2f0c19ae52f45bdb9b38a41b356e30 /scalls/recvfrom.c
parentca76600acc8bf7a02346efa5bd8f17072210ec01 (diff)
Meta: Move kernel and userland to their own folders.
This is to allow both the kernel and the userland to share certain header files and to make the folder structure a bit more clear.
Diffstat (limited to 'scalls/recvfrom.c')
-rw-r--r--scalls/recvfrom.c59
1 files changed, 0 insertions, 59 deletions
diff --git a/scalls/recvfrom.c b/scalls/recvfrom.c
deleted file mode 100644
index 1770fa1..0000000
--- a/scalls/recvfrom.c
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <assert.h>
-#include <fs/vfs.h>
-#include <math.h>
-#include <poll.h>
-#include <scalls/recvfrom.h>
-
-size_t syscall_recvfrom(
- int socket, void *buffer, size_t length, int flags,
- struct two_args
- *extra_args /*struct sockaddr *address, socklen_t *address_len*/) {
-
- struct sockaddr *address = (struct sockaddr *)extra_args->a;
- socklen_t *address_len = (socklen_t *)extra_args->b;
- kprintf("address: %x\n", address);
- kprintf("address_len: %x\n", address_len);
-
- if (flags & MSG_WAITALL) {
- struct pollfd fds[1];
- fds[0].fd = socket;
- fds[0].events = POLLIN;
- poll(fds, 1, 0);
- }
-
- uint16_t data_length;
- socklen_t tmp_socklen;
- vfs_pread(socket, &tmp_socklen, sizeof(socklen_t), 0);
- if (address_len)
- *address_len = tmp_socklen;
- if (address) {
- vfs_pread(socket, address, tmp_socklen, 0);
- } else {
- // We still have to throwaway the data.
- char devnull[100];
- for (; tmp_socklen;) {
- int rc = vfs_pread(socket, devnull, min(tmp_socklen, 100), 0);
- assert(rc >= 0);
- tmp_socklen -= rc;
- }
- }
-
- vfs_pread(socket, &data_length, sizeof(data_length), 0);
- // If it is reading less than the packet length that could cause
- // problems as the next read will not be put at a new header. Luckily
- // it seems as if other UNIX systems can discard the rest of the
- // packet if not read.
-
- // Read in the data requested
- int read_len = min(length, data_length);
- int rc = vfs_pread(socket, buffer, read_len, 0);
- // Discard the rest of the packet
- int rest = data_length - read_len;
- char devnull[100];
- for (; rest;) {
- int rc = vfs_pread(socket, devnull, 100, 0);
- assert(rc >= 0);
- rest -= rc;
- }
- return rc;
-}