Permalink
Browse files

Add clack-socket to abstract :clack.io sockets in handlers.

  • Loading branch information...
1 parent e3700e2 commit 89427b48fe0b077565b07f0d3b4ef8bfe241cd81 @fukamachi committed Aug 10, 2015
Showing with 35 additions and 1 deletion.
  1. +1 −0 clack-handler-wookie.asd
  2. +10 −0 clack-socket.asd
  3. +14 −1 src/handler/wookie.lisp
  4. +10 −0 src/socket.lisp
@@ -22,6 +22,7 @@
:author "Eitaro Fukamachi"
:license "LLGPL"
:depends-on (:wookie
+ :clack-socket
:cl-async
:fast-http
:quri
View
@@ -0,0 +1,10 @@
+(in-package :cl-user)
+(defpackage clack-socket-asd
+ (:use :cl :asdf))
+(in-package :clack-socket-asd)
+
+(defsystem clack-socket
+ :version "0.1"
+ :author "Eitaro Fukamachi"
+ :license "LLGPL"
+ :components ((:file "src/socket")))
@@ -23,7 +23,9 @@
(:import-from :cl-async
:with-event-loop
:close-tcp-server
- :async-io-stream)
+ :async-io-stream
+ :socket-data
+ :write-socket-data)
(:import-from :fast-http
:http-version)
(:import-from :quri
@@ -160,3 +162,14 @@
:status status
:headers headers
:body body))))))
+
+(defmethod clack.socket:set-read-callback (socket callback)
+ (setf (getf (as:socket-data socket) :parser) callback))
+
+(defmethod clack.socket:write-to-socket (socket message &key callback)
+ (as:write-socket-data socket message
+ :write-cb
+ (and callback
+ (lambda (socket)
+ (declare (ignore socket))
+ (funcall callback)))))
View
@@ -0,0 +1,10 @@
+(in-package :cl-user)
+(defpackage clack.socket
+ (:use :cl)
+ (:export :set-read-callback
+ :write-to-socket))
+(in-package :clack.socket)
+
+(defgeneric set-read-callback (socket callback))
+
+(defgeneric write-to-socket (socket message &key callback))

0 comments on commit 89427b4

Please sign in to comment.