Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct clients {
- uint32_t client_id;
- ...
- ...
- ...
- struct clients *next;
- };
- struct listeners {
- struct tcp_callback tcp_listener;
- struct clients **clients;
- };
- struct listeners listeners[65536];
- void show_clients(uint16_t port) {
- struct clients *client1 = listeners[port].clients;
- while(client1 != NULL) {
- kprintf("0x%x -> ",client1->client_id);
- client1 = client1->next;
- }
- kprintf("\n");
- }
- struct clients *add_client(uint32_t client_id, uint16_t port) {
- struct clients *client;
- client = pmm_alloc();
- client->client_id = client_id;
- client->con_est = false;
- client->last_ack = 0;
- client->last_seq = 0;
- client->fin_ack = 0;
- client->fin_seq = 0;
- client->next = NULL;
- struct clients *client1 = listeners[port].clients;
- if(client1 == NULL) {
- listeners[port].clients = client;
- return client;
- }
- while(client1->next != NULL) {
- client1 = client1->next;
- }
- client1->next = client;
- show_clients(port);
- return client;
- }
- bool del_client(uint32_t client_id, uint16_t port) {
- struct clients *client = listeners[port].clients;
- if(client->client_id == client_id) {
- struct clients *client_temp = client;
- listeners[port].clients = client->next;
- kprintf("Deleted1: 0x%x\n",client_temp->client_id);
- pmm_free(client_temp);
- show_clients(port);
- return true;
- }
- while(client->next != NULL) {
- if(client->next->client_id == client_id) {
- struct clients *client_temp = client->next;
- client->next = client->next->next;
- kprintf("Deleted2: 0x%x\n",client_temp->client_id);
- pmm_free(client_temp);
- show_clients(port);
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment