Skip to content

Commit 22c6805

Browse files
author
Sergey Fedchenko
committed
Cosmetic fixes in port.go.
This closes #5 on GitHub. From 615369a
1 parent 409dcd3 commit 22c6805

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

src/go/unit/port.go

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,19 @@ func nxt_go_port_send(pid C.int, id C.int, buf unsafe.Pointer, buf_size C.int,
134134

135135
p := find_port(key)
136136

137-
if p != nil {
138-
n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size),
139-
C.GoBytes(oob, oob_size), nil)
137+
if p == nil {
138+
return 0
139+
}
140140

141-
if err != nil {
142-
fmt.Printf("write result %d (%d), %s\n", n, oobn, err)
143-
}
141+
n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size),
142+
C.GoBytes(oob, oob_size), nil)
144143

145-
return C.int(n)
144+
if err != nil {
145+
fmt.Printf("write result %d (%d), %s\n", n, oobn, err)
146146
}
147147

148-
return 0
148+
return C.int(n)
149+
149150
}
150151

151152
//export nxt_go_main_send
@@ -154,18 +155,18 @@ func nxt_go_main_send(buf unsafe.Pointer, buf_size C.int, oob unsafe.Pointer,
154155

155156
p := main_port()
156157

157-
if p != nil {
158-
n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size),
159-
C.GoBytes(oob, oob_size), nil)
158+
if p == nil {
159+
return 0
160+
}
160161

161-
if err != nil {
162-
fmt.Printf("write result %d (%d), %s\n", n, oobn, err)
163-
}
162+
n, oobn, err := p.snd.WriteMsgUnix(C.GoBytes(buf, buf_size),
163+
C.GoBytes(oob, oob_size), nil)
164164

165-
return C.int(n)
165+
if err != nil {
166+
fmt.Printf("write result %d (%d), %s\n", n, oobn, err)
166167
}
167168

168-
return 0
169+
return C.int(n)
169170
}
170171

171172
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 {
200201

201202
if c_req == 0 {
202203
m.Close()
203-
} else {
204-
r := find_request(c_req)
205-
206-
go func(r *request) {
207-
if handler == nil {
208-
handler = http.DefaultServeMux
209-
}
204+
return nil
205+
}
210206

211-
handler.ServeHTTP(r.response(), &r.req)
212-
r.done()
213-
}(r)
207+
r := find_request(c_req)
214208

215-
if len(r.msgs) == 0 {
216-
r.push(m)
217-
} else if r.ch != nil {
218-
r.ch <- m
219-
} else {
220-
m.Close()
209+
go func(r *request) {
210+
if handler == nil {
211+
handler = http.DefaultServeMux
221212
}
213+
214+
handler.ServeHTTP(r.response(), &r.req)
215+
r.done()
216+
}(r)
217+
218+
if len(r.msgs) == 0 {
219+
r.push(m)
220+
} else if r.ch != nil {
221+
r.ch <- m
222+
} else {
223+
m.Close()
222224
}
223225

224-
return err
226+
return nil
225227
}

0 commit comments

Comments
 (0)