add docs and some hashmap code

This commit is contained in:
2024-11-10 17:06:52 +01:00
parent 5e5d25cd75
commit f1612dad0f
7 changed files with 114 additions and 10 deletions

View File

@@ -1,19 +1,32 @@
#ifndef __HASHMAP_C__
#define __HASHMAP_C__
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#define HASHMAP_MAX_CLIENTS 10000
/* Each process on Linux can have a maximum of 1024 open file descriptors */
#define HASHMAP_MAX_CLIENTS 1024
struct hashmap {
int sockfd;
struct sockaddr_storage sas;
struct hashmap *next;
};
/* Calculate the hash code of a file descriptor */
int hash(int sockfd);
/* Initialize the hash map */
void hm_init(struct hashmap *map);
/* Insert a new key in the hash map */
void hm_insert(struct hashmap *map, int sockfd, struct sockaddr_storage *sas);
/* Search for a key in the hash map */
struct hashmap *hm_lookup(struct hashmap *map, int sockfd);
/* Clean up the hash map */
void hm_free(struct hashmap *map);
#endif