summaryrefslogtreecommitdiffhomepage
path: root/go/unit.go
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-11-18 22:33:53 +0300
committerMax Romanov <max.romanov@nginx.com>2020-11-18 22:33:53 +0300
commit8132e1f700934a32bc9e3fb0ab66f550a335a326 (patch)
treec9e276355d4a1f6883efc85eaf2a1f3d65d2598a /go/unit.go
parentd26afcb481d97cd71db014b16bde44e807043a2b (diff)
downloadunit-8132e1f700934a32bc9e3fb0ab66f550a335a326.tar.gz
unit-8132e1f700934a32bc9e3fb0ab66f550a335a326.tar.bz2
Go: removing C proxy functions and re-using goroutines.
Diffstat (limited to 'go/unit.go')
-rw-r--r--go/unit.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/go/unit.go b/go/unit.go
index 1534479e..b5dd4f6c 100644
--- a/go/unit.go
+++ b/go/unit.go
@@ -30,15 +30,15 @@ func buf_ref(buf []byte) C.uintptr_t {
return C.uintptr_t(uintptr(unsafe.Pointer(&buf[0])))
}
-type StringHeader struct {
+type string_header struct {
Data unsafe.Pointer
Len int
}
-func str_ref(s string) C.uintptr_t {
- header := (*StringHeader)(unsafe.Pointer(&s))
+func str_ref(s string) *C.char {
+ header := (*string_header)(unsafe.Pointer(&s))
- return C.uintptr_t(uintptr(unsafe.Pointer(header.Data)))
+ return (*C.char)(header.Data)
}
func (buf *cbuf) init_bytes(b []byte) {
@@ -46,12 +46,7 @@ func (buf *cbuf) init_bytes(b []byte) {
buf.s = C.size_t(len(b))
}
-func (buf *cbuf) init_string(s string) {
- buf.b = str_ref(s)
- buf.s = C.size_t(len(s))
-}
-
-type SliceHeader struct {
+type slice_header struct {
Data unsafe.Pointer
Len int
Cap int
@@ -63,17 +58,17 @@ func (buf *cbuf) GoBytes() []byte {
return b[:0]
}
- bytesHeader := &SliceHeader{
+ header := &slice_header{
Data: unsafe.Pointer(uintptr(buf.b)),
Len: int(buf.s),
Cap: int(buf.s),
}
- return *(*[]byte)(unsafe.Pointer(bytesHeader))
+ return *(*[]byte)(unsafe.Pointer(header))
}
func GoBytes(buf unsafe.Pointer, size C.int) []byte {
- bytesHeader := &SliceHeader{
+ bytesHeader := &slice_header{
Data: buf,
Len: int(size),
Cap: int(size),
@@ -82,12 +77,25 @@ func GoBytes(buf unsafe.Pointer, size C.int) []byte {
return *(*[]byte)(unsafe.Pointer(bytesHeader))
}
+func GoStringN(sptr *C.nxt_unit_sptr_t, l C.int) string {
+ p := unsafe.Pointer(sptr)
+ b := uintptr(p) + uintptr(*(*C.uint32_t)(p))
+
+ return C.GoStringN((*C.char)(unsafe.Pointer(b)), l)
+}
+
func nxt_go_warn(format string, args ...interface{}) {
str := fmt.Sprintf("[go] " + format, args...)
C.nxt_cgo_warn(str_ref(str), C.uint32_t(len(str)))
}
+func nxt_go_alert(format string, args ...interface{}) {
+ str := fmt.Sprintf("[go] " + format, args...)
+
+ C.nxt_cgo_alert(str_ref(str), C.uint32_t(len(str)))
+}
+
type handler_registry struct {
sync.RWMutex
next uintptr