Skip to content

Commit

Permalink
servers: server idle handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 9, 2024
1 parent 6b6fc4c commit ebf4e00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void *kernelThread(void *args) {
KDEBUG("early boot complete, memory usage: %d MiB / %d MiB\n", ps.usedPages>>8, ps.usablePages>>8);

for(;;) {
serverIdle();
if(!syscallProcess()) platformHalt();
}
}
Expand Down
26 changes: 25 additions & 1 deletion src/servers/handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void serverInit() {
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, SERVER_KERNEL_PATH); // this is a special path and not a true file

kernelSocket = socket(NULL, AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0);
kernelSocket = socket(NULL, AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0); // NEVER block the kernel
if(kernelSocket < 0) {
KERROR("failed to open kernel socket: error code %d\n", -1*kernelSocket);
while(1) platformHalt();
Expand Down Expand Up @@ -60,4 +60,28 @@ void serverInit() {
}

KDEBUG("kernel is listening on socket %d: %s\n", kernelSocket, addr.sun_path);
}

/* serverIdle(): handles incoming kernel connections when idle
* params: none
* returns: nothing
*/

void serverIdle() {
// check for incoming connections
int sd = accept(NULL, kernelSocket, &connaddr[connectionCount], &connlen[connectionCount]);
if(sd > 0) {
KDEBUG("kernel accepted connection from %s\n", sd, connaddr[connectionCount].sa_data);
connections[connectionCount] = sd;
connectionCount++;
}

// check if any of the incoming connections sent anything
if(!connectionCount) return;
for(int i = 0; i < connectionCount; i++) {
sd = connections[i];
if(recv(NULL, sd, buffer, SERVER_MAX_SIZE, 0) > 0) {
// TODO: handle
}
}
}

0 comments on commit ebf4e00

Please sign in to comment.