Ignore:
Timestamp:
02/07/07 04:55:55 (18 years ago)
Author:
psmith
Message:

nio-server Only listen if necessary

Location:
branches/home/psmith/restructure/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/home/psmith/restructure/src/io/nio-server.lisp

    r76 r77  
    6666                             
    6767
    68 (defun start-server (connection-type 
     68(defun start-server (connection-type
    6969                     &key
    70                      (protocol :inet) 
    71                      (port (+ (random 60000) 1024)) 
    72                      (host "localhost")
     70                     (protocol :inet)
     71                     (port (+ (random 60000) 1024))
     72                     (host "127.0.0.1")
    7373                     (accept-connection #'trivial-accept))
    74                      
    75 
    7674  (let (sock
    7775        (event-queue (make-event-queue))
     
    7977        )
    8078
    81     (setq sock (ecase protocol
    82                  (:inet (make-inet-socket))
    83                  (:inet6 (make-inet6-socket))))
    84 
    85     (unless (ecase protocol
    86               (:inet (bind-inet-socket sock port host))
    87               (:inet6 (bind-inet6-socket sock port host)))
    88       (error "Can't bind socket!"))
    89 
    90     (set-fd-nonblocking sock)
    91 
    92     (format t "~&Starting server on ~S port ~S.. (socket fd is ~D)~%" host port sock)
    93 
    94     (start-listen sock)
    95 
    96     (add-fd event-queue sock :read :trigger :level)
     79    (when (not (null connection-type))
     80      (format t "Binding to ~A:~A~%" host port)
     81      (setq sock (ecase protocol
     82                   (:inet (make-inet-socket))
     83                   (:inet6 (make-inet6-socket))))
     84      (unless (ecase protocol
     85                (:inet (bind-inet-socket sock port host))
     86                (:inet6 (bind-inet6-socket sock port host)))
     87        (error "Can't bind socket!"))
     88      (set-fd-nonblocking sock)
     89      (format t "~&Starting server on ~S port ~S.. (socket fd is ~D)~%" host port sock)     
     90      (start-listen sock)
     91      (add-fd event-queue sock :read :trigger :level))
    9792           
    9893    (format t "waiting for events..~%") (force-output)
     
    109104                  (cond
    110105                    ;; new connection
    111                     ((= fd sock)
    112                      (let ((async-fd (socket-accept fd connection-type)))
     106                    ((and sock (= fd sock))
     107                     (progn
     108#+nio-debug                    (format t "start-server - incomming conn")
     109                       (let ((async-fd (socket-accept fd connection-type)))
    113110#+nio-debug                    (format t "start-server - New conn: ~A~%" async-fd)
    114111                       (cond
     
    132129                         (t
    133130                          (format-log t "start-server - accept-connection closed~%")
    134                           (close-async-fd async-fd)))))
     131                          (close-async-fd async-fd))))))
    135132
    136133
     
    169166
    170167(defun add-connection (host port connection-type
    171                    &key
    172                    (protocol :inet)
    173                    
    174                    )
     168                       &key
     169                       (protocol :inet))
     170  (format-log t "nio-server:add-connection - Called with: ~A:~A:~A ~%" protocol host port)
    175171  (let ((sock nil))
    176172    (setq sock (ecase protocol
  • TabularUnified branches/home/psmith/restructure/src/nio-logger/nio-logger.lisp

    r76 r77  
    4545;;e.g. (tail-log "/var/log/httpd/access_log" "192.168.1.1")
    4646(defun tail-log(filename ip-address)
    47   ;;shouldn't be listenting on the client hence nil for accept SM to start-server
    48   (sb-thread:make-thread #'(lambda()(nio:start-server nil)) :name "nio-server")
     47  (sleep 4)
    4948  (let ((sm (nio:add-connection ip-address 16323 'nio-yarpc:yarpc-client-state-machine)))
    5049    (nio-utils:format-log t "toplevel adding conn ~A to ~A~%" sm ip-address)
  • TabularUnified branches/home/psmith/restructure/src/nio-logger/run-logging-client.lisp

    r71 r77  
    3434      (ip (third sb-ext:*posix-argv*)))
    3535  (format t "Starting logging client with ~A ~A~%" log-file ip)
    36   (nio-logger:tail-log log-file ip))
     36  (sb-thread:make-thread #'(lambda()(nio-logger:tail-log log-file ip)) :name "nio-server")
     37
     38  ;;shouldn't be listenting on the client hence nil for accept SM to start-server
     39  (nio:start-server nil))
Note: See TracChangeset for help on using the changeset viewer.