From 155f1c55e5b3cfb5efc0fa3a87aca4843b418415 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Wed, 16 Jul 2003 16:40:35 +0000 Subject: [PATCH] r5317: *** empty log message *** --- classes.lisp | 4 +++- log.lisp | 18 ++++++++++++++++++ sessions.lisp | 48 +++++++++++++++++++++++++++++++++++++++++------- wol.asd | 3 ++- 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 log.lisp diff --git a/classes.lisp b/classes.lisp index 869cc9e..70f01b3 100644 --- a/classes.lisp +++ b/classes.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: July 2003 ;;;; -;;;; $Id: classes.lisp,v 1.1 2003/07/16 16:02:21 kevin Exp $ +;;;; $Id: classes.lisp,v 1.2 2003/07/16 16:40:35 kevin Exp $ ;;;; ;;;; This file and Wol are Copyright (c) 2001-2003 by Kevin M. Rosenberg ;;;; ************************************************************************* @@ -26,6 +26,8 @@ (defclass websession () ((key :initarg :key :accessor websession-key) (lastref :initarg :lastref :accessor websession-lastref) + (lifetime :initarg :lifetime :initform nil + :accessor websession-lifetime) (data :initform nil :accessor websession-data) (method :initarg :method :accessor websession-method) (variables :initform (make-hash-table :test 'equal) diff --git a/log.lisp b/log.lisp new file mode 100644 index 0000000..3793720 --- /dev/null +++ b/log.lisp @@ -0,0 +1,18 @@ +;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: wol -*- +;;;; ************************************************************************* +;;;; FILE IDENTIFICATION +;;;; +;;;; Name: log.lisp +;;;; Purpose: Logging functions +;;;; Programmer: Kevin M. Rosenberg +;;;; Date Started: July 2003 +;;;; +;;;; $Id: log.lisp,v 1.1 2003/07/16 16:40:35 kevin Exp $ +;;;; +;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg +;;;; ************************************************************************* + +(in-package #:wol) + +(defun add-log-entry (project fmt &rest args) + (apply #'cmsg fmt args)) diff --git a/sessions.lisp b/sessions.lisp index 227483b..b5bc559 100644 --- a/sessions.lisp +++ b/sessions.lisp @@ -7,19 +7,13 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: July 2003 ;;;; -;;;; $Id: sessions.lisp,v 1.1 2003/07/16 16:02:21 kevin Exp $ +;;;; $Id: sessions.lisp,v 1.2 2003/07/16 16:40:35 kevin Exp $ ;;;; ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg ;;;; ************************************************************************* (in-package #:wol) -(defun start-reaper () - (process-run-function "wol-reaper" - (lambda () (reap-sessions) (kmrcl::process-sleep *reap-interval*)))) - -(defun reap-sessions () - (cmsg-c :debug "Reaping")) (defun make-new-session-id () (random-string :length 24 :set :lower-alphanumeric)) @@ -48,6 +42,7 @@ (sess (make-instance 'websession :key key :lastref (get-universal-time) + :lifetime (lifetime (session-master (entity-project ent))) :method method)) (hash (sessions (session-master (entity-project ent))))) (when hash @@ -60,3 +55,42 @@ (getf (request-plist req) :session-id)) (setf (websession-from-req req) (ensure-websession it req ent :uri)))) + + + +;;; Reap expired sessions + + +(defun start-reaper () + (process-run-function "wol-reaper" + (lambda () (reap-sessions) (kmrcl::process-sleep *reap-interval*)))) + +(defun reap-sessions () + (cmsg-c :debug "Reaping") + (dolist (expired (find-expired-sessions)) + (flush-expired expired))) + +(defun find-expired-sessions () + (loop for s in (all-sessions) + when (is-session-expired (car s)) + collect s)) + +(defun all-sessions (&aux s) + (dolist (p *active-projects* s) + (let ((sm (session-master p)) + (sessions (when sm (sessions sm)))) + (when sessions + (maphash + (lambda (k v) + (declare (ignore k)) + (push (cons v p) s)) + sessions))))) + +(defmethod flush-expired (s) + (let ((sessions (sessions (session-master (cdr s))))) + (remhash (car s) sessions) + (add-log-entry (cdr s) "flush expired session: key=~A" (websession-key (car s))))) + +(defun is-session-expired (ws) + (> (get-universal-time) (+ (websession-lastref ws) + (websession-lifetime ws)))) diff --git a/wol.asd b/wol.asd index 15ed38f..664a8fb 100644 --- a/wol.asd +++ b/wol.asd @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: July 2003 ;;;; -;;;; $Id: wol.asd,v 1.1 2003/07/16 16:02:21 kevin Exp $ +;;;; $Id: wol.asd,v 1.2 2003/07/16 16:40:35 kevin Exp $ ;;;; ;;;; This file and Wol are Copyright (c) 2003 by Kevin M. Rosenberg ;;;; ************************************************************************* @@ -33,4 +33,5 @@ (:file "project" :depends-on ("classes")) (:file "sessions" :depends-on ("classes")) (:file "uri" :depends-on ("classes")) + (:file "log" :depends-on ("classes")) )) -- 2.34.1