<commit_before>#include "syshead.h"
#include "tcp_socket.h"

#define MAX_TCP_SOCKETS 128
static int cur_fd = 3;
static struct tcp_socket tcp_sockets[MAX_TCP_SOCKETS];

void init_tcp_sockets()
{
    memset(tcp_sockets, 0, sizeof(struct tcp_socket) * MAX_TCP_SOCKETS);
}

struct tcp_socket *alloc_tcp_socket()
{
    struct tcp_socket *sock;
    for (int i = 0; i<MAX_TCP_SOCKETS; i++) {
        sock = &tcp_sockets[i];
        if (sock->fd == 0) {
            sock->fd = cur_fd++;
            sock->state = CLOSED;
            return sock;
        }
    }

    /* No space left, error case */
    return NULL;
}

void free_tcp_socket(struct tcp_socket *sock)
{

}

struct tcp_socket *get_tcp_socket(int sockfd)
{
    struct tcp_socket sk;
    for (int i = 0; i<MAX_TCP_SOCKETS; i++) {
        sk = tcp_sockets[i];

        if (sk.fd == sockfd) return &sk;
    }

    return NULL;
}<commit_msg>Fix ugly pointer return bug<commit_after>#include "syshead.h"
#include "tcp_socket.h"

#define MAX_TCP_SOCKETS 128
static int cur_fd = 3;
static struct tcp_socket tcp_sockets[MAX_TCP_SOCKETS];

void init_tcp_sockets()
{
    memset(tcp_sockets, 0, sizeof(struct tcp_socket) * MAX_TCP_SOCKETS);
}

struct tcp_socket *alloc_tcp_socket()
{
    struct tcp_socket *sock;
    for (int i = 0; i<MAX_TCP_SOCKETS; i++) {
        sock = &tcp_sockets[i];
        if (sock->fd == 0) {
            sock->fd = cur_fd++;
            sock->state = CLOSED;
            return sock;
        }
    }

    /* No space left, error case */
    return NULL;
}

void free_tcp_socket(struct tcp_socket *sock)
{

}

struct tcp_socket *get_tcp_socket(int sockfd)
{
    struct tcp_socket *sk;
    for (int i = 0; i<MAX_TCP_SOCKETS; i++) {
        sk = &tcp_sockets[i];

        if (sk->fd == sockfd) return sk;
    }

    return NULL;
}
{'fraction_non_alphanumeric': 0.12235817575083426, 'fraction_numerical': 0.008898776418242492, 'mean_word_length': 2.7714884696016773, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1408116', 'n_tokens_mistral': 690, 'n_tokens_neox': 656, 'n_words': 160}