-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;
}
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));
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];
int calloc_sockctx(int fd){
- int i = make_hash(fd);
struct SOCK_CONTEXT* ctx = 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];
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];
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*));