Author: psmith Date: Tue Feb 6 20:48:24 2007 New Revision: 76
Modified: branches/home/psmith/restructure/run-http.lisp branches/home/psmith/restructure/src/event/epoll.lisp branches/home/psmith/restructure/src/io/nio-server.lisp branches/home/psmith/restructure/src/nio-logger/nio-logger.lisp Log: Thread safe connect; tidy up
Modified: branches/home/psmith/restructure/run-http.lisp ============================================================================== --- branches/home/psmith/restructure/run-http.lisp (original) +++ branches/home/psmith/restructure/run-http.lisp Tue Feb 6 20:48:24 2007 @@ -1,4 +1,4 @@ (push :nio-debug *features*) (require :asdf) (require :nio-http) -(nio:start-server 'identity 'identity 'nio-http:http-state-machine :host "127.0.0.1") +(nio:start-server 'nio-http:http-state-machine :host "127.0.0.1")
Modified: branches/home/psmith/restructure/src/event/epoll.lisp ============================================================================== --- branches/home/psmith/restructure/src/event/epoll.lisp (original) +++ branches/home/psmith/restructure/src/event/epoll.lisp Tue Feb 6 20:48:24 2007 @@ -73,14 +73,14 @@ (define-condition poll-error (error) ())
(defun poll-events (event-queue) -#+nio-debug (format t "poll-events called with :event-queue ~A~%" event-queue) +#+nio-debug2 (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+ 100) do (progn -#+nio-debug (format t "poll-events - dealing with ~A~%" res) +#+nio-debug2 (format t "poll-events - dealing with ~A~%" res) (case res (-1 (let ((errno (get-errno)))
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 Tue Feb 6 20:48:24 2007 @@ -34,7 +34,7 @@ t)
;TODO thread safety -(defparameter +connected-sockets+ nil +(defparameter +connected-sockets-queue+ (nio-compat:concurrent-queue) "List of sockets that have been connected and are awaiting addition to the event-notification system")
;loop over hashtable @@ -59,13 +59,13 @@ (push async-fd removals))) client-hash) (dolist (async-fd removals) - (remhash (async-fd-read-fd async-fd) client-hash)) - (format t "client-hash list ~A~%"client-hash ))) + (remhash (async-fd-read-fd async-fd) client-hash)))) +; (format t "client-hash list ~A~%"client-hash )
-(defun start-server (connection-handler accept-filter connection-type +(defun start-server (connection-type &key (protocol :inet) (port (+ (random 60000) 1024)) @@ -153,14 +153,12 @@ (when (write-event-p event) (setf (write-ready async-fd) t)))))))))
;add outgoing sockets to event queue - (format-log t "nio-server:start-server - Processing client add ~A~%" +connected-sockets+) - (loop for new-fd in +connected-sockets+ do +#+nio-debug2 (format-log t "nio-server:start-server - Processing client add ~A~%" +connected-sockets-queue+) + + (loop for new-fd = (nio-compat:take +connected-sockets-queue+ :blocking-call nil) until (null new-fd) do (format-log t "nio-server:start-server - Dealing with ~A~%" new-fd) (setf (gethash (async-fd-read-fd new-fd) client-hash) new-fd) (add-async-fd event-queue new-fd :read-write)) - - ;TODO thread safety - (setf +connected-sockets+ nil) ;loop over async-fd's processing where necessary (process-async-fds client-hash) @@ -181,8 +179,8 @@
(if (connect-inet-socket sock host port) (let ((sm (create-state-machine connection-type sock sock sock))) - (push sm +connected-sockets+) - (format-log t "nio-server:add-connection - Socket enqueued: ~A~%" +connected-sockets+) + (nio-compat:add +connected-sockets-queue+ sm) + (format-log t "nio-server:add-connection - Socket enqueued: ~A~%" +connected-sockets-queue+) (return-from add-connection sm)) (format t "Connect failed!!~A ~%" (get-errno)))))
\ No newline at end of file
Modified: branches/home/psmith/restructure/src/nio-logger/nio-logger.lisp ============================================================================== --- branches/home/psmith/restructure/src/nio-logger/nio-logger.lisp (original) +++ branches/home/psmith/restructure/src/nio-logger/nio-logger.lisp Tue Feb 6 20:48:24 2007 @@ -45,8 +45,7 @@ ;;e.g. (tail-log "/var/log/httpd/access_log" "192.168.1.1") (defun tail-log(filename ip-address) ;;shouldn't be listenting on the client hence nil for accept SM to start-server - (sb-thread:make-thread #'(lambda()(nio:start-server 'identity 'identity nil :host "127.0.0.1" :port 9897)) :name "nio-server") - (sleep 4) + (sb-thread:make-thread #'(lambda()(nio:start-server nil)) :name "nio-server") (let ((sm (nio:add-connection ip-address 16323 'nio-yarpc:yarpc-client-state-machine))) (nio-utils:format-log t "toplevel adding conn ~A to ~A~%" sm ip-address) (with-line-from-tailed-file (text filename 1) @@ -62,7 +61,7 @@ (setf nio-yarpc:+process-jobs-inline+ nil) (setf +log-file-name+ out-file) (nio:load-ips allowed-ips) - (sb-thread:make-thread #'(lambda()(nio:start-server 'identity 'identity 'nio-yarpc:yarpc-state-machine :host listen-ip :accept-connection 'nio:check-ip)) :name "nio-server") + (sb-thread:make-thread #'(lambda()(nio:start-server 'nio-yarpc:yarpc-state-machine :host listen-ip :accept-connection 'nio:check-ip)) :name "nio-server") (loop ;;block waiting for jobs (nio-yarpc:run-job)))