diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-08-30 11:50:33 -0700 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-08-30 11:50:33 -0700 |
commit | a33145d614e9ea1d0c59cf219f50e36f879aa5bb (patch) | |
tree | 17973a2f4cb4bde8b78e8ac9399bb9cddf740f20 /src/nginext/port.go | |
parent | 9537821f3f486f5176affc7d4f51328c23efd48f (diff) | |
download | unit-a33145d614e9ea1d0c59cf219f50e36f879aa5bb.tar.gz unit-a33145d614e9ea1d0c59cf219f50e36f879aa5bb.tar.bz2 |
ListenAndServe changed to be compatible with http.ListenAndServe.
Diffstat (limited to '')
-rw-r--r-- | src/nginext/port.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/nginext/port.go b/src/nginext/port.go index ee858612..768fbf84 100644 --- a/src/nginext/port.go +++ b/src/nginext/port.go @@ -14,6 +14,7 @@ import "C" import ( "fmt" "net" + "net/http" "os" "sync" "unsafe" @@ -177,11 +178,15 @@ func new_port(pid int, id int, t int, rcv int, snd int) *port { return p } -func (p *port) read() { +func (p *port) read(handler http.Handler) error { var buf [16384]byte var oob [1024]byte - n, oobn, _, _, _ := p.rcv.ReadMsgUnix(buf[:], oob[:]) + n, oobn, _, _, err := p.rcv.ReadMsgUnix(buf[:], oob[:]) + + if err != nil { + return err + } m := new_cmsg(buf[:n], oob[:oobn]) @@ -191,6 +196,16 @@ func (p *port) read() { m.Close() } else { r := find_request(c_req) + + go func(r *request) { + if handler == nil { + handler = http.DefaultServeMux + } + + handler.ServeHTTP(r.response(), &r.req) + r.done() + }(r) + if len(r.msgs) == 0 { r.push(m) } else if r.ch != nil { @@ -200,4 +215,5 @@ func (p *port) read() { } } + return err } |