summaryrefslogtreecommitdiffhomepage
path: root/go
diff options
context:
space:
mode:
Diffstat (limited to 'go')
-rw-r--r--go/nxt_cgo_lib.c36
-rw-r--r--go/nxt_cgo_lib.h2
-rw-r--r--go/port.go8
3 files changed, 31 insertions, 15 deletions
diff --git a/go/nxt_cgo_lib.c b/go/nxt_cgo_lib.c
index a4fef9ea..f7171f55 100644
--- a/go/nxt_cgo_lib.c
+++ b/go/nxt_cgo_lib.c
@@ -14,10 +14,10 @@ static void nxt_cgo_request_handler(nxt_unit_request_info_t *req);
static nxt_cgo_str_t *nxt_cgo_str_init(nxt_cgo_str_t *dst,
nxt_unit_sptr_t *sptr, uint32_t length);
static int nxt_cgo_add_port(nxt_unit_ctx_t *, nxt_unit_port_t *port);
-static void nxt_cgo_remove_port(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id);
-static ssize_t nxt_cgo_port_send(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id,
+static void nxt_cgo_remove_port(nxt_unit_t *, nxt_unit_port_t *port);
+static ssize_t nxt_cgo_port_send(nxt_unit_ctx_t *, nxt_unit_port_t *port,
const void *buf, size_t buf_size, const void *oob, size_t oob_size);
-static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id,
+static ssize_t nxt_cgo_port_recv(nxt_unit_ctx_t *, nxt_unit_port_t *port,
void *buf, size_t buf_size, void *oob, size_t oob_size);
static void nxt_cgo_shm_ack_handler(nxt_unit_ctx_t *ctx);
@@ -44,7 +44,7 @@ nxt_cgo_run(uintptr_t handler)
return NXT_UNIT_ERROR;
}
- rc = nxt_unit_run(ctx);
+ rc = nxt_unit_run_ctx(ctx);
nxt_unit_done(ctx);
@@ -105,36 +105,37 @@ nxt_cgo_str_init(nxt_cgo_str_t *dst, nxt_unit_sptr_t *sptr, uint32_t length)
static int
nxt_cgo_add_port(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port)
{
- nxt_go_add_port(port->id.pid, port->id.id,
+ nxt_go_add_port((uintptr_t) ctx, port->id.pid, port->id.id,
port->in_fd, port->out_fd);
- return nxt_unit_add_port(ctx, port);
+ port->in_fd = -1;
+ port->out_fd = -1;
+
+ return NXT_UNIT_OK;
}
static void
-nxt_cgo_remove_port(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id)
+nxt_cgo_remove_port(nxt_unit_t *unit, nxt_unit_port_t *port)
{
- nxt_go_remove_port(port_id->pid, port_id->id);
-
- nxt_unit_remove_port(ctx, port_id);
+ nxt_go_remove_port(port->id.pid, port->id.id);
}
static ssize_t
-nxt_cgo_port_send(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id,
+nxt_cgo_port_send(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port,
const void *buf, size_t buf_size, const void *oob, size_t oob_size)
{
- return nxt_go_port_send(port_id->pid, port_id->id,
+ return nxt_go_port_send(port->id.pid, port->id.id,
(void *) buf, buf_size, (void *) oob, oob_size);
}
static ssize_t
-nxt_cgo_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_id_t *port_id,
+nxt_cgo_port_recv(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port,
void *buf, size_t buf_size, void *oob, size_t oob_size)
{
- return nxt_go_port_recv(port_id->pid, port_id->id,
+ return nxt_go_port_recv(port->id.pid, port->id.id,
buf, buf_size, oob, oob_size);
}
@@ -203,6 +204,13 @@ nxt_cgo_request_done(uintptr_t req, int res)
void
+nxt_cgo_unit_run_shared(uintptr_t ctx)
+{
+ nxt_unit_run_shared((nxt_unit_ctx_t *) ctx);
+}
+
+
+void
nxt_cgo_warn(uintptr_t msg, uint32_t msg_len)
{
nxt_unit_warn(NULL, "%.*s", (int) msg_len, (char *) msg);
diff --git a/go/nxt_cgo_lib.h b/go/nxt_cgo_lib.h
index 5317380b..fa515be5 100644
--- a/go/nxt_cgo_lib.h
+++ b/go/nxt_cgo_lib.h
@@ -35,6 +35,8 @@ int nxt_cgo_request_close(uintptr_t req);
void nxt_cgo_request_done(uintptr_t req, int res);
+void nxt_cgo_unit_run_shared(uintptr_t ctx);
+
void nxt_cgo_warn(uintptr_t msg, uint32_t msg_len);
#endif /* _NXT_CGO_LIB_H_INCLUDED_ */
diff --git a/go/port.go b/go/port.go
index 59a13f8b..64004d91 100644
--- a/go/port.go
+++ b/go/port.go
@@ -93,7 +93,7 @@ func getUnixConn(fd int) *net.UnixConn {
}
//export nxt_go_add_port
-func nxt_go_add_port(pid C.int, id C.int, rcv C.int, snd C.int) {
+func nxt_go_add_port(ctx C.uintptr_t, pid C.int, id C.int, rcv C.int, snd C.int) {
p := &port{
key: port_key{
pid: int(pid),
@@ -104,6 +104,12 @@ func nxt_go_add_port(pid C.int, id C.int, rcv C.int, snd C.int) {
}
add_port(p)
+
+ if id == 65535 {
+ go func(ctx C.uintptr_t) {
+ C.nxt_cgo_unit_run_shared(ctx);
+ }(ctx)
+ }
}
//export nxt_go_remove_port