From psmith at common-lisp.net Sun Oct 1 00:19:28 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Sat, 30 Sep 2006 20:19:28 -0400 (EDT) Subject: [nio-cvs] r3 - Message-ID: <20061001001928.7AE4B4B01E@common-lisp.net> Author: psmith Date: Sat Sep 30 20:19:28 2006 New Revision: 3 Modified: nio.asd Log: Corrected typo in nio.asd Modified: nio.asd ============================================================================== --- nio.asd (original) +++ nio.asd Sat Sep 30 20:19:28 2006 @@ -6,7 +6,7 @@ :components ((:file "nio") (:file "async-fd" :depends-on ("nio")) - (:file "async-socket" :depend-on ("async-fd")) + (:file "async-socket" :depends-on ("async-fd")) ) :depends-on (:cffi)) From psmith at common-lisp.net Tue Oct 3 01:41:03 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Mon, 2 Oct 2006 21:41:03 -0400 (EDT) Subject: [nio-cvs] r4 - Message-ID: <20061003014103.ED5274E000@common-lisp.net> Author: psmith Date: Mon Oct 2 21:41:03 2006 New Revision: 4 Added: logo120x80.png (contents, props changed) Log: Added missing png Added: logo120x80.png ============================================================================== Binary file. No diff available. From psmith at common-lisp.net Wed Oct 4 18:28:01 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Wed, 4 Oct 2006 14:28:01 -0400 (EDT) Subject: [nio-cvs] r5 - Message-ID: <20061004182801.46CDE710F0@common-lisp.net> Author: psmith Date: Wed Oct 4 14:28:01 2006 New Revision: 5 Added: nio-httpd.asd Modified: nio.asd Log: Commited asdf-install able changes by William Bland Added: nio-httpd.asd ============================================================================== --- (empty file) +++ nio-httpd.asd Wed Oct 4 14:28:01 2006 @@ -0,0 +1,6 @@ + +(defsystem :nio-httpd + :components ((:file "nio-server") + (:file "nio-httpd" :depends-on ("nio-server")) + (:file "nio-httpd-default-site" :depends-on ("nio-httpd"))) + :depends-on (:nio)) Modified: nio.asd ============================================================================== --- nio.asd (original) +++ nio.asd Wed Oct 4 14:28:01 2006 @@ -9,5 +9,5 @@ (:file "async-socket" :depends-on ("async-fd")) ) - :depends-on (:cffi)) + :depends-on (:cffi :event-notification)) From psmith at common-lisp.net Tue Oct 10 02:52:11 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Mon, 9 Oct 2006 22:52:11 -0400 (EDT) Subject: [nio-cvs] r6 - branches tags trunk trunk/src Message-ID: <20061010025211.903F336024@common-lisp.net> Author: psmith Date: Mon Oct 9 22:52:10 2006 New Revision: 6 Added: branches/ tags/ trunk/ trunk/event-notification.asd - copied, changed from r5, event-notification.asd trunk/nio-httpd.asd - copied, changed from r5, nio-httpd.asd trunk/nio.asd - copied, changed from r5, nio.asd trunk/src/ trunk/src/async-fd.lisp - copied unchanged from r5, async-fd.lisp trunk/src/async-socket.lisp - copied unchanged from r5, async-socket.lisp trunk/src/epoll-cffi.lisp - copied unchanged from r5, epoll-cffi.lisp trunk/src/epoll.lisp - copied unchanged from r5, epoll.lisp trunk/src/event-notification.lisp - copied unchanged from r5, event-notification.lisp trunk/src/kqueue-cffi.lisp - copied unchanged from r5, kqueue-cffi.lisp trunk/src/kqueue.lisp - copied unchanged from r5, kqueue.lisp trunk/src/load.lisp - copied unchanged from r5, load.lisp trunk/src/logo120x80.png - copied unchanged from r5, logo120x80.png trunk/src/nio-httpd-default-site.lisp - copied unchanged from r5, nio-httpd-default-site.lisp trunk/src/nio-httpd.lisp - copied unchanged from r5, nio-httpd.lisp trunk/src/nio-server.lisp - copied unchanged from r5, nio-server.lisp trunk/src/nio.lisp - copied unchanged from r5, nio.lisp Removed: async-fd.lisp async-socket.lisp epoll-cffi.lisp epoll.lisp event-notification.asd event-notification.lisp kqueue-cffi.lisp kqueue.lisp load.lisp logo120x80.png nio-httpd-default-site.lisp nio-httpd.asd nio-httpd.lisp nio-server.lisp nio.asd nio.lisp Log: Moved to standard directory structure Copied: trunk/event-notification.asd (from r5, event-notification.asd) ============================================================================== --- event-notification.asd (original) +++ trunk/event-notification.asd Mon Oct 9 22:52:10 2006 @@ -4,11 +4,11 @@ (defsystem :event-notification - :components ((:file "event-notification") - (:file "kqueue-cffi" :depends-on ("event-notification")) - (:file "epoll-cffi" :depends-on ("event-notification")) - (:file "kqueue" :depends-on ("event-notification" "kqueue-cffi")) - (:file "epoll" :depends-on ("event-notification" "epoll-cffi"))) + :components ((:file "src/event-notification") + (:file "src/kqueue-cffi" :depends-on ("src/event-notification")) + (:file "src/epoll-cffi" :depends-on ("src/event-notification")) + (:file "src/kqueue" :depends-on ("src/event-notification" "src/kqueue-cffi")) + (:file "src/epoll" :depends-on ("src/event-notification" "src/epoll-cffi"))) :depends-on (:cffi)) Copied: trunk/nio-httpd.asd (from r5, nio-httpd.asd) ============================================================================== --- nio-httpd.asd (original) +++ trunk/nio-httpd.asd Mon Oct 9 22:52:10 2006 @@ -1,6 +1,6 @@ (defsystem :nio-httpd - :components ((:file "nio-server") - (:file "nio-httpd" :depends-on ("nio-server")) - (:file "nio-httpd-default-site" :depends-on ("nio-httpd"))) + :components ((:file "src/nio-server") + (:file "src/nio-httpd" :depends-on ("src/nio-server")) + (:file "src/nio-httpd-default-site" :depends-on ("src/nio-httpd"))) :depends-on (:nio)) Copied: trunk/nio.asd (from r5, nio.asd) ============================================================================== --- nio.asd (original) +++ trunk/nio.asd Mon Oct 9 22:52:10 2006 @@ -4,9 +4,9 @@ (defsystem :nio - :components ((:file "nio") - (:file "async-fd" :depends-on ("nio")) - (:file "async-socket" :depends-on ("async-fd")) + :components ((:file "src/nio") + (:file "src/async-fd" :depends-on ("src/nio")) + (:file "src/async-socket" :depends-on ("src/async-fd")) ) :depends-on (:cffi :event-notification)) From psmith at common-lisp.net Tue Oct 10 03:00:31 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Mon, 9 Oct 2006 23:00:31 -0400 (EDT) Subject: [nio-cvs] r7 - branches/home Message-ID: <20061010030031.17F923901E@common-lisp.net> Author: psmith Date: Mon Oct 9 23:00:30 2006 New Revision: 7 Added: branches/home/ Log: Create branches/home for user branches From psmith at common-lisp.net Tue Oct 10 03:00:56 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Mon, 9 Oct 2006 23:00:56 -0400 (EDT) Subject: [nio-cvs] r8 - branches/home/psmith Message-ID: <20061010030056.218D53901E@common-lisp.net> Author: psmith Date: Mon Oct 9 23:00:53 2006 New Revision: 8 Added: branches/home/psmith/ Log: Create my home for branches From psmith at common-lisp.net Tue Oct 10 03:06:24 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Mon, 9 Oct 2006 23:06:24 -0400 (EDT) Subject: [nio-cvs] r9 - branches/home/psmith/stress-mods Message-ID: <20061010030624.474603A016@common-lisp.net> Author: psmith Date: Mon Oct 9 23:06:24 2006 New Revision: 9 Added: branches/home/psmith/stress-mods/ - copied from r8, trunk/ Log: Branch to play with different modes From psmith at common-lisp.net Tue Oct 10 05:55:24 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Tue, 10 Oct 2006 01:55:24 -0400 (EDT) Subject: [nio-cvs] r10 - in branches/home/psmith/stress-mods: . src Message-ID: <20061010055524.1326C1F00F@common-lisp.net> Author: psmith Date: Tue Oct 10 01:55:24 2006 New Revision: 10 Modified: branches/home/psmith/stress-mods/event-notification.asd branches/home/psmith/stress-mods/src/async-fd.lisp branches/home/psmith/stress-mods/src/async-socket.lisp branches/home/psmith/stress-mods/src/epoll.lisp branches/home/psmith/stress-mods/src/event-notification.lisp branches/home/psmith/stress-mods/src/nio-httpd.lisp branches/home/psmith/stress-mods/src/nio-server.lisp Log: Moved to event driven SM: Server socket in level triggered mode - (TODO: why does this improve performance?) Put accepted connections fd's in nonblocking, RW notification and left as ET (as suggested in 'man epoll') Increased accept backlog to 1k (TODO: put on config) Included code review suggestions from Risto Modified: branches/home/psmith/stress-mods/event-notification.asd ============================================================================== --- branches/home/psmith/stress-mods/event-notification.asd (original) +++ branches/home/psmith/stress-mods/event-notification.asd Tue Oct 10 01:55:24 2006 @@ -8,7 +8,8 @@ (:file "src/kqueue-cffi" :depends-on ("src/event-notification")) (:file "src/epoll-cffi" :depends-on ("src/event-notification")) (:file "src/kqueue" :depends-on ("src/event-notification" "src/kqueue-cffi")) - (:file "src/epoll" :depends-on ("src/event-notification" "src/epoll-cffi"))) + (:file "src/errno") + (:file "src/epoll" :depends-on ("src/event-notification" "src/epoll-cffi" "src/errno"))) :depends-on (:cffi)) Modified: branches/home/psmith/stress-mods/src/async-fd.lisp ============================================================================== --- branches/home/psmith/stress-mods/src/async-fd.lisp (original) +++ branches/home/psmith/stress-mods/src/async-fd.lisp Tue Oct 10 01:55:24 2006 @@ -105,6 +105,7 @@ (defun close-fd (unix-fd) "Close UNIX-FD." +#+nio-debug (format t "close-fd ~A~%" unix-fd) (%close unix-fd)) @@ -145,15 +146,20 @@ (define-condition read-error (error) ()) (defun read-more (async-fd) +#+nio-debug (format t "read-more called with ~A~%" async-fd) "Read more data from ASYNC-FD." (with-slots (foreign-read-buffer foreign-read-buffer-size) async-fd (with-slots (read-fd lisp-read-buffer lisp-read-buffer-write-ptr) async-fd - +#+nio-debug (format t "read-more - calling read()~%") +#+nio-debug (force-output t) (let ((new-bytes (%read read-fd foreign-read-buffer foreign-read-buffer-size))) - +#+nio-debug (format t "read-more : Read ~A bytes~%" new-bytes) +#+nio-debug (force-output t) (cond - ((< new-bytes 0) - (error 'read-error)) + ((< new-bytes 0) + (progn + (format t "read-error - Errno: ~A~%" (sb-alien:get-errno)) + (error 'read-error))) ((= new-bytes 0) nil);;(throw 'end-of-file nil)) @@ -168,6 +174,8 @@ (mem-aref foreign-read-buffer :uint8 i))) (incf lisp-read-buffer-write-ptr new-bytes) +#+nio-debug (format t "read-more prior to callback") +#+nio-debug (force-output t) ;; call callback (with-slots (accept-filter read-callback) async-fd (if accept-filter @@ -182,8 +190,8 @@ (defun close-async-fd (async-fd) "Close ASYNC-FD's fd after everything has been written from write-queue." (with-slots (write-queue read-fd write-fd foreign-read-buffer) async-fd +#+nio-debug (format t "close-asyn-fd called with :read-fd ~A :write-fd ~A~%" read-fd write-fd) (cond - ;; if write-queue is emtpy, close now ((null write-queue) (close-fd read-fd) @@ -197,6 +205,7 @@ (defun write-more (async-fd) "Write data from ASYNC-FD's write-queue." +#+nio-debug (format t "write-more called with ~A~%" async-fd) (with-slots (write-fd write-queue) async-fd ;; loop for packets in queue @@ -234,7 +243,7 @@ (defun async-write-seq (async-fd seq &optional (start 0) (end (length seq))) "Queue from SEQ between START and END to write-queue." - +#+nio-debug (format t "async-write-seq - called ~A~%" async-fd) (assert (and (numberp start) (not (null seq)))) ;; enqueue sequence @@ -243,7 +252,8 @@ (setf write-queue (append write-queue (list entry))))) ;; start writing - (write-more async-fd)) +; (write-more async-fd) +) @@ -258,13 +268,15 @@ (defun add-async-fd (event-queue async-fd mode) (ecase mode (:read (add-fd event-queue (slot-value async-fd 'read-fd) :read)) - (:write (add-fd event-queue (slot-value async-fd 'write-fd) :write)))) + (:write (add-fd event-queue (slot-value async-fd 'write-fd) :write)) + (:read-write (add-fd event-queue (slot-value async-fd 'write-fd) :read-write)))) (defun remove-async-fd (event-queue async-fd mode) (ecase mode (:read (remove-fd event-queue (slot-value async-fd 'read-fd) :read)) - (:write (remove-fd event-queue (slot-value async-fd 'write-fd) :write)))) + (:write (remove-fd event-queue (slot-value async-fd 'write-fd) :write)) + (:read-write (remove-fd event-queue (slot-value async-fd 'write-fd) :read-write)))) (defun async-fd-read-fd (async-fd) Modified: branches/home/psmith/stress-mods/src/async-socket.lisp ============================================================================== --- branches/home/psmith/stress-mods/src/async-socket.lisp (original) +++ branches/home/psmith/stress-mods/src/async-socket.lisp Tue Oct 10 01:55:24 2006 @@ -82,8 +82,8 @@ (sockaddr :pointer) (socklen :pointer)) - -(defun start-listen (socket-fd &optional (backlog 7)) +;;TODO put backlog on config +(defun start-listen (socket-fd &optional (backlog 1000)) (%listen socket-fd backlog)) Modified: branches/home/psmith/stress-mods/src/epoll.lisp ============================================================================== --- branches/home/psmith/stress-mods/src/epoll.lisp (original) +++ branches/home/psmith/stress-mods/src/epoll.lisp Tue Oct 10 01:55:24 2006 @@ -29,23 +29,38 @@ #+linux (progn - (defun make-event-queue () - (%epoll-create 10)) + (defconstant +epoll-size+ 1000) + (defun make-event-queue () + (%epoll-create +epoll-size+)) - (defun add-fd (event-queue fd mode &key (trigger :edge)) - (with-foreign-object (ev 'epoll-event) - (memzero ev +epoll-event-size+) + (defun read-event-p (event) + (not (eql (logand event +epoll-in+) 0))) - (setf (foreign-slot-value ev 'epoll-event 'fd) fd - (foreign-slot-value ev 'epoll-event 'events) - (logior (if (eql :read mode) +epoll-in+ 0) - (if (eql :write mode) +epoll-out+ 0) - (if (eql trigger :edge) +epoll-et+))) + (defun write-event-p (event) + (not (eql (logand event +epoll-out+) 0))) - (%epoll-ctl event-queue +epoll-ctl-add+ fd ev))) + (defun add-fd (event-queue fd mode &key (trigger :edge)) + (with-foreign-object (ev 'epoll-event) + (memzero ev +epoll-event-size+) + (let ((actual-mode (logior (if (eql :read mode) +epoll-in+ 0) + (if (eql :write mode) +epoll-out+ 0) + (if (eql :read-write mode) (logior +epoll-in+ +epoll-out+) 0) + (if (eql trigger :edge) +epoll-et+ 0)))) + #+nio-debug (format t "Add-fd called with :fd ~A :event-queue ~A :mode ~A :trigger ~A :actual-mode ~A~%" fd event-queue mode trigger actual-mode) + + (setf (foreign-slot-value ev 'epoll-event 'fd) fd + (foreign-slot-value ev 'epoll-event 'events) + actual-mode)) + + (if (eql (%epoll-ctl event-queue +epoll-ctl-add+ fd ev) -1) + (progn + (format t "add-fd (epoll_ctl) error occurred: ~A~%" (get-errno)) + ;; (error 'poll-error) + )))) + (defun remove-fd (event-queue fd mode) (with-foreign-object (ev 'epoll-event) (memzero ev +epoll-event-size+) @@ -58,21 +73,26 @@ (define-condition poll-error (error) ()) (defun poll-events (event-queue) - (with-foreign-object (events 'epoll-event 10) - (memzero events (* +epoll-event-size+ 10)) - (loop for res = (%epoll-wait event-queue events 10 -1) +#+nio-debug (format t "poll-events called with :event-queue ~A~%" event-queue) + (with-foreign-object (events 'epoll-event +epoll-size+) + (memzero events (* +epoll-event-size+ +epoll-size+)) + (loop for res = (%epoll-wait event-queue events +epoll-size+ -1) + do - (case res - (-1 (error 'poll-error)) - (0 nil) - (t - (let ((idents nil)) - (loop for i from 0 below res do - (push (foreign-slot-value - (mem-aref events 'epoll-event i) - 'epoll-event 'fd) - idents)) - (return idents))))))) - - - ) + (progn +#+nio-debug (format t "poll-events - dealing with ~A~%" res) + (case res + (-1 (error 'poll-error)) + (0 nil) + (t + (let ((idents nil)) + (loop for i from 0 below res do + (push (cons (foreign-slot-value + (mem-aref events 'epoll-event i) + 'epoll-event 'fd) + (foreign-slot-value + (mem-aref events 'epoll-event i) + 'epoll-event 'events)) + idents)) + (return idents)))))))) +) Modified: branches/home/psmith/stress-mods/src/event-notification.lisp ============================================================================== --- branches/home/psmith/stress-mods/src/event-notification.lisp (original) +++ branches/home/psmith/stress-mods/src/event-notification.lisp Tue Oct 10 01:55:24 2006 @@ -26,4 +26,4 @@ |# (defpackage :event-notification (:use :cl :cffi) (:export - make-event-queue add-fd remove-fd poll-events poll-error)) \ No newline at end of file + make-event-queue add-fd remove-fd poll-events poll-error read-event-p write-event-p)) \ No newline at end of file Modified: branches/home/psmith/stress-mods/src/nio-httpd.lisp ============================================================================== --- branches/home/psmith/stress-mods/src/nio-httpd.lisp (original) +++ branches/home/psmith/stress-mods/src/nio-httpd.lisp Tue Oct 10 01:55:24 2006 @@ -94,6 +94,7 @@ (defun serve-content (client status content-type content) +#+nio-debug (format t "serve-content :client ~A~%" client) (let ((status-line (make-status-line status)) (content-type (concatenate 'vector Modified: branches/home/psmith/stress-mods/src/nio-server.lisp ============================================================================== --- branches/home/psmith/stress-mods/src/nio-server.lisp (original) +++ branches/home/psmith/stress-mods/src/nio-server.lisp Tue Oct 10 01:55:24 2006 @@ -59,7 +59,8 @@ (format t "~&Starting server on ~S port ~S.. (socket fd is ~D)~%" host port sock) (start-listen sock) - (add-fd event-queue sock :read) + + (add-fd event-queue sock :read :trigger :level) (format t "waiting for events..~%") (force-output) @@ -69,38 +70,39 @@ (format t "Poll-error, exiting..~%") (throw 'poll-error-exit nil)))) - (loop for unix-fds = (poll-events event-queue) do + (loop for unix-epoll-events = (poll-events event-queue) do - (loop for fd in unix-fds do - + (loop for (fd . event) in unix-epoll-events do (cond ;; new connection ((= fd sock) (let ((async-fd (socket-accept fd))) - +#+nio-debug (format t "start-server - New conn: ~A~%" async-fd) (cond ((null async-fd) (format t "Accept failed.~%")) ;; accept connection ? - ((funcall accept-connection async-fd) + ((set-fd-nonblocking (async-fd-read-fd async-fd)) + (funcall accept-connection async-fd) (setf (gethash (async-fd-read-fd async-fd) client-hash) async-fd) (set-accept-filter async-fd accept-filter) (set-read-callback async-fd connection-handler) - (add-async-fd event-queue async-fd :read) - (add-async-fd event-queue async-fd :write) + (add-async-fd event-queue async-fd :read-write) +; (add-async-fd event-queue async-fd :write) ) ;; no accept, close (t + (format t "start-server - accept-connection closed~%") (close-async-fd async-fd))))) ;; socket i/o available (t (let ((async-fd (gethash fd client-hash))) - +#+nio-debug (format t "IO event ~A on ~A~%" event async-fd) (unless (null async-fd) (catch 'error-exit (handler-bind ((read-error #'(lambda (x) @@ -112,9 +114,9 @@ (force-close-async-fd async-fd) (throw 'error-exit nil)))) - (read-more async-fd)))) + (when (read-event-p event) (read-more async-fd)) + (when (write-event-p event) (write-more async-fd))))) )) - ))))) - + ))))) (ignore-errors (close-fd sock)))) From psmith at common-lisp.net Sun Oct 29 00:49:00 2006 From: psmith at common-lisp.net (psmith at common-lisp.net) Date: Sat, 28 Oct 2006 20:49:00 -0400 (EDT) Subject: [nio-cvs] r11 - branches/home/psmith/stress-mods/src Message-ID: <20061029004900.297275903D@common-lisp.net> Author: psmith Date: Sat Oct 28 20:48:59 2006 New Revision: 11 Added: branches/home/psmith/stress-mods/src/errno.lisp Log: Stress-mods branch: Commited missing file for errno on sbcl Added: branches/home/psmith/stress-mods/src/errno.lisp ============================================================================== --- (empty file) +++ branches/home/psmith/stress-mods/src/errno.lisp Sat Oct 28 20:48:59 2006 @@ -0,0 +1,34 @@ +#| +Copyright (c) 2006 Risto Laakso +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +|# +(in-package :event-notification) + +(declaim (optimize (debug 3) (speed 3) (space 0))) + +(defun get-errno () + #+sbcl (sb-alien:get-errno) + #-sbcl 0) +