Changeset 15100


Ignore:
Timestamp:
Dec 1, 2011, 10:44:22 PM (8 years ago)
Author:
gz
Message:

Add abortable stream-peek-char and stream-listen methods for listener input stream

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/cocoa-listener.lisp

    r15065 r15100  
    5858
    5959
    60 
    61 (defmethod dequeue-listener-char ((stream cocoa-listener-input-stream) wait-p)
     60(defmethod queued-listener-char ((stream cocoa-listener-input-stream) wait-p dequeue-p)
    6261  (with-slots (queue queue-lock read-lock queue-semaphore text-semaphore cur-string cur-string-pos) stream
    6362    (with-lock-grabbed (read-lock)
    6463      (or (with-lock-grabbed (queue-lock)
    6564            (when (< cur-string-pos (length cur-string))
    66               (prog1 (aref cur-string cur-string-pos) (incf cur-string-pos))))
     65              (prog1 (aref cur-string cur-string-pos) (and dequeue-p (incf cur-string-pos)))))
    6766          (loop
    6867            (unless (if wait-p
     
    7675                (setq queue (delq s queue 1))
    7776                (when (< 0 (length s))
    78                   (setf cur-string s cur-string-pos 1)
     77                  (setf cur-string s cur-string-pos (if dequeue-p 1 0))
    7978                  (return (aref s 0))))))))))
    8079
     
    133132
    134133(defmethod enqueue-listener-input ((stream cocoa-listener-input-stream) string)
    135   (with-slots (queue-lock queue queue-semaphore text-semaphore) stream
    136     (with-lock-grabbed (queue-lock)
    137       (setq queue (nconc queue (list string)))
    138       (signal-semaphore queue-semaphore)
    139       (signal-semaphore text-semaphore))))
     134  (when (> (length string) 0)
     135    (with-slots (queue-lock queue queue-semaphore text-semaphore) stream
     136      (with-lock-grabbed (queue-lock)
     137        (setq queue (nconc queue (list string)))
     138        (signal-semaphore queue-semaphore)
     139        (signal-semaphore text-semaphore)))))
    140140
    141141(defmethod stream-read-char-no-hang ((stream cocoa-listener-input-stream))
    142   (dequeue-listener-char stream nil))
     142  (queued-listener-char stream nil t))
    143143
    144144(defmethod stream-read-char ((stream cocoa-listener-input-stream))
    145   (dequeue-listener-char stream t))
     145  (queued-listener-char stream t t))
     146
     147;; The default implementation of peek-char will lose the character if aborted. This won't.
     148(defmethod stream-peek-char ((stream cocoa-listener-input-stream))
     149  (queued-listener-char stream t nil))
     150
     151(defmethod stream-listen ((stream cocoa-listener-input-stream))
     152  (queued-listener-char stream nil nil))
    146153
    147154(defmethod stream-unread-char ((stream cocoa-listener-input-stream) char)
Note: See TracChangeset for help on using the changeset viewer.