aboutsummaryrefslogtreecommitdiff
path: root/workerpool.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-11 16:39:59 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-11-11 16:39:59 +0200
commita4e8e226fff071c4cc6c538617c62335dca18aaf (patch)
tree5eb4bfb840e1bbb68deceafe59845d06ac83adde /workerpool.go
parentAccept net.Conn instead of io.ReadWriteCloser in Serve*() methods, since in r... (diff)
downloadfasthttp-a4e8e226fff071c4cc6c538617c62335dca18aaf.tar.gz
fasthttp-a4e8e226fff071c4cc6c538617c62335dca18aaf.tar.bz2
fasthttp-a4e8e226fff071c4cc6c538617c62335dca18aaf.zip
Removed dubious loop for obtaining free worker - just increase the number of workers if 'no free workers' error occur
Diffstat (limited to 'workerpool.go')
-rw-r--r--workerpool.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/workerpool.go b/workerpool.go
index c472c58..89961f8 100644
--- a/workerpool.go
+++ b/workerpool.go
@@ -11,7 +11,7 @@ import (
// in FIFO order, i.e. the most recently stopped worker will serve the next
// incoming connection.
type workerPool struct {
- // Function for serving incoming connections.
+ // Function for serving server connections.
// It must close c before returning.
WorkerFunc func(c net.Conn) error
@@ -88,7 +88,16 @@ func (wp *workerPool) clean() {
wp.lock.Unlock()
}
-func (wp *workerPool) TryServe(c net.Conn) bool {
+func (wp *workerPool) Serve(c net.Conn) bool {
+ ch := wp.getCh()
+ if ch == nil {
+ return false
+ }
+ ch.ch <- c
+ return true
+}
+
+func (wp *workerPool) getCh() *workerChan {
var ch *workerChan
createWorker := false
@@ -108,7 +117,7 @@ func (wp *workerPool) TryServe(c net.Conn) bool {
if ch == nil {
if !createWorker {
- return false
+ return nil
}
vch := workerChanPool.Get()
if vch == nil {
@@ -122,8 +131,7 @@ func (wp *workerPool) TryServe(c net.Conn) bool {
workerChanPool.Put(vch)
}()
}
- ch.ch <- c
- return true
+ return ch
}
func (wp *workerPool) release(ch *workerChan) bool {