diff --git a/cffi-socket.lisp b/cffi-socket.lisp
index 0938742..a9cfe4d 100644
--- a/cffi-socket.lisp
+++ b/cffi-socket.lisp
@@ -59,27 +59,27 @@
(sin-port in-port-t)
(sin-addr uint32-t)
(sin-zero :unsigned-char :count #.(- (foreign-type-size '(:struct sockaddr))
- (foreign-type-size 'sa-family-t)
- (foreign-type-size 'in-port-t)
- (foreign-type-size 'uint32-t))))
+ (foreign-type-size 'sa-family-t)
+ (foreign-type-size 'in-port-t)
+ (foreign-type-size 'uint32-t))))
(defun inet-addr-from-string (x &key (start 0) (end (length x)))
(ignore-errors
(let ((addr 0))
(flet ((eat-byte ()
- (let ((b 0))
- (loop while (< start end)
- for c = (char x start)
- while (char<= #\0 c #\9)
- do (setf b (+ (* 10 b) (- (char-code c) (char-code #\0))))
- do (incf start))
- (setf addr (logior (ash addr 8) b)))))
- (dotimes (_ 3)
- (eat-byte)
- (assert (char= #\. (char x start)))
- (incf start))
- (eat-byte)
- (assert (= end start)))
+ (let ((b 0))
+ (loop while (< start end)
+ for c = (char x start)
+ while (char<= #\0 c #\9)
+ do (setf b (+ (* 10 b) (- (char-code c) (char-code #\0))))
+ do (incf start))
+ (setf addr (logior (ash addr 8) b)))))
+ (dotimes (_ 3)
+ (eat-byte)
+ (assert (char= #\. (char x start)))
+ (incf start))
+ (eat-byte)
+ (assert (= end start)))
addr)))
(defun inet-addr (x)
@@ -91,15 +91,15 @@
(defun bind-inet (sockfd addr port)
(with-foreign-object (addr-in '(:struct sockaddr))
(with-foreign-slots ((sin-family sin-port sin-addr)
- addr-in (:struct sockaddr-in))
+ addr-in (:struct sockaddr-in))
(let ((inet-addr (inet-addr addr)))
- (setf sin-family +af-inet+
- sin-port (htons port)
- sin-addr inet-addr)))
+ (setf sin-family +af-inet+
+ sin-port (htons port)
+ sin-addr inet-addr)))
(let ((r (c-bind sockfd addr-in (foreign-type-size
- '(:struct sockaddr-in)))))
+ '(:struct sockaddr-in)))))
(when (< r 0)
- (error-errno "bind"))
+ (error-errno "bind"))
r)))
(defcfun ("listen" c-listen) :int
@@ -122,23 +122,23 @@
(with-foreign-object (addrlen :int)
(setf (mem-ref addrlen :int) (foreign-type-size '(:struct sockaddr-in)))
(let ((s (c-accept sockfd addr addrlen)))
- (cond ((<= 0 s)
- (values s addr))
- ((or (= errno +eagain+)
- (= errno +ewouldblock+))
- nil)
- (t
- (error-errno "accept")))))))
+ (cond ((<= 0 s)
+ (values s addr))
+ ((or (= errno +eagain+)
+ (= errno +ewouldblock+))
+ nil)
+ (t
+ (error-errno "accept")))))))
(defmacro with-accept ((fd-var &optional (addr-var (gensym))) listening-fd
- &body body)
+ &body body)
(declare (type symbol fd-var addr-var))
`(multiple-value-bind (,fd-var ,addr-var) (accept ,listening-fd)
(declare (ignorable ,addr-var))
(when ,fd-var
(unwind-protect (progn ,@body)
(shutdown ,fd-var t t)
- (unistd:close ,fd-var)))))
+ (unistd:close ,fd-var)))))
(defcfun ("recv" c-recv) ssize-t
(sockfd :int)
@@ -151,12 +151,12 @@
(let ((len (- end start)))
(with-foreign-pointer (buf len)
(let ((r (c-recv sockfd buf len flags)))
- (dotimes (i len)
- (setf (aref buffer start) (mem-aref buf :unsigned-char i))
- (incf start))
- (when (< r 0)
- (error-errno "recv"))
- r))))
+ (dotimes (i len)
+ (setf (aref buffer start) (mem-aref buf :unsigned-char i))
+ (incf start))
+ (when (< r 0)
+ (error-errno "recv"))
+ r))))
(defun recv-sequence (sockfd buffer flags &key (start 0) (end (length buffer)))
(loop while (< start end)
@@ -175,12 +175,12 @@
(let ((len (- end start)))
(with-foreign-pointer (buf len)
(dotimes (i len)
- (setf (mem-aref buf :unsigned-char i) (aref buffer start))
- (incf start))
+ (setf (mem-aref buf :unsigned-char i) (aref buffer start))
+ (incf start))
(let ((r (c-send sockfd buf len flags)))
- (when (< r 0)
- (error-errno "send"))
- r))))
+ (when (< r 0)
+ (error-errno "send"))
+ r))))
(defun send-sequence (sockfd buffer flags &key (start 0) (end (length buffer)))
(loop while (< start end)
@@ -195,5 +195,5 @@
(defun shutdown (sockfd &optional read write)
(when (or read write)
(c-shutdown sockfd (cond ((and read write) +shut-rdwr+)
- (read +shut-rd+)
- (write +shut-wr+)))))
+ (read +shut-rd+)
+ (write +shut-wr+)))))