<commit_before>use std::thread;
use std::net::UdpSocket;

use dns::answer::Answer;
use dns::message::Message;

pub fn run() -> thread::JoinHandle<u8> {
    thread::spawn(move || {
        loop {
            let socket = UdpSocket::bind("127.0.0.1:12043").unwrap();

            let mut buffer: [u8; 512] = [0; 512];
            let (size, source) = socket.recv_from(&mut buffer).unwrap();

            let query_message = Message::unpack(&buffer[..size]);

            let answer_message: Message;

            if query_message.questions[0].name.last().unwrap() == "dev" {
                let mut answers = Vec::new();
                answers.push(Answer{
                    name: query_message.questions[0].name.clone(),
                    rrtype: 1,
                    class: 1,
                    ttl: 0,
                    length: 4,
                    data: vec!(127, 0, 0, 1),
                });

                answer_message = Message {
                    query_response: 1,
                    answer_count: 1,
                    ns_count: 0,
                    ar_count: 0,
                    answers: answers,
                    ..query_message
                };
            } else {
                answer_message = Message {
                    query_response: 1,
                    answer_count: 0,
                    ns_count: 0,
                    ar_count: 0,
                    error_code: 3,
                    ..query_message
                };
            }

            let size = answer_message.pack(&mut buffer);

            socket.send_to(&buffer[..size], &source).unwrap();

            drop(socket);
        }
    })
}
<commit_msg>Avoid rebiding of udp socket on every dns request<commit_after>use std::thread;
use std::net::UdpSocket;

use dns::answer::Answer;
use dns::message::Message;

pub fn run() -> thread::JoinHandle<u8> {
    thread::spawn(move || {
        let socket = UdpSocket::bind("127.0.0.1:12043").unwrap();

        let mut buffer: [u8; 512] = [0; 512];

        loop {
            let (size, source) = socket.recv_from(&mut buffer).unwrap();

            let query_message = Message::unpack(&buffer[..size]);

            let answer_message: Message;

            if query_message.questions[0].name.last().unwrap() == "dev" {
                let mut answers = Vec::new();

                answers.push(Answer{
                    name: query_message.questions[0].name.clone(),
                    rrtype: 1,
                    class: 1,
                    ttl: 0,
                    length: 4,
                    data: vec!(127, 0, 0, 1),
                });

                answer_message = Message {
                    query_response: 1,
                    answer_count: 1,
                    ns_count: 0,
                    ar_count: 0,
                    answers: answers,
                    ..query_message
                };
            } else {
                answer_message = Message {
                    query_response: 1,
                    answer_count: 0,
                    ns_count: 0,
                    ar_count: 0,
                    error_code: 3,
                    ..query_message
                };
            }

            let size = answer_message.pack(&mut buffer);

            socket.send_to(&buffer[..size], &source).unwrap();
        }
    })
}

{'fraction_non_alphanumeric': 0.11818993748139327, 'fraction_numerical': 0.0244120273891039, 'mean_word_length': 1.163554410817772, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6768886', 'n_tokens_mistral': 994, 'n_tokens_neox': 870, 'n_words': 191}