<commit_before>(in-package :cl-async)

(defparameter *buffer-size* 16384
  "The amount of data we'll pull from the evbuffers when doing reading/writing.")

(defconstant +sockaddr-size+ (cffi:foreign-type-size (le::cffi-type le::sockaddr-in))
  "Really no sense in computing this OVER AND OVER.")

(defun get-last-tcp-err ()
  "Since libevent provides a macro but not a function for getting the last error
   code, we have to essentially rebuild that macro here.

   NOTE: As libevent says, this function cannot be considered idempotent. In
   other words, calling it more than once may result in different values
   returned. So, call once and save the result until the next time an error
   happens."
  #+(or :windows :win32 :win64)
    (let ((code (cffi:foreign-funcall "WSAGetLastError" :int)))
      (values code
              (cffi:foreign-funcall "evutil_socket_error_to_string" :int code :string)))
  #-(or :windows :win32 :win64)
    (let ((code (cffi:mem-aref (cffi:foreign-symbol-pointer "errno") :int)))
      (values code
              (cffi:foreign-funcall "strerror" :int code :string))))

(defun close-socket (bev)
  "Free a socket (bufferevent) and clear out all associated data."
  (le:bufferevent-disable bev (logior le:+ev-read+ le:+ev-write+))
  ;; grab the data pointer associated with the bufferevent and free it. see
  ;; comment tcp-send about data-pointer for a better explanation.
  (let ((bev-data-pointer (deref-data-from-pointer bev))
        (fd (le::bufferevent-getfd bev)))
    (le:bufferevent-free bev)
    (le:evutil-closesocket fd)
    (free-pointer-data bev-data-pointer)
    (free-pointer-data bev :preserve-pointer t)))
<commit_msg>renaming bev to socket in close-socket<commit_after>(in-package :cl-async)

(defparameter *buffer-size* 16384
  "The amount of data we'll pull from the evbuffers when doing reading/writing.")

(defconstant +sockaddr-size+ (cffi:foreign-type-size (le::cffi-type le::sockaddr-in))
  "Really no sense in computing this OVER AND OVER.")

(defun get-last-tcp-err ()
  "Since libevent provides a macro but not a function for getting the last error
   code, we have to essentially rebuild that macro here.

   NOTE: As libevent says, this function cannot be considered idempotent. In
   other words, calling it more than once may result in different values
   returned. So, call once and save the result until the next time an error
   happens."
  #+(or :windows :win32 :win64)
    (let ((code (cffi:foreign-funcall "WSAGetLastError" :int)))
      (values code
              (cffi:foreign-funcall "evutil_socket_error_to_string" :int code :string)))
  #-(or :windows :win32 :win64)
    (let ((code (cffi:mem-aref (cffi:foreign-symbol-pointer "errno") :int)))
      (values code
              (cffi:foreign-funcall "strerror" :int code :string))))

(defun close-socket (socket)
  "Free a socket (bufferevent) and clear out all associated data."
  (le:bufferevent-disable socket (logior le:+ev-read+ le:+ev-write+))
  ;; grab the data pointer associated with the bufferevent and free it. see
  ;; comment tcp-send about data-pointer for a better explanation.
  (let ((bev-data-pointer (deref-data-from-pointer socket))
        (fd (le::bufferevent-getfd socket)))
    (le:bufferevent-free socket)
    (le:evutil-closesocket fd)
    (free-pointer-data bev-data-pointer)
    (free-pointer-data socket :preserve-pointer t)))

{'fraction_non_alphanumeric': 0.11498669819686669, 'fraction_numerical': 0.007685486254803429, 'mean_word_length': 3.8412017167381975, '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': '3412490', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1073, 'n_words': 371}