From b1bf0fc9ec0ffcc06b7b1d4e422f3e28a00a27a6 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 19 Jan 2017 13:56:10 -0600 Subject: [PATCH] Clean up the networking code a bit. --- mudsync/networking.scm | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/mudsync/networking.scm b/mudsync/networking.scm index d2593d1..f30a1b9 100644 --- a/mudsync/networking.scm +++ b/mudsync/networking.scm @@ -37,27 +37,24 @@ (define %default-server #f) (define %default-port 8889) -(define-class () +(define-actor () + ((start-listening + (lambda* (actor message + #:key (server %default-server) + (port %default-port)) + (nm-install-socket actor server port))) + (send-to-client + (lambda* (actor message #:key client data) + (nm-send-to-client-id actor client data))) + (new-client nm-new-client)) + (server-socket #:getter nm-server-socket) ;; mapping of client -> client-id (clients #:getter nm-clients #:init-thunk make-hash-table) ;; send input to this actor (send-input-to #:getter nm-send-input-to - #:init-keyword #:send-input-to) - - (actions - #:allocation #:each-subclass - #:init-value - (build-actions - (start-listening - (lambda* (actor message - #:key (server %default-server) - (port %default-port)) - (nm-install-socket actor server port))) - (send-to-client - (lambda* (actor message #:key client data) - (nm-send-to-client-id actor client data)))))) + #:init-keyword #:send-input-to)) ;;; TODO: We should provide something like this, but this isn't used currently, ;;; and uses old deprecated code (the 8sync-port-remove stuff). @@ -121,10 +118,11 @@ (let loop () ;; (yield) ;; @@: Do we need this? (define client-connection (accept s)) - (8sync (nm-new-client nm s client-connection)) + (<- (actor-id nm) 'new-client + s client-connection) (loop))) -(define (nm-new-client nm s client-connection) +(define (nm-new-client nm message s client-connection) "Handle new client coming in to socket S" (define client-details (cdr client-connection)) (define client (car client-connection)) @@ -135,7 +133,7 @@ (sockaddr:addr client-details))) (fcntl client F_SETFL (logior O_NONBLOCK (fcntl client F_GETFL))) (hash-set! (nm-clients nm) client-id client) - (<-* `(#:actor ,nm) (nm-send-input-to nm) 'new-client #:client client-id) + (<- (nm-send-input-to nm) 'new-client #:client client-id) (nm-client-receive-loop nm client client-id)) (define (nm-client-receive-loop nm client client-id) -- 2.31.1