Author: ehuelsmann Date: Wed Feb 28 14:26:08 2007 New Revision: 201
Modified: usocket/trunk/package.lisp usocket/trunk/usocket.lisp Log: Implement 2 helper macros from an idea by Harold Lee (harold at hotelling dot net) [my implementation.
Modified: usocket/trunk/package.lisp ============================================================================== --- usocket/trunk/package.lisp (original) +++ usocket/trunk/package.lisp Wed Feb 28 14:26:08 2007 @@ -21,8 +21,10 @@ #:get-local-name #:get-peer-name
- #:with-connected-socket ; macros + #:with-connected-socket ; convenience macros #:with-server-socket + #:with-client-socket + #:with-socket-listener
#:usocket ; socket object and accessors #:stream-usocket
Modified: usocket/trunk/usocket.lisp ============================================================================== --- usocket/trunk/usocket.lisp (original) +++ usocket/trunk/usocket.lisp Wed Feb 28 14:26:08 2007 @@ -117,6 +117,17 @@ (when ,var (socket-close ,var)))))
+(defmacro with-client-socket ((socket-var stream-var &rest socket-connect-args) + &body body) + "Bind the socket resulting from a call to `socket-connect' with +the arguments `socket-connect-args' to `socket-var' and if `stream-var' is +non-nil, bind the associated socket stream to it." + `(with-connected-socket (,socket-var (socket-connect ,@socket-connect-args)) + ,(if (null stream-var) + `(progn ,@body) + `(let ((,stream-var (socket-stream ,socket-var))) + ,@body)))) + (defmacro with-server-socket ((var server-socket) &body body) "Bind `server-socket' to `var', ensuring socket destruction on exit.
@@ -126,6 +137,14 @@ `(with-connected-socket (var server-socket) ,@body))
+(defmacro with-socket-listener ((socket-var &rest socket-listen-args) + &body body) + "Bind the socket resulting from a call to `socket-listen' with arguments +`socket-listen-args' to `socket-var'." + `(with-server-socket (,socket-var (socket-listen ,@socket-listen-args)) + ,@body)) + + ;; ;; IP(v4) utility functions ;;