From: ljsebald <ljs...@us...> - 2023-11-18 15:12:44
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 932513b05e6f234ddde655a628addb01e9e75753 (commit) via 068101701152c072348b93af13f8803fae065a3d (commit) from e8653ec03223ab890cb6682ed819e3c1da5c35f4 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 932513b05e6f234ddde655a628addb01e9e75753 Merge: e8653ec 0681017 Author: Lawrence Sebald <ljs...@us...> Date: Sat Nov 18 10:12:06 2023 -0500 Merge pull request #371 from KallistiOS/setsockopt Implement SO_RCVBUF and SO_SNDBUF for setsockopt() commit 068101701152c072348b93af13f8803fae065a3d Author: darc <da...@pr...> Date: Sat Nov 18 00:59:03 2023 -0600 Implement SO_RCVBUF and SO_SNDBUF for setsockopt() ----------------------------------------------------------------------- Summary of changes: kernel/net/net_tcp.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/kernel/net/net_tcp.c b/kernel/net/net_tcp.c index 5a82daa..4250b2d 100644 --- a/kernel/net/net_tcp.c +++ b/kernel/net/net_tcp.c @@ -1767,6 +1767,7 @@ static int net_tcp_setsockopt(net_socket_t *hnd, int level, int option_name, const void *option_value, socklen_t option_len) { struct tcp_sock *sock; int tmp; + uint8_t *new_ptr; if(!option_value || !option_len) { errno = EFAULT; @@ -1808,6 +1809,45 @@ static int net_tcp_setsockopt(net_socket_t *hnd, int level, int option_name, case SO_ERROR: case SO_TYPE: goto ret_inval; + + case SO_RCVBUF: + if(option_len != sizeof(uint32_t)) + goto ret_inval; + + tmp = *(uint32_t *)option_value; + /* Receive buffer size must be in the range 256 - 65535 */ + if(tmp < 256) + tmp = 256; + else if(tmp > 65535) + tmp = 65535; + + new_ptr = realloc(sock->data.rcvbuf, tmp); + if(!new_ptr) + goto ret_nomem; + + sock->data.rcvbuf = new_ptr; + sock->rcvbuf_sz = tmp; + goto ret_success; + + case SO_SNDBUF: + if(option_len != sizeof(uint32_t)) + goto ret_inval; + + tmp = *(uint32_t *)option_value; + /* Send buffer size must be in the range 2048 - 65535 */ + if(tmp < 2048) + tmp = 2048; + else if(tmp > 65535) + tmp = 65535; + + new_ptr = realloc(sock->data.sndbuf, tmp); + if(!new_ptr) { + goto ret_nomem; + } + + sock->data.sndbuf = new_ptr; + sock->sndbuf_sz = tmp; + goto ret_success; } break; @@ -1889,6 +1929,12 @@ ret_inval: errno = EINVAL; return -1; +ret_nomem: + mutex_unlock(&sock->mutex); + rwsem_read_unlock(&tcp_sem); + errno = ENOMEM; + return -1; + ret_success: mutex_unlock(&sock->mutex); rwsem_read_unlock(&tcp_sem); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |