diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-08-31 00:42:16 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-08-31 00:42:16 +0300 |
commit | f0e9e3ace94c82fab78ab1d4ee8c3042f3e94fdf (patch) | |
tree | 74fab38d3799598febc98aaabb0f5902d7dc5a0e /src/nginext/nginext.go | |
parent | 61606835448554a7ee9a4431d732e1f2a9318376 (diff) | |
download | unit-f0e9e3ace94c82fab78ab1d4ee8c3042f3e94fdf.tar.gz unit-f0e9e3ace94c82fab78ab1d4ee8c3042f3e94fdf.tar.bz2 |
nginext has been renamed to unit.
Diffstat (limited to 'src/nginext/nginext.go')
-rw-r--r-- | src/nginext/nginext.go | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/src/nginext/nginext.go b/src/nginext/nginext.go deleted file mode 100644 index 895d6b28..00000000 --- a/src/nginext/nginext.go +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) Max Romanov - * Copyright (C) NGINX, Inc. - */ - -package nginext - -/* -#include "nxt_go_lib.h" -*/ -import "C" - -import ( - "fmt" - "net/http" - "os" - "strconv" - "strings" - "unsafe" -) - -type cbuf struct { - b unsafe.Pointer - s C.size_t - f bool -} - -func new_cbuf(buf []byte) *cbuf { - if len(buf) == 0 { - return nil - } - - return &cbuf{ - getCBytes(buf), C.size_t(len(buf)), true, - } -} - -func (buf *cbuf) Close() { - if buf == nil { - return - } - - if buf.f && buf.s > 0 { - C.free(buf.b) - buf.f = false - buf.b = nil - buf.s = 0 - } -} - -func (buf *cbuf) GoBytes() []byte { - if buf == nil { - var b [0]byte - return b[:0] - } - - return C.GoBytes(buf.b, C.int(buf.s)) -} - -type cmsg struct { - buf cbuf - oob cbuf -} - -func new_cmsg(buf []byte, oob []byte) *cmsg { - return &cmsg{ - buf: cbuf{getCBytes(buf), C.size_t(len(buf)), true}, - oob: cbuf{getCBytes(oob), C.size_t(len(oob)), true}, - } -} - -func (msg *cmsg) Close() { - msg.buf.Close() - msg.oob.Close() -} - -var nxt_go_quit bool = false - -//export nxt_go_set_quit -func nxt_go_set_quit() { - nxt_go_quit = true -} - -func ListenAndServe(addr string, handler http.Handler) error { - var read_port *port - - go_ports_env := os.Getenv("NXT_GO_PORTS") - - ports := strings.Split(go_ports_env, ";") - pid := os.Getpid() - - for _, port_str := range ports { - if len(port_str) <= 0 { - continue - } - - attrs := strings.Split(port_str, ",") - - var attrsN [5]int - var err error - for i, attr := range attrs { - attrsN[i], err = strconv.Atoi(attr) - if err != nil { - fmt.Printf("err %s\n", err) - break - } - } - - if err != nil { - continue - } - - p := new_port(attrsN[0], attrsN[1], attrsN[2], attrsN[3], attrsN[4]) - - if attrsN[0] == pid { - read_port = p - } - } - - if read_port != nil { - C.nxt_go_ready() - - for !nxt_go_quit { - err := read_port.read(handler) - if err != nil { - return err - } - } - } else { - return http.ListenAndServe(addr, handler) - } - - return nil -} |