diff options
author | Anton Kling <anton@kling.gg> | 2024-03-28 10:34:00 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-03-28 10:34:00 +0100 |
commit | 7eceb43433634ee253507208baf1d8298b40e377 (patch) | |
tree | 59c399d8bd9a24d9a74c52f3830125b1dd217e95 | |
parent | 873c45b99fe05e43c71763c385da54b0945bf8a3 (diff) |
new stuff
-rw-r--r-- | kernel/fs/fifo.c | 6 | ||||
-rw-r--r-- | kernel/fs/vfs.c | 18 | ||||
-rw-r--r-- | kernel/network/tcp.c | 1 | ||||
-rw-r--r-- | kernel/socket.c | 17 | ||||
-rw-r--r-- | userland/irc/irc.c | 46 | ||||
-rw-r--r-- | userland/minibox/utilities/kill.c | 9 |
6 files changed, 63 insertions, 34 deletions
diff --git a/kernel/fs/fifo.c b/kernel/fs/fifo.c index 7c286db..f2ad933 100644 --- a/kernel/fs/fifo.c +++ b/kernel/fs/fifo.c @@ -9,11 +9,17 @@ void fifo_close(vfs_fd_t *fd) { return; } +void fifo_realloc(FIFO_FILE *file) { + file->buffer_len += 4096; + file->buffer = krealloc(file->buffer, file->buffer_len); +} + int fifo_object_write(u8 *buffer, u64 offset, u64 len, FIFO_FILE *file) { (void)offset; file->has_data = 1; if (file->write_len + len >= file->buffer_len) { file->can_write = 0; + fifo_realloc(file); return -EAGAIN; } memcpy(file->buffer + file->write_len, buffer, len); diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c index f2b763c..505d6ae 100644 --- a/kernel/fs/vfs.c +++ b/kernel/fs/vfs.c @@ -375,7 +375,23 @@ int vfs_pwrite(int fd, void *buf, u64 count, u64 offset) { if (!(vfs_fd->flags & O_WRITE)) { return -EBADF; } - return raw_vfs_pwrite(vfs_fd, buf, count, offset); + int rc = raw_vfs_pwrite(vfs_fd, buf, count, offset); + if (-EAGAIN == rc) { + if (!(vfs_fd->flags & O_NONBLOCK)) { + struct pollfd fds; + do { + fds.fd = fd; + fds.events = POLLOUT; + fds.revents = 0; + int rc = poll(&fds, 1, 0); + if (-EINTR == rc) { + return -EINTR; + } + } while (!(fds.revents & POLLOUT)); + return vfs_pwrite(fd, buf, count, offset); + } + } + return rc; } vfs_vm_object_t *vfs_get_vm_object(int fd, u64 length, u64 offset) { diff --git a/kernel/network/tcp.c b/kernel/network/tcp.c index 1a3641b..997b699 100644 --- a/kernel/network/tcp.c +++ b/kernel/network/tcp.c @@ -218,6 +218,7 @@ void handle_tcp(ipv4_t src_ip, const u8 *payload, u32 payload_length) { (u8 *)(payload + header->data_offset * sizeof(u32)), 0, tcp_payload_length, incoming_connection->data_file); assert(len >= 0); + assert(len == tcp_payload_length); incoming_connection->ack += len; tcp_send_ack(incoming_connection); } diff --git a/kernel/socket.c b/kernel/socket.c index 36d0fcb..39775ce 100644 --- a/kernel/socket.c +++ b/kernel/socket.c @@ -9,12 +9,8 @@ #include <sched/scheduler.h> #include <socket.h> -// FIXME: Make these more dynamic OPEN_UNIX_SOCKET *un_sockets[100] = {0}; -// struct TcpConnection *tcp_sockets[100]; -// struct TcpListen *tcp_listen[100]; - void gen_ipv4(ipv4_t *ip, u8 i1, u8 i2, u8 i3, u8 i4) { ip->a[0] = i1; ip->a[1] = i2; @@ -195,14 +191,11 @@ int tcp_read(u32 socket, u8 *buffer, u64 buffer_size, u64 *out) { return 0; } - int rc = 0; - for (; rc <= 0;) { - rc = fifo_object_read(buffer, 0, buffer_size, con->data_file); - if (rc <= 0) { - enable_interrupts(); - rc = 0; - return 0; - } + int rc = fifo_object_read(buffer, 0, buffer_size, con->data_file); + if (rc <= 0) { + enable_interrupts(); + rc = 0; + return 0; } if (out) { *out = rc; diff --git a/userland/irc/irc.c b/userland/irc/irc.c index 6bdbce5..9aa962f 100644 --- a/userland/irc/irc.c +++ b/userland/irc/irc.c @@ -129,27 +129,20 @@ void msg_sv_println(struct sv s) { } void msg_sv_print(struct sv s) { - char buffer[4096]; - int buffer_pos = 0; - mvcursor(message_pos_x, message_pos_y); - for (size_t i = 0; i < s.length; i++) { - buffer[buffer_pos] = s.s[i]; - buffer_pos++; - message_pos_x++; - if ('\n' == s.s[i] || message_pos_x > TERMINAL_WIDTH) { - buffer[buffer_pos] = '\0'; - printf("%s", buffer); - buffer_pos = 0; - message_pos_x = 0; - message_pos_y++; - mvcursor(message_pos_x, message_pos_y); + for (;;) { + mvcursor(message_pos_x, message_pos_y); + struct sv line = sv_split_delim(s, &s, '\n'); + write(1, line.s, line.length); + message_pos_x += line.length; + if (sv_isempty(s) && '\n' != line.s[line.length]) { + break; + } + message_pos_x = 0; + message_pos_y++; + if ('\n' == line.s[line.length]) { + break; } } - if (0 != buffer_pos) { - buffer[buffer_pos] = '\0'; - printf("%s", buffer); - } - mvcursor(prompt_x, prompt_y); } #define RPL_WELCOME C_TO_SV("001") @@ -339,6 +332,16 @@ void irc_show_channel(struct irc_channel *channel) { clear_area(0, 0, TERMINAL_WIDTH, prompt_y - 1); message_pos_x = 0; message_pos_y = 0; + + char buffer[4096]; + sprintf(buffer, "Number of messages in channe: %d", + (int)channel->messages_num); + struct sb b; + sb_init(&b); + sb_append(&b, buffer); + msg_sv_println(SB_TO_SV(b)); + sb_free(&b); + for (size_t i = 0; i < channel->messages_num; i++) { struct message *m = &channel->messages[i]; struct sv nick = { @@ -351,9 +354,9 @@ void irc_show_channel(struct irc_channel *channel) { }; msg_sv_print(nick); msg_sv_print(C_TO_SV(": ")); - msg_sv_print(msg); - msg_sv_print(C_TO_SV("\n")); + msg_sv_println(msg); } + mvcursor(prompt_x, prompt_y); } void irc_add_message_to_channel(struct irc_channel *chan, struct sv sender, @@ -523,6 +526,7 @@ int main(void) { .s = current_msg, .length = msg_usage, }); + refresh_screen(); msg_usage = 0; continue; } diff --git a/userland/minibox/utilities/kill.c b/userland/minibox/utilities/kill.c new file mode 100644 index 0000000..2888b3b --- /dev/null +++ b/userland/minibox/utilities/kill.c @@ -0,0 +1,9 @@ +// kill +#include "include.h" +#include <signal.h> +#include <stdio.h> + +int kill_main(int argc, char **argv) { + kill(4, SIGTERM); + return 0; +} |