<commit_before>{- |
  Raw UDP Server used by Ames driver.

  1. Opens a UDP socket and makes sure that it stays open.

    - If can't open the port, wait and try again repeatedly.
    - If there is an error reading or writting from the open socket,
      close it and open another, making sure, however, to reuse the
      same port

  2. Receives packets from the socket.

    - When packets come in from the socket, they go into a bounded queue.
    - If the queue is full, the packet is dropped.
    - If the socket is closed, wait and try again repeatedly.
    - `usRecv` gets the first packet from the queue.

  3. Sends packets to the socket.

    - Packets sent to `usSend` enter a bounded queue.
    - If that queue is full, the packet is dropped.
    - Packets are taken off the queue one at a time.
    - If the socket is closed (or broken), the packet is dropped.

  4. Runs until `usKill` is run, then all threads are killed and the
     socket is closed.
-}

module Urbit.Vere.Ames.UDP
  ( UdpServ(..)
  , fakeUdpServ
  , realUdpServ
  )
where

import Urbit.Prelude
import Urbit.Vere.Ports

import Network.Socket
<commit_msg>king: add requested disclamer to UDP.hs<commit_after>{- |
  Raw UDP Server used by Ames driver.

  1. Opens a UDP socket and makes sure that it stays open.

    - If can't open the port, wait and try again repeatedly.
    - If there is an error reading or writting from the open socket,
      close it and open another, making sure, however, to reuse the
      same port
        NOTE: It's not clear what, if anything, closing and reopening
      the socket does. We're keeping this behavior out of conservatism
      until we understand it better.

  2. Receives packets from the socket.

    - When packets come in from the socket, they go into a bounded queue.
    - If the queue is full, the packet is dropped.
    - If the socket is closed, wait and try again repeatedly.
    - `usRecv` gets the first packet from the queue.

  3. Sends packets to the socket.

    - Packets sent to `usSend` enter a bounded queue.
    - If that queue is full, the packet is dropped.
    - Packets are taken off the queue one at a time.
    - If the socket is closed (or broken), the packet is dropped.

  4. Runs until `usKill` is run, then all threads are killed and the
     socket is closed.
-}

module Urbit.Vere.Ames.UDP
  ( UdpServ(..)
  , fakeUdpServ
  , realUdpServ
  )
where

import Urbit.Prelude
import Urbit.Vere.Ports

import Network.Socket

{'fraction_non_alphanumeric': 0.06088709677419355, 'fraction_numerical': 0.0032258064516129032, 'mean_word_length': 2.648529411764706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '664833', 'n_tokens_mistral': 754, 'n_tokens_neox': 723, 'n_words': 376}