[nio-cvs] r104 - branches/home/psmith/restructure/src/io
psmith at common-lisp.net
psmith at common-lisp.net
Fri Mar 2 00:50:07 UTC 2007
Author: psmith
Date: Thu Mar 1 19:50:07 2007
New Revision: 104
Modified:
branches/home/psmith/restructure/src/io/async-socket.lisp
Log:
Improved error-handling on %socket
Modified: branches/home/psmith/restructure/src/io/async-socket.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/async-socket.lisp (original)
+++ branches/home/psmith/restructure/src/io/async-socket.lisp Thu Mar 1 19:50:07 2007
@@ -96,6 +96,11 @@
(socklent :int))
+(define-condition fd-error (error)
+ ((error-number :initarg :error)))
+
+
+
;;TODO put backlog on config
(defun start-listen (socket-fd &optional (backlog 1000))
(%listen socket-fd backlog))
@@ -104,7 +109,12 @@
;;;; IPv4
(defun make-inet-socket (&optional (type :tcp))
- (%socket +af-inet+ (ecase type (:tcp +sock-stream+) (:udp +sock-dgram+)) 0))
+ (let ((fd (%socket +af-inet+ (ecase type (:tcp +sock-stream+) (:udp +sock-dgram+)) 0)))
+ (when (eql fd -1)
+ (perror)
+#+nio-debug (format-log t "async-socket::make-inet-socket - %socket failed (errno ~A)~%" )
+ (error (make-instance 'fd-error :error (get-errno))))
+ fd))
(defun init-inet-socket(sa port addr)
@@ -133,7 +143,7 @@
nil)))
(defun connect-inet-socket (socket-fd node)
- (format-log t "async-socket:connect-inet-socket ccalled with ~A, and ~A~%" socket-fd node)
+ (format-log t "async-socket:connect-inet-socket called with ~A, and ~A~%" socket-fd node)
(with-foreign-object (sa 'sockaddr-in)
(init-inet-socket sa (remote-port node) (remote-host node))
(let ((res (%connect socket-fd sa +sockaddr-in-len+)))
@@ -221,3 +231,13 @@
(foreign-free len)
(if (>= res 0) async-fd nil)
)))))))
+
+
+
+(defun test-socket-connect(close)
+ (format t "Got fd's :")
+ (loop for i from 1 to 1025 do
+ (let ((fd (make-inet-socket)))
+ (format t "~A " fd)
+ (when (and close fd)
+ (close-fd fd)))))
\ No newline at end of file
More information about the Nio-cvs
mailing list