Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multithread write #81

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ addons:

install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install libev; fi
- curl -L https://raw.githubusercontent.com/snmsts/roswell/$ROSWELL_BRANCH/scripts/install-for-ci.sh | sh
- curl -L https://raw.githubusercontent.com/roswell/roswell/$ROSWELL_BRANCH/scripts/install-for-ci.sh | sh
# for thread-support on OS X
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ros install sbcl; fi

Expand Down
9 changes: 2 additions & 7 deletions clack-handler-woo.asd
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
(in-package :cl-user)
(defpackage clack-handler-woo-asd
(:use :cl :asdf))
(in-package :clack-handler-woo-asd)

(defsystem clack-handler-woo
:depends-on (:woo))
(defsystem "clack-handler-woo"
:depends-on ("woo"))
23 changes: 15 additions & 8 deletions src/ev/socket.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
:with-pointer-to-vector-data
:incf-pointer
:foreign-free)
(:import-from :alexandria
:once-only)
(:export :socket
:make-socket
:socket-read-watcher
Expand Down Expand Up @@ -79,7 +81,8 @@
(buffer (make-output-buffer))
(sendfile-fd nil :type (or null fixnum))
(sendfile-size nil :type (or null integer))
(sendfile-offset 0 :type (or null integer)))
(sendfile-offset 0 :type (or null integer))
(thread (bt:current-thread)))

(defun buffer-empty-p (socket)
(declare (optimize (speed 3) (safety 0) (debug 0)))
Expand Down Expand Up @@ -292,13 +295,17 @@
(async-write socket)))

(defmacro with-async-writing ((socket &key write-cb force-streaming) &body body)
`(progn
,@body
(setf (socket-write-cb ,socket) ,write-cb)
,(if force-streaming
`(unless (async-write ,socket)
(lev:ev-io-start *evloop* (socket-write-watcher ,socket)))
`(lev:ev-io-start *evloop* (socket-write-watcher ,socket)))))
(once-only (socket)
`(progn
,@body
(setf (socket-write-cb ,socket) ,write-cb)
(bt:interrupt-thread
(socket-thread ,socket)
(lambda ()
,(if force-streaming
`(unless (async-write ,socket)
(lev:ev-io-start *evloop* (socket-write-watcher ,socket)))
`(lev:ev-io-start *evloop* (socket-write-watcher ,socket))))))))

(defun send-static-file (socket fd size)
(with-slots (sendfile-fd sendfile-size sendfile-offset) socket
Expand Down
16 changes: 5 additions & 11 deletions woo-test.asd
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
(in-package :cl-user)
(defpackage woo-test-asd
(:use :cl :asdf))
(in-package :woo-test-asd)

(defsystem woo-test
:defsystem-depends-on (:prove-asdf)
:depends-on (:woo
:clack-test)
(defsystem "woo-test"
:defsystem-depends-on ("prove-asdf")
:depends-on ("woo"
"clack-test")
:components
((:test-file "t/woo")
(:test-file "t/ipv6"))
:perform (test-op :after (op c)
(funcall (intern #.(string :run-test-system) :prove) c)))
:perform (test-op (op c) (symbol-call :prove-asdf :run-test-system c)))