From psmith at common-lisp.net Fri Mar 2 00:41:30 2007 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Thu, 1 Mar 2007 19:41:30 -0500 (EST) Subject: [nio-cvs] r103 - branches/home/psmith/restructure/src/utils Message-ID: <20070302004130.DA6883E054@common-lisp.net> Author: psmith Date: Thu Mar 1 19:41:30 2007 New Revision: 103 Modified: branches/home/psmith/restructure/src/utils/concurrent-queue.lisp Log: Improved debug output from queue Modified: branches/home/psmith/restructure/src/utils/concurrent-queue.lisp ============================================================================== --- branches/home/psmith/restructure/src/utils/concurrent-queue.lisp (original) +++ branches/home/psmith/restructure/src/utils/concurrent-queue.lisp Thu Mar 1 19:41:30 2007 @@ -65,7 +65,7 @@ ;Append the element to the tail of this queue (defmethod add ((queue concurrent-queue) elt) -#+nio-debug (format-log t "concurent-queue:add - (~A) adding ~A~%" sb-thread:*current-thread* elt) +#+nio-debug (format-log t "concurent-queue:add - (~A) adding ~A to ~A~%" sb-thread:*current-thread* elt queue) (sb-thread:with-mutex ((buffer-lock queue)) (setf (buffer queue) (append (buffer queue) (list elt)) ) (sb-thread:condition-notify (buffer-queue queue)))) From psmith at common-lisp.net Fri Mar 2 00:50:07 2007 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Thu, 1 Mar 2007 19:50:07 -0500 (EST) Subject: [nio-cvs] r104 - branches/home/psmith/restructure/src/io Message-ID: <20070302005007.7ADC859088@common-lisp.net> Author: psmith Date: Thu Mar 1 19:50:07 2007 New Revision: 104 Modified: branches/home/psmith/restructure/src/io/async-socket.lisp Log: Improved error-handling on %socket Modified: branches/home/psmith/restructure/src/io/async-socket.lisp ============================================================================== --- branches/home/psmith/restructure/src/io/async-socket.lisp (original) +++ branches/home/psmith/restructure/src/io/async-socket.lisp Thu Mar 1 19:50:07 2007 @@ -96,6 +96,11 @@ (socklent :int)) +(define-condition fd-error (error) + ((error-number :initarg :error))) + + + ;;TODO put backlog on config (defun start-listen (socket-fd &optional (backlog 1000)) (%listen socket-fd backlog)) @@ -104,7 +109,12 @@ ;;;; IPv4 (defun make-inet-socket (&optional (type :tcp)) - (%socket +af-inet+ (ecase type (:tcp +sock-stream+) (:udp +sock-dgram+)) 0)) + (let ((fd (%socket +af-inet+ (ecase type (:tcp +sock-stream+) (:udp +sock-dgram+)) 0))) + (when (eql fd -1) + (perror) +#+nio-debug (format-log t "async-socket::make-inet-socket - %socket failed (errno ~A)~%" ) + (error (make-instance 'fd-error :error (get-errno)))) + fd)) (defun init-inet-socket(sa port addr) @@ -133,7 +143,7 @@ nil))) (defun connect-inet-socket (socket-fd node) - (format-log t "async-socket:connect-inet-socket ccalled with ~A, and ~A~%" socket-fd node) + (format-log t "async-socket:connect-inet-socket called with ~A, and ~A~%" socket-fd node) (with-foreign-object (sa 'sockaddr-in) (init-inet-socket sa (remote-port node) (remote-host node)) (let ((res (%connect socket-fd sa +sockaddr-in-len+))) @@ -221,3 +231,13 @@ (foreign-free len) (if (>= res 0) async-fd nil) ))))))) + + + +(defun test-socket-connect(close) + (format t "Got fd's :") + (loop for i from 1 to 1025 do + (let ((fd (make-inet-socket))) + (format t "~A " fd) + (when (and close fd) + (close-fd fd))))) \ No newline at end of file From psmith at common-lisp.net Sat Mar 17 18:31:00 2007 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Sat, 17 Mar 2007 13:31:00 -0500 (EST) Subject: [nio-cvs] r105 - branches/home/psmith/restructure/src/io Message-ID: <20070317183100.5DE9B12088@common-lisp.net> Author: psmith Date: Sat Mar 17 13:30:59 2007 New Revision: 105 Modified: branches/home/psmith/restructure/src/io/nio-server.lisp Log: Fix leaking sockets 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 13:30:59 2007 @@ -190,7 +190,9 @@ (if (connect-inet-socket sock node) (let ((sm (create-state-machine connection-type sock sock node))) (return-from connect sm)) - (format t "Connect failed!!~A ~%" (get-errno))))) + (progn + (format t "Connect failed!!~A ~%" (get-errno)) + (close-fd sock))))) (defun add-connection(node) (nio-utils:add +connected-sockets-queue+ node)) \ No newline at end of file From psmith at common-lisp.net Sun Mar 18 01:07:14 2007 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Sat, 17 Mar 2007 20:07:14 -0500 (EST) Subject: [nio-cvs] r106 - branches/home/psmith/restructure/src/io Message-ID: <20070318010714.7B4961A0AC@common-lisp.net> 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 From psmith at common-lisp.net Mon Mar 19 00:27:10 2007 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Sun, 18 Mar 2007 19:27:10 -0500 (EST) Subject: [nio-cvs] r107 - branches/home/psmith/restructure/src/io Message-ID: <20070319002710.AB58E1010@common-lisp.net> Author: psmith Date: Sun Mar 18 19:27:10 2007 New Revision: 107 Modified: branches/home/psmith/restructure/src/io/async-fd.lisp Log: up max buffer size 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 Sun Mar 18 19:27:10 2007 @@ -168,7 +168,7 @@ (when close-pending (close-async-fd async-fd))))) -(defconstant +MAX-BUFFER-SIZE-BYTES+ (* 1024 1024)) +(defconstant +MAX-BUFFER-SIZE-BYTES+ (* 1024 1024 15)) (defmacro realloc-buffer(async-fd accessor size) `(let ((buffer (,accessor ,async-fd)))