<commit_before>;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-

;;   Copyright (C) 2006, 2007 <NAME>
;;
;;   This code is free software; you can redistribute it and/or
;;   modify it under the terms of the version 2.1 of
;;   the GNU Lesser General Public License as published by
;;   the Free Software Foundation, as clarified by the
;;   preamble found here:
;;       http://opensource.franz.com/preamble.html
;;
;;   This program is distributed in the hope that it will be useful,
;;   but WITHOUT ANY WARRANTY; without even the implied warranty of
;;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;   GNU General Public License for more details.
;;
;;   You should have received a copy of the GNU Lesser General
;;   Public License along with this library; if not, write to the
;;   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
;;   Boston, MA 02110-1301, USA

(in-package :io.multiplex)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defvar *available-multiplexers* nil)
  (defvar *best-available-multiplexer* nil))

(defvar *maximum-event-loop-timeout* 1)



;;;
;;; Event-Base
;;;
(defclass event-base ()
  ((mux :initform (make-instance *best-available-multiplexer*)
        :reader mux-of)
   (fds :initform (make-hash-table :test 'eql)
        :reader fds-of)
   (timeouts :initform (make-queue)
             :reader timeouts-of)
   (exit :initform nil
         :accessor exit-p)
   (exit-when-empty :initarg :exit-when-empty
                    :accessor exit-when-empty-p))
  (:default-initargs :exit-when-empty nil))

(defmethod print-object ((base event-base) stream)
  (print-unreadable-object (base stream :type nil :identity t)
    (format stream "event base, ~A FDs monitored, using: ~A"
            (hash-table-count (fds-of base))
            (mux-of base))))

(defgeneric close-event-base (event-base)
  (:method ((event-base event-base))
    (with-accessors ((mux mux-of)) event-base
      (close-multiplexer mux)
      (dolist (slot '(fds timeouts exit))
        (setf (slot-value event-base slot) nil))
      event-base)))

(defgeneric add-fd (base fd event-type function &key timeout persistent))

(defgeneric add-timeout (event-base function timeout &key persistent))

(defgeneric remove-event (event-base event))

(defgeneric remove-events (event-base event-list))

(defgeneric event-dispatch (event-base &key &allow-other-keys))

(defgeneric exit-event-loop (event-base &key delay)<commit_msg>Using CLOSE instead of CLOSE-EVENT-BASE. Signed-off-by: <NAME> <<EMAIL>><commit_after>;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-

;;   Copyright (C) 2006, 2007 <NAME>
;;
;;   This code is free software; you can redistribute it and/or
;;   modify it under the terms of the version 2.1 of
;;   the GNU Lesser General Public License as published by
;;   the Free Software Foundation, as clarified by the
;;   preamble found here:
;;       http://opensource.franz.com/preamble.html
;;
;;   This program is distributed in the hope that it will be useful,
;;   but WITHOUT ANY WARRANTY; without even the implied warranty of
;;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;   GNU General Public License for more details.
;;
;;   You should have received a copy of the GNU Lesser General
;;   Public License along with this library; if not, write to the
;;   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
;;   Boston, MA 02110-1301, USA

(in-package :io.multiplex)

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defvar *available-multiplexers* nil)
  (defvar *best-available-multiplexer* nil))

(defvar *maximum-event-loop-timeout* 1)



;;;
;;; Event-Base
;;;
(defclass event-base ()
  ((mux :initform (make-instance *best-available-multiplexer*)
        :reader mux-of)
   (fds :initform (make-hash-table :test 'eql)
        :reader fds-of)
   (timeouts :initform (make-queue)
             :reader timeouts-of)
   (exit :initform nil
         :accessor exit-p)
   (exit-when-empty :initarg :exit-when-empty
                    :accessor exit-when-empty-p))
  (:default-initargs :exit-when-empty nil))

(defmethod print-object ((base event-base) stream)
  (print-unreadable-object (base stream :type nil :identity t)
    (format stream "event base, ~A FDs monitored, using: ~A"
            (hash-table-count (fds-of base))
            (mux-of base))))

(defmethod close ((event-base event-base) &key abort)
  (declare (ignore abort))
  (with-accessors ((mux mux-of)) event-base
    (close mux)
    (dolist (slot '(fds timeouts exit))
      (setf (slot-value event-base slot) nil))
    event-base))

(defgeneric add-fd (base fd event-type function &key timeout persistent))

(defgeneric add-timeout (event-base function timeout &key persistent))

(defgeneric remove-event (event-base event))

(defgeneric remove-events (event-base event-list))

(defgeneric event-dispatch (event-base &key &allow-other-keys))

(defgeneric exit-event-loop (event-base &key delay)
{'fraction_non_alphanumeric': 0.12585444310414154, 'fraction_numerical': 0.008845999195818254, 'mean_word_length': 3.4658886894075405, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4298886', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1545, 'n_words': 521}