;;; along with Mudsync. If not, see <http://www.gnu.org/licenses/>.
(define-module (mudsync networking)
- #:use-module (8sync systems actors)
+ #:use-module (8sync actors)
#:use-module (8sync agenda)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
;; send input to this actor
(send-input-to #:getter nm-send-input-to
#:init-keyword #:send-input-to)
- (message-handler
+
+ (actions
+ #:allocation #:each-subclass
#:init-value
- (make-action-dispatch
- ((start-listening actor message)
- (nm-install-socket actor (message-ref message 'server %default-server)
- (message-ref message 'port %default-port)))
- ((send-to-client actor message client data)
- (nm-send-to-client-id actor client data)))))
+ (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))))))
;;; TODO: We should provide something like this, but this isn't used currently,
;;; and uses old deprecated code (the 8sync-port-remove stuff).
(sockaddr:addr client-details)))
(fcntl client F_SETFL (logior O_NONBLOCK (fcntl client F_GETFL)))
(hash-set! (nm-clients nm) client-id client)
- (<- nm (nm-send-input-to nm) 'new-client #:client client-id)
+ (<-* `(#:actor ,nm) (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)
(begin
(nm-handle-line nm client client-id
(string-trim-right line #\return))
- (loop))))
+ (when (actor-alive? nm)
+ (loop)))))
(loop))
(define (nm-handle-port-closed nm client client-id)
"Handle a closed port"
(format #t "DEBUG: handled closed port ~x\n" client-id)
(hash-remove! (nm-clients nm) client-id)
- (<- nm (nm-send-input-to nm) 'client-closed #:client client-id))
+ (<-* `(#:actor ,nm) (nm-send-input-to nm) 'client-closed #:client client-id))
(define-method (nm-handle-port-eof nm client client-id)
"Handle seeing an EOF on port"
(format #t "DEBUG: handled eof-object on port ~x\n" client-id)
(close client)
(hash-remove! (nm-clients nm) client-id)
- (<- nm (nm-send-input-to nm) 'client-closed #:client client-id))
+ (<-* `(#:actor ,nm) (nm-send-input-to nm) 'client-closed
+ #:client client-id))
(define-method (nm-handle-line nm client client-id line)
"Handle an incoming line of input from a client"
- (<- nm (nm-send-input-to nm) 'client-input
+ (<-* `(#:actor ,nm) (nm-send-input-to nm) 'client-input
#:data line
#:client client-id))