(elmo-network-session-idle-timeout): New option.
authorteranisi <teranisi>
Sat, 8 Jan 2005 12:41:48 +0000 (12:41 +0000)
committerteranisi <teranisi>
Sat, 8 Jan 2005 12:41:48 +0000 (12:41 +0000)
(elmo-network-session): New attribute `last-accessed'.
(elmo-network-get-session): Discard network cache if elapsed time
since last-accessed is larger than elmo-network-session-idle-timeout.

elmo/ChangeLog
elmo/elmo-net.el

index ed39ac1..f5bfd16 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-08  Yuuichi Teranishi  <teranisi@gohome.org>
+
+       * elmo-net.el (elmo-network-session-idle-timeout): New option.
+       (elmo-network-session): New attribute `last-accessed'.
+       (elmo-network-get-session): Discard network cache if elapsed time
+       since last-accessed is larger than elmo-network-session-idle-timeout.
+
 2005-01-07  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
 
        * elmo.el (elmo-find-fetch-strategy): Removed argument `entity'
index 480fa7a..ece84d8 100644 (file)
 
 (defvar sasl-mechanisms)
 
+(defcustom elmo-network-session-idle-timeout nil
+  "Idle timeout of the network cache. Specified in seconds.
+If elapsed time since last access is larger than this value,
+cached session is not reused.
+If nil, network cache is reused."
+  :type 'number
+  :group 'elmo)
+
 ;;; Code:
 ;;
 (eval-and-compile
@@ -66,7 +74,8 @@
                                              auth
                                              stream-type
                                              process
-                                             greeting))
+                                             greeting
+                                             last-accessed))
   (luna-define-internal-accessors 'elmo-network-session))
 
 (luna-define-generic elmo-network-initialize-session (session)
@@ -166,16 +175,26 @@ if making session failed, returns nil."
     (setq pair (assoc (setq key (elmo-network-session-cache-key name folder))
                      elmo-network-session-cache))
     (when (and pair
-              (not (memq (process-status
-                          (elmo-network-session-process-internal
-                           (cdr pair)))
-                         '(open run))))
+              (or (not (memq (process-status
+                              (elmo-network-session-process-internal
+                               (cdr pair)))
+                             '(open run)))
+                  (and elmo-network-session-idle-timeout
+                       (elmo-network-session-last-accessed-internal
+                        (cdr pair))
+                       (elmo-time-expire
+                        (elmo-network-session-last-accessed-internal
+                         (cdr pair))
+                        elmo-network-session-idle-timeout))))
       (setq elmo-network-session-cache
            (delq pair elmo-network-session-cache))
       (elmo-network-close-session (cdr pair))
       (setq pair nil))
     (if pair
-       (cdr pair)                      ; connection cache exists.
+       (progn
+         (elmo-network-session-set-last-accessed-internal
+          (cdr pair) (current-time))
+         (cdr pair))                   ; connection cache exists.
       (unless if-exists
        (setq session
              (elmo-network-open-session
@@ -211,7 +230,9 @@ Returns a process object.  if making session failed, returns nil."
                           :auth auth
                           :stream-type stream-type
                           :process nil
-                          :greeting nil))
+                          :greeting nil
+                          :last-accessed (current-time)
+                          ))
        (buffer (format " *%s session for %s@%s:%d%s"
                        name
                        user