Skip to content

Commit

Permalink
Add clack-socket to abstract :clack.io sockets in handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Aug 10, 2015
1 parent e3700e2 commit 89427b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions clack-handler-wookie.asd
Expand Up @@ -22,6 +22,7 @@
:author "Eitaro Fukamachi"
:license "LLGPL"
:depends-on (:wookie
:clack-socket
:cl-async
:fast-http
:quri
Expand Down
10 changes: 10 additions & 0 deletions clack-socket.asd
@@ -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")))
15 changes: 14 additions & 1 deletion src/handler/wookie.lisp
Expand Up @@ -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
Expand Down Expand Up @@ -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)))))
10 changes: 10 additions & 0 deletions src/socket.lisp
@@ -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.