[nio-cvs] r106 - branches/home/psmith/restructure/src/io
psmith at common-lisp.net
psmith at common-lisp.net
Sun Mar 18 01:07:14 UTC 2007
Author: psmith
Date: Sat Mar 17 20:07:13 2007
New Revision: 106
Modified:
branches/home/psmith/restructure/src/io/async-fd.lisp
branches/home/psmith/restructure/src/io/nio-server.lisp
Log:
Corrected return from connect and utilised write eagain in async-fd
Modified: branches/home/psmith/restructure/src/io/async-fd.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/async-fd.lisp (original)
+++ branches/home/psmith/restructure/src/io/async-fd.lisp Sat Mar 17 20:07:13 2007
@@ -129,7 +129,9 @@
((error-number :initarg :error)))
(defun write-more (async-fd)
- "Write data from ASYNC-FD's write bytebuffer"
+ "Write data from ASYNC-FD's foreign-write-buffer to the network \
+ Leaves foreign-write-buffer in state ready to be written to \
+ Sets write-ready appropriatly"
#+nio-debug (format-log t "async-fd:write-more - called with ~A~%" async-fd)
(with-slots (write-fd foreign-write-buffer close-pending) async-fd
#+nio-debug (format t "async-fd:write-more - foreign-write-buffer b4 flip ~A~%" foreign-write-buffer)
@@ -143,21 +145,24 @@
(when (not (eql now-written -1))
(inc-position foreign-write-buffer now-written)
(incf total-written now-written)))
-#+nio-debug (format t "async-fd:write-more - after write :foreign-write-buffer ~A :now-written ~A :total-written ~A ~%" foreign-write-buffer now-written total-written))
- (if (eql now-written -1)
+#+nio-debug (format t "async-fd:write-more - after write :foreign-write-buffer ~A :now-written ~A :total-written ~A ~%" foreign-write-buffer now-written total-written)
+ )
+
+ (when (eql now-written -1)
;;Deal with failure
(let ((err (get-errno)))
- (format t "write-more - write returned -1 :errno ~A~%" err)
- (unless (eql err 11) ;; eagain - failed to write whole buffer need to wait for next notify
- (perror)
- (let ((err-cond (make-instance 'write-error :error err)))
- (close-fd (write-fd async-fd)); - deal with in nio-server?
- (error err-cond))))
- ;;update buffers
- (if (eql (remaining foreign-write-buffer) 0)
- (clear foreign-write-buffer)
- (error 'not-implemented-yet))))
-
+#+nio-debug (format t "write-more - write returned -1 :errno ~A~%" err)
+ (if (eql err 11) ;; eagain - failed to write whole buffer need to wait for next notify
+ (setf (write-ready async-fd) nil)
+ (progn
+ (perror)
+ (let ((err-cond (make-instance 'write-error :error err)))
+ (close-fd (write-fd async-fd)); - deal with in nio-server?
+ (error err-cond))))))
+ ;;update buffers
+ (if (eql (remaining foreign-write-buffer) 0)
+ (clear foreign-write-buffer)
+ (compact foreign-write-buffer)))
#+nio-debug (format t "write buffer after write :~A~%" foreign-write-buffer)
(when (eql (buffer-position foreign-write-buffer) 0)
(when close-pending (close-async-fd async-fd)))))
Modified: branches/home/psmith/restructure/src/io/nio-server.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/nio-server.lisp (original)
+++ branches/home/psmith/restructure/src/io/nio-server.lisp Sat Mar 17 20:07:13 2007
@@ -50,10 +50,14 @@
(when (> (buffer-position (foreign-read-buffer async-fd)) 0)
(process-read async-fd))
;process-writes
- (process-write async-fd)
- (when (and (write-ready async-fd)
- (> (buffer-position (foreign-write-buffer async-fd)) 0))
- (write-more async-fd))
+ (loop
+ (when (and (write-ready async-fd) (> (buffer-position (foreign-write-buffer async-fd)) 0))
+ (write-more async-fd))
+ (when (write-ready async-fd)
+ (assert (eql (buffer-position (foreign-write-buffer async-fd)) 0))
+ (process-write async-fd))
+ (unless (and (write-ready async-fd) (> (buffer-position (foreign-write-buffer async-fd)) 0)) (return)))
+
;process normal close
(when (close-pending async-fd)
(write-more async-fd)
@@ -192,7 +196,8 @@
(return-from connect sm))
(progn
(format t "Connect failed!!~A ~%" (get-errno))
- (close-fd sock)))))
+ (close-fd sock)
+ nil))))
(defun add-connection(node)
(nio-utils:add +connected-sockets-queue+ node))
\ No newline at end of file
More information about the Nio-cvs
mailing list