summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/go/unit/port.go68
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
}