From d2602e0a182263a99edf487c63df6fb89853b051 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 31 Jan 2020 20:32:06 +0900 Subject: [PATCH] Clean up message handling in the stdio daemon by moving it into a separate function --- kernel/core/stdio.c | 72 +++++++++++++++++++++++++++++---------------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/kernel/core/stdio.c b/kernel/core/stdio.c index 72c3c33..3cc888c 100644 --- a/kernel/core/stdio.c +++ b/kernel/core/stdio.c @@ -30,8 +30,20 @@ static int stdio_flush(int fd) return(0); } +struct fd { + int f_id; +}; + +struct proc { + pid_t p_pid; + int p_nfds; + + struct fd *p_fds; +}; + void _stdio(void) { + struct state state; struct cxmsg msg; int err; @@ -58,34 +70,10 @@ void _stdio(void) } /* msg.cm_len now contains the number of bytes in sio_data */ - if(err > 0) { - switch(msg.cm_type) { - case CX_MSG_READ: - err = stdio_read(msg.cm_stdio.sio_fd, - msg.cm_stdio.sio_data, - msg.cm_len); - break; - - case CX_MSG_WRITE: - err = stdio_write(msg.cm_stdio.sio_fd, - msg.cm_stdio.sio_data, - msg.cm_len); - break; - - case CX_MSG_FLUSH: - err = stdio_flush(msg.cm_stdio.sio_fd); - break; - - default: - /* malformed input? */ - err = -EINVAL; - break; - } - msg.cm_dst = msg.cm_src; msg.cm_type = CX_MSG_RETVAL; - msg.cm_retval = err; + msg.cm_retval = _handle_msg(&msg); msg.cm_len = sizeof(msg.cm_hdr) + sizeof(int); cxsend(msg.cm_dst, &msg); @@ -94,3 +82,37 @@ void _stdio(void) return; } + +static int _handle_msg(struct cxmsg *msg) +{ + switch(msg->cm_type) { + case CX_OPEN: + case CX_CLOSE: + case CX_READ: + case CX_WRITE: + case CX_FCNTL: + err = -ENOSYS; + break; + + case CX_MSG_READ: + err = stdio_read(msg->cm_stdio.sio_fd, + msg->cm_stdio.sio_data, + msg->cm_len); + break; + + case CX_MSG_WRITE: + err = stdio_write(msg->cm_stdio.sio_fd, + msg->cm_stdio.sio_data, + msg->cm_len); + break; + + case CX_MSG_FLUSH: + err = stdio_flush(msg->cm_stdio.sio_fd); + break; + + default: + /* malformed input? */ + err = -EINVAL; + break; + } +} -- 2.47.3