[nio-cvs] r77 - in branches/home/psmith/restructure/src: io nio-logger
psmith at common-lisp.net
psmith at common-lisp.net
Wed Feb 7 04:55:55 UTC 2007
Author: psmith
Date: Tue Feb 6 23:55:55 2007
New Revision: 77
Modified:
branches/home/psmith/restructure/src/io/nio-server.lisp
branches/home/psmith/restructure/src/nio-logger/nio-logger.lisp
branches/home/psmith/restructure/src/nio-logger/run-logging-client.lisp
Log:
nio-server Only listen if necessary
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 23:55:55 2007
@@ -65,35 +65,30 @@
-(defun start-server (connection-type
+(defun start-server (connection-type
&key
- (protocol :inet)
- (port (+ (random 60000) 1024))
- (host "localhost")
+ (protocol :inet)
+ (port (+ (random 60000) 1024))
+ (host "127.0.0.1")
(accept-connection #'trivial-accept))
-
-
(let (sock
(event-queue (make-event-queue))
(client-hash (make-hash-table :test 'eql))
)
- (setq sock (ecase protocol
- (:inet (make-inet-socket))
- (:inet6 (make-inet6-socket))))
-
- (unless (ecase protocol
- (:inet (bind-inet-socket sock port host))
- (:inet6 (bind-inet6-socket sock port host)))
- (error "Can't bind socket!"))
-
- (set-fd-nonblocking sock)
-
- (format t "~&Starting server on ~S port ~S.. (socket fd is ~D)~%" host port sock)
-
- (start-listen sock)
-
- (add-fd event-queue sock :read :trigger :level)
+ (when (not (null connection-type))
+ (format t "Binding to ~A:~A~%" host port)
+ (setq sock (ecase protocol
+ (:inet (make-inet-socket))
+ (:inet6 (make-inet6-socket))))
+ (unless (ecase protocol
+ (:inet (bind-inet-socket sock port host))
+ (:inet6 (bind-inet6-socket sock port host)))
+ (error "Can't bind socket!"))
+ (set-fd-nonblocking sock)
+ (format t "~&Starting server on ~S port ~S.. (socket fd is ~D)~%" host port sock)
+ (start-listen sock)
+ (add-fd event-queue sock :read :trigger :level))
(format t "waiting for events..~%") (force-output)
@@ -108,8 +103,10 @@
(loop for (fd . event) in unix-epoll-events do
(cond
;; new connection
- ((= fd sock)
- (let ((async-fd (socket-accept fd connection-type)))
+ ((and sock (= fd sock))
+ (progn
+#+nio-debug (format t "start-server - incomming conn")
+ (let ((async-fd (socket-accept fd connection-type)))
#+nio-debug (format t "start-server - New conn: ~A~%" async-fd)
(cond
((null async-fd)
@@ -131,7 +128,7 @@
;; no accept, close
(t
(format-log t "start-server - accept-connection closed~%")
- (close-async-fd async-fd)))))
+ (close-async-fd async-fd))))))
;; socket i/o available
@@ -168,10 +165,9 @@
(defun add-connection (host port connection-type
- &key
- (protocol :inet)
-
- )
+ &key
+ (protocol :inet))
+ (format-log t "nio-server:add-connection - Called with: ~A:~A:~A ~%" protocol host port)
(let ((sock nil))
(setq sock (ecase protocol
(:inet (make-inet-socket))
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 23:55:55 2007
@@ -44,8 +44,7 @@
;;Tail the given log and write to remote logger
;;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 nil)) :name "nio-server")
+ (sleep 4)
(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)
Modified: branches/home/psmith/restructure/src/nio-logger/run-logging-client.lisp
==============================================================================
--- branches/home/psmith/restructure/src/nio-logger/run-logging-client.lisp (original)
+++ branches/home/psmith/restructure/src/nio-logger/run-logging-client.lisp Tue Feb 6 23:55:55 2007
@@ -33,4 +33,7 @@
(let ((log-file (second sb-ext:*posix-argv*))
(ip (third sb-ext:*posix-argv*)))
(format t "Starting logging client with ~A ~A~%" log-file ip)
- (nio-logger:tail-log log-file ip))
+ (sb-thread:make-thread #'(lambda()(nio-logger:tail-log log-file ip)) :name "nio-server")
+
+ ;;shouldn't be listenting on the client hence nil for accept SM to start-server
+ (nio:start-server nil))
More information about the Nio-cvs
mailing list