diff options
author | Sergey Fedchenko <seregayoga@bk.ru> | 2017-09-08 14:10:23 -0700 |
---|---|---|
committer | Sergey Fedchenko <seregayoga@bk.ru> | 2017-09-08 14:10:23 -0700 |
commit | 22c6805949417efdf6ab6c47c498f3a30cfb6f21 (patch) | |
tree | 39e043cc3d368431004b0e42268a12b14e9bc33c /src/go/unit/port.go | |
parent | 409dcd3a7978eb205ab9ac54add002387b4cf9f0 (diff) | |
download | unit-22c6805949417efdf6ab6c47c498f3a30cfb6f21.tar.gz unit-22c6805949417efdf6ab6c47c498f3a30cfb6f21.tar.bz2 |
Cosmetic fixes in port.go.
This closes #5 on GitHub.
From 615369a29511c6021e5623070f082fdb17ff37a2
Diffstat (limited to '')
-rw-r--r-- | src/go/unit/port.go | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/src/go/unit/port.go b/src/go/unit/port.go index 74b5e8fe..6eaa86bb 100644 --- a/src/go/unit/port.go +++ b/src/go/unit/port.go @@ -134,18 +134,19 @@ func nxt_go_port_send(pid C.int, id C.int, buf unsafe.Pointer, buf_size C.int, p := find_port(key) - if p != nil { - n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size), - C.GoBytes(oob, oob_size), nil) + if p == nil { + return 0 + } - if err != nil { - fmt.Printf("write result %d (%d), %s\n", n, oobn, err) - } + n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size), + C.GoBytes(oob, oob_size), nil) - return C.int(n) + if err != nil { + fmt.Printf("write result %d (%d), %s\n", n, oobn, err) } - return 0 + return C.int(n) + } //export nxt_go_main_send @@ -154,18 +155,18 @@ func nxt_go_main_send(buf unsafe.Pointer, buf_size C.int, oob unsafe.Pointer, p := main_port() - if p != nil { - n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size), - C.GoBytes(oob, oob_size), nil) + if p == nil { + return 0 + } - if err != nil { - fmt.Printf("write result %d (%d), %s\n", n, oobn, err) - } + n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size), + C.GoBytes(oob, oob_size), nil) - return C.int(n) + if err != nil { + fmt.Printf("write result %d (%d), %s\n", n, oobn, err) } - return 0 + return C.int(n) } func new_port(pid int, id int, t int, rcv int, snd int) *port { @@ -200,26 +201,27 @@ func (p *port) read(handler http.Handler) error { if c_req == 0 { m.Close() - } else { - r := find_request(c_req) - - go func(r *request) { - if handler == nil { - handler = http.DefaultServeMux - } + return nil + } - handler.ServeHTTP(r.response(), &r.req) - r.done() - }(r) + r := find_request(c_req) - if len(r.msgs) == 0 { - r.push(m) - } else if r.ch != nil { - r.ch <- m - } else { - m.Close() + 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 { + r.ch <- m + } else { + m.Close() } - return err + return nil } |