response.go (1316:5b767c6bfd0a) response.go (1323:6dfc9895e25e)
1/*
2 * Copyright (C) Max Romanov
3 * Copyright (C) NGINX, Inc.
4 */
5
6package unit
7
8/*

--- 5 unchanged lines hidden (view full) ---

14 "net/http"
15)
16
17type response struct {
18 header http.Header
19 headerSent bool
20 req *http.Request
21 c_req C.uintptr_t
1/*
2 * Copyright (C) Max Romanov
3 * Copyright (C) NGINX, Inc.
4 */
5
6package unit
7
8/*

--- 5 unchanged lines hidden (view full) ---

14 "net/http"
15)
16
17type response struct {
18 header http.Header
19 headerSent bool
20 req *http.Request
21 c_req C.uintptr_t
22 ch chan int
22}
23
24func new_response(c_req C.uintptr_t, req *http.Request) *response {
25 resp := &response{
26 header: http.Header{},
27 req: req,
28 c_req: c_req,
29 }

--- 5 unchanged lines hidden (view full) ---

35 return r.header
36}
37
38func (r *response) Write(p []byte) (n int, err error) {
39 if !r.headerSent {
40 r.WriteHeader(http.StatusOK)
41 }
42
23}
24
25func new_response(c_req C.uintptr_t, req *http.Request) *response {
26 resp := &response{
27 header: http.Header{},
28 req: req,
29 c_req: c_req,
30 }

--- 5 unchanged lines hidden (view full) ---

36 return r.header
37}
38
39func (r *response) Write(p []byte) (n int, err error) {
40 if !r.headerSent {
41 r.WriteHeader(http.StatusOK)
42 }
43
43 res := C.nxt_cgo_response_write(r.c_req, buf_ref(p), C.uint32_t(len(p)))
44 return int(res), nil
44 l := len(p)
45 written := int(0)
46 br := buf_ref(p)
47
48 for written < l {
49 res := C.nxt_cgo_response_write(r.c_req, br, C.uint32_t(l - written))
50
51 written += int(res)
52 br += C.uintptr_t(res)
53
54 if (written < l) {
55 if r.ch == nil {
56 r.ch = make(chan int, 2)
57 }
58
59 wait_shm_ack(r.ch)
60 }
61 }
62
63 return written, nil
45}
46
47func (r *response) WriteHeader(code int) {
48 if r.headerSent {
49 // Note: explicitly using Stderr, as Stdout is our HTTP output.
50 nxt_go_warn("multiple response.WriteHeader calls")
51 return
52 }

--- 27 unchanged lines hidden (view full) ---

80 C.nxt_cgo_response_send(r.c_req)
81}
82
83func (r *response) Flush() {
84 if !r.headerSent {
85 r.WriteHeader(http.StatusOK)
86 }
87}
64}
65
66func (r *response) WriteHeader(code int) {
67 if r.headerSent {
68 // Note: explicitly using Stderr, as Stdout is our HTTP output.
69 nxt_go_warn("multiple response.WriteHeader calls")
70 return
71 }

--- 27 unchanged lines hidden (view full) ---

99 C.nxt_cgo_response_send(r.c_req)
100}
101
102func (r *response) Flush() {
103 if !r.headerSent {
104 r.WriteHeader(http.StatusOK)
105 }
106}
107
108var observer_registry_ observable
109
110func wait_shm_ack(c chan int) {
111 observer_registry_.attach(c)
112
113 _ = <-c
114}
115
116//export nxt_go_shm_ack_handler
117func nxt_go_shm_ack_handler() {
118 observer_registry_.notify(1)
119}