Changeset 85 for branches/home/psmith/restructure/src/io
- Timestamp:
- 02/11/07 23:53:09 (18 years ago)
- Location:
- branches/home/psmith/restructure/src/io
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/home/psmith/restructure/src/io/async-fd.lisp ¶
r84 r85 46 46 (close-pending :initform nil 47 47 :accessor close-pending) 48 ;TODO this is either an inet-socket if we are client side or a node is we are server side... 48 49 (socket :initarg :socket 49 :accessor socket))) 50 :accessor socket 51 :documentation "The remote node we are talking to"))) 50 52 51 53 52 54 (defmethod print-object ((async-fd async-fd) stream) 53 (with-slots ( socketread-fd write-fd) async-fd54 (format stream "#<ASYNC-FD : socket ~D :read-fd ~D :write-fd ~D.>"55 socketread-fd write-fd)))55 (with-slots (read-fd write-fd) async-fd 56 (format stream "#<ASYNC-FD :read-fd ~D :write-fd ~D.>" 57 read-fd write-fd))) 56 58 57 59 ;;Implement this in concrete SM for read … … 121 123 122 124 (define-condition read-error (error) ()) 125 (define-condition write-error (error) 126 ((error-number :initarg :error))) 123 127 124 128 (defun write-more (async-fd) … … 145 149 (perror) 146 150 (let ((err-cond (make-instance 'write-error :error err))) 147 (close err-cond)151 (close-fd (write-fd async-fd)) 148 152 (error err-cond)))) 149 153 ;;update buffers … … 158 162 159 163 (defconstant +MAX-BUFFER-SIZE-BYTES+ (* 1024 1024)) 160 161 162 163 ;(let ((buffer (foreign-read-buffer async-fd)))164 ; (if (>= (length buffer) size)165 ; t166 ; (let ((new-buffer (byte-buffer size)))167 ; (copy-buffer buffer new-buffer)168 ; (free-buffer buffer)169 ; (setf (foreign-read-buffer async-fd) new-buffer)))))170 171 164 172 165 (defmacro realloc-buffer(async-fd accessor size) -
TabularUnified branches/home/psmith/restructure/src/io/async-socket.lisp ¶
r50 r85 133 133 nil))) 134 134 135 (defun connect-inet-socket (socket-fd addr port) 135 (defun connect-inet-socket (socket-fd node) 136 (format-log t "async-socket:connect-inet-socket ccalled with ~A, and ~A~%" socket-fd node) 136 137 (with-foreign-object (sa 'sockaddr-in) 137 (init-inet-socket sa port addr) 138 138 (init-inet-socket sa (remote-port node) (remote-host node)) 139 139 (let ((res (%connect socket-fd sa +sockaddr-in-len+))) 140 140 (format-log t "async-socket:connect-inet-socket library connect call returned ~A, and errno ~A~%" res (get-errno)) … … 171 171 172 172 ;;;; SOCKET I/O 173 174 (defclass async-socket-fd ()175 ((family :initform :unknown :initarg :family)176 (remote-host :initform nil :initarg :remote-host)177 (remote-port :initform nil :initarg :remote-port)))178 179 180 173 181 174 (defun socket-accept (socket-fd connection-type) … … 201 194 202 195 ;; accept connection 196 #+nio-debug (format-log t "async-socket::socket-accept - calling %accept~%") 203 197 (let* ((res (%accept socket-fd addr len)) 204 ;; (async-socket-fd (make-instance 'async-socket-fd :read-fd res :write-fd res))) 205 (async-socket-fd (create-state-machine connection-type res res (make-instance 'async-socket-fd)))) 198 (async-fd (create-state-machine connection-type res res (node nil nil)))) 199 200 #+nio-debug (format-log t "async-socket::socket-accept - create async-fd ~A~%" async-fd) 206 201 207 202 (unless (< res 0) … … 210 205 ;; parse sockaddr struct for remote client info 211 206 212 (with-slots (family remote-host remote-port) (socket async- socket-fd)207 (with-slots (family remote-host remote-port) (socket async-fd) 213 208 214 209 (cond … … 225 220 226 221 (foreign-free len) 227 (if (>= res 0) async- socket-fd nil)222 (if (>= res 0) async-fd nil) 228 223 ))))))) 229 230 231 (defun remote-info (async-socket-fd)232 "Return FAMILY, REMOTE-HOST and REMOTE-PORT in list."233 (with-slots (family remote-host remote-port) async-socket-fd234 (list family remote-host remote-port)))235 -
TabularUnified branches/home/psmith/restructure/src/io/nio-server.lisp ¶
r84 r85 42 42 (let ((removals nil)) 43 43 (maphash #'(lambda (k async-fd) 44 #+nio-debug 2(format-log t "Dealing with ~a => ~a~%" k async-fd)44 #+nio-debug (format-log t "Dealing with ~a => ~a~%" k async-fd) 45 45 46 46 ;process reads … … 50 50 51 51 ;process-writes 52 (process-write async-fd) 53 (when (and (write-ready async-fd) 54 (> (buffer-position (foreign-write-buffer async-fd)) 0)) 55 (write-more async-fd)) 56 57 (when (close-pending async-fd) 58 (write-more async-fd) 59 (push async-fd removals))) 52 (handler-case 53 (progn 54 (process-write async-fd) 55 (when (and (write-ready async-fd) 56 (> (buffer-position (foreign-write-buffer async-fd)) 0)) 57 (write-more async-fd)) 58 59 (when (close-pending async-fd) 60 (write-more async-fd) 61 (push async-fd removals))) 62 (write-error (we) (push async-fd removals)))) 60 63 client-hash) 61 64 (dolist (async-fd removals) 65 (format-log t "nio-server:process-async-fds processing remove for ~a~%" async-fd) 66 (setf (active-conn (socket async-fd)) nil) 62 67 (remhash (async-fd-read-fd async-fd) client-hash)))) 63 ; (format t "client-hash list ~A~%"client-hash )64 65 66 68 67 69 … … 122 124 (perror))) 123 125 (setf (gethash (async-fd-read-fd async-fd) client-hash) async-fd) 124 (add-async-fd event-queue async-fd :read-write) 125 ; (add-async-fd event-queue async-fd :write) 126 ) 126 (add-async-fd event-queue async-fd :read-write)) 127 127 128 128 ;; no accept, close … … 150 150 (when (write-event-p event) (setf (write-ready async-fd) t))))))))) 151 151 152 152 ;add outgoing sockets to event queue 153 153 #+nio-debug2 (format-log t "nio-server:start-server - Processing new connections queue ~A~%" +connected-sockets-queue+) 154 154 (loop for node = (nio-compat:take +connected-sockets-queue+ :blocking-call nil) until (null node) do 155 155 #+nio-debug (format-log t "nio-server:start-server - adding node to nodes-list ~A~%" node) 156 156 (push node *nodes-list*)) 157 157 158 (with-connect-ready-nodes (a-node) 158 159 #+nio-debug (format-log t "nio-server:start-server - attempting connection to node ~A~%" a-node) 159 (let ((new-fd (connect (host a-node) (port a-node) connection-type))) 160 (let ((new-fd (connect a-node connection-type))) 161 #+nio-debug (format-log t "nio-server:start-server - connect returned async-fd ~A~%" new-fd) 160 162 (update-last-connect-attempt a-node) 161 163 (when new-fd … … 172 174 173 175 174 (defun connect( host portconnection-type176 (defun connect(node connection-type 175 177 &key 176 178 (protocol :inet)) 177 (format-log t "nio-server:connect - Called with: ~A :~A:~A ~%" protocol host port)179 (format-log t "nio-server:connect - Called with: ~A ~A~%" protocol node) 178 180 (let ((sock nil)) 179 181 (setq sock (ecase protocol … … 181 183 (:inet6 (make-inet6-socket)))) 182 184 183 (if (connect-inet-socket sock host port) 184 (let ((sm (create-state-machine connection-type sock sock sock))) 185 ; (nio-compat:add +connected-sockets-queue+ sm) 186 ; (format-log t "nio-server:connect - Socket enqueued: ~A~%" +connected-sockets-queue+) 185 (if (connect-inet-socket sock node) 186 (let ((sm (create-state-machine connection-type sock sock node))) 187 187 (return-from connect sm)) 188 188 (format t "Connect failed!!~A ~%" (get-errno))))) -
TabularUnified branches/home/psmith/restructure/src/io/nio.asd ¶
r81 r85 9 9 (:file "packet" :depends-on ("nio-package")) 10 10 (:file "async-fd" :depends-on ("fd-helper")) 11 (:file "async-socket" :depends-on ("async-fd"))12 11 (:file "nodes" :depends-on ("nio-package")) 12 (:file "async-socket" :depends-on ("async-fd" "nodes")) 13 13 (:file "nio-server" :depends-on ("async-socket" "nodes")) 14 14 (:file "ip-authorisation" :depends-on ("nio-package")) -
TabularUnified branches/home/psmith/restructure/src/io/nodes.lisp ¶
r81 r85 29 29 (declaim (optimize (debug 3) (speed 3) (space 0))) 30 30 31 ;;concept of a remote socket 31 32 ;;concept of a remote socket with properties e.g. stats, connection attempts etc 32 33 (defclass node() 33 ((host :initarg :host 34 :reader host) 35 (port :initarg :port 36 :reader port) 34 ((family :initform :unknown :initarg :family) 35 (remote-host :initarg :remote-host 36 :initform nil 37 :accessor remote-host) 38 (remote-port :initarg :remote-port 39 :initform nil 40 :accessor remote-port) 37 41 (last-connect-attempt :initform nil 38 42 :accessor last-connect-attempt 39 43 :documentation "Time we last attempted a connection") 40 (retry-delay :initform 60 044 (retry-delay :initform 60 41 45 :accessor retry-delay 42 :documentation "The delay to wait after the last-connection-attempt before trying to connect again")46 :documentation "The delay to wait (in secs) after the last-connection-attempt before trying to connect again (10 mins)") 43 47 (active-conn :initform nil 44 48 :accessor active-conn … … 46 50 47 51 (defun node(host port) 48 (make-instance 'node : host host :port port))52 (make-instance 'node :remote-host host :remote-port port)) 49 53 50 54 ;(node-from-socket-repn "192.168.1.1:1234") … … 57 61 58 62 (defmethod print-object ((a-node node) stream) 59 (with-slots (host port last-connect-attempt retry-delay active-conn) a-node 60 (format stream "#<NODE :HOST ~A :port ~A :last-connect-attempt ~A :retry-delay ~A :active-conn ~A>" host port last-connect-attempt retry-delay active-conn))) 63 (with-slots (remote-host remote-port last-connect-attempt retry-delay active-conn) a-node 64 (format stream "#<NODE :remote-host ~A :remote-port ~A :last-connect-attempt ~A :retry-delay ~A :active-conn ~A>" 65 remote-host remote-port last-connect-attempt retry-delay active-conn))) 61 66 62 67
Note: See TracChangeset
for help on using the changeset viewer.