Mercurial > demo / examples/net/yoctochat.lisp
changeset 41: |
81b7333f27f8 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Sun, 16 Jun 2024 22:15:04 -0400 |
permissions: |
-rw-r--r-- |
description: |
more examples |
1 ;;; examples/net/yoctochat.lisp --- Yoctochat Implementation 3 ;; The tiniest (lisp) chat server on earth! 5 ;; based on https://github.com/robn/yoctochat 7 ;; A 'yoctochat' server will: 9 ;; - take a single commandline argument, the port to listen on 10 ;; - open a listening port 11 ;; - handle multiple connections and disconnections on that port 12 ;; - receive text on a connection, and forward it on to all ofhter connections 13 ;; - produce simple output about what it's doing 14 ;; - demonstrate a single IO multiplexing technique as simply as possible 15 ;; - be well commented! 19 ;; This implementation is based on the yc_uring.c implementation which 20 ;; uses io_uring. To use io_uring from Lisp, we use the high-level IO 21 ;; package, which internally calls foreign functions defined in the 27 (defpackage :examples/yoctochat 28 (:use :cl :std :net :cli/clap :io :log :sb-alien) 29 (:import-from :uring :load-uring)) 31 (in-package :examples/yoctochat) 33 ;; To start using the IO package we should make sure the liburing 34 ;; shared library is properly loaded. This function takes care of that 35 ;; and arranges for the library to be remembered when entering a saved 36 ;; lisp image such that it will be automatically re-opened. 39 ;; Initialize a simple logger to report on what's happening. 40 ;; (setq *logger* (make-logger nil)) 42 ;; Define some parameters for the queue depth and maximum number of 43 ;; connections allowed on a single server. 44 (defparameter *num-conns* 128) 46 (defparameter *queue-depth* (* 2 *num-conns*)) 48 (defclass yc-server (server) 49 ((connections :initform nil ::type sequence)) 50 (:documentation "The Yoctochat Server. ")) 52 ;; The main loop of our yoctochat server. The 'defmain' macro will 53 ;; produce a function 'main' which can be saved as an executable 56 (init-io *queue-depth*)