]> git.feebdaed.xyz Git - socialize.git/commitdiff
add: bucket size
authorseantywork <seantywork@gmail.com>
Wed, 12 Mar 2025 23:10:11 +0000 (08:10 +0900)
committerseantywork <seantywork@gmail.com>
Wed, 12 Mar 2025 23:10:11 +0000 (08:10 +0900)
include/socialize/core.h
include/socialize/ctl.h
src/ctl.c
src/sock/sock.c

index 00c99b78f5b804d6874a3fddcbb9a735a60f4f12..b275947f222973a563566905313669b4fd7317fc 100644 (file)
@@ -223,6 +223,7 @@ struct SOCK_CONTEXT_LOCK {
 
 struct SOCK_CTL {
     struct spinlock slock;
+    int size;
     struct SOCK_CONTEXT** SOCK_CTX;
     struct SOCK_CONTEXT_LOCK** SOCK_CTX_LOCK;
 };
index 0391971a0462f953e8762149cc3328ebd07cf804..219cc826b58cfbd8b7965e8f98c4015625272a5c 100644 (file)
@@ -18,7 +18,7 @@ int extract_common_name(uint8_t* common_name, const char* cert);
 int idpw_verify(char* idpw, char* newid, uint8_t* newtoken);
 
 
-int make_hash(int fd);
+int make_hash(int fd, int buck_size);
 
 int set_sockctx_by_fd(int fd);
 
index 2f9cca8388bb43dc85d35f615e7803d437b24af1..e61088af8d41c0bb335b799f6812b1aea1e0625c 100644 (file)
--- a/src/ctl.c
+++ b/src/ctl.c
@@ -218,9 +218,9 @@ int idpw_verify(char* idpw, char *newid, uint8_t* newtoken){
 
 
 
-int make_hash(int fd){
+int make_hash(int fd, int buck_size){
 
-    int hash = fd % MAX_CONN;
+    int hash = fd % buck_size;
 
     return hash;
 }
@@ -246,8 +246,6 @@ int set_sockctx_by_fd(int fd){
 
 struct SOCK_CONTEXT* get_sockctx_by_fd(int fd){
 
-    int i = make_hash(fd);
-
     //struct SOCK_CONTEXT* ctx = (struct SOCK_CONTEXT*)malloc(sizeof(struct SOCK_CONTEXT));
 
     //memset(ctx, 0, sizeof(struct SOCK_CONTEXT));
@@ -258,6 +256,8 @@ struct SOCK_CONTEXT* get_sockctx_by_fd(int fd){
 
     spinlock_lock(&SOCK_CTL.slock);
 
+    int i = make_hash(fd, SOCK_CTL.size);
+
     ctx = SOCK_CTL.SOCK_CTX[i];
 
     ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i];
@@ -499,7 +499,6 @@ int free_chanctx(int idx){
 
 int calloc_sockctx(int fd){
 
-    int i = make_hash(fd);
 
     struct SOCK_CONTEXT* ctx = NULL;
 
@@ -507,6 +506,8 @@ int calloc_sockctx(int fd){
 
     spinlock_lock(&SOCK_CTL.slock);
 
+    int i = make_hash(fd, SOCK_CTL.size);
+
     ctx = SOCK_CTL.SOCK_CTX[i];
 
     ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i];
@@ -545,14 +546,14 @@ int calloc_sockctx(int fd){
 int free_sockctx(int fd, int memfree){
 
 
-    int i = make_hash(fd);
-
     struct SOCK_CONTEXT* ctx = NULL;
 
     struct SOCK_CONTEXT_LOCK* ctxlock = NULL;
 
     spinlock_lock(&SOCK_CTL.slock);
 
+    int i = make_hash(fd, SOCK_CTL.size);
+
     ctx = SOCK_CTL.SOCK_CTX[i];
 
     ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i];
index 5e7ddfd293451ccb36751a98615c84009d2dd4db..07ddd22ebbd27b46b62c68bbed54c168034e39f3 100644 (file)
@@ -34,6 +34,8 @@ int init_all(){
 
     spinlock_init(&SOCK_CTL.slock);
 
+    SOCK_CTL.size = MAX_CONN;
+
     SOCK_CTL.SOCK_CTX = (struct SOCK_CONTEXT**)malloc(MAX_CONN * sizeof(struct SOCK_CONTEXT*));
 
     SOCK_CTL.SOCK_CTX_LOCK = (struct SOCK_CONTEXT_LOCK**)malloc(MAX_CONN * sizeof(struct SOCK_CONTEXT_LOCK*));