mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-05 08:01:26 +00:00
host_ctx is opaque, and leaf puts an instance number in it. The SDK held it as a Go pointer, so the first stack copy that found a value like 1 stopped the process with "invalid pointer found on stack". It is now an integer on the Go side and a pointer only in C. ConnEngine refused application input behind a busy write loop without reporting BLOCKED. The host read that as an engine waiting for its output to be taken, buffered decoded bytes to make room, and failed saturated two-way transfers as stalled, about one run in ten. It now reports BLOCKED once the handshake is done and the input buffer is full. On the application's half close ConnEngine closed the wrapped conn whole, dropping the reply still on its way. It now calls CloseWrite when the conn has one and keeps reading. enginetest.Driver drives an engine the way the host does, for a plugin's own tests; SharedLogger routes a per-outbound library logger into leaf's log.
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package leafabi
|
|
|
|
/*
|
|
#cgo CFLAGS: -I${SRCDIR}/../../leaf-plugin-abi/include
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include "abi.h"
|
|
|
|
// Callbacks for the SDK's own tests, which cannot define C functions: cgo is
|
|
// not available in _test.go files. They take a moment, so the collector that
|
|
// runs beside the test overlaps them.
|
|
static void leafabi_test_wake(void* host_ctx) {
|
|
(void)host_ctx;
|
|
usleep(1);
|
|
}
|
|
|
|
static void leafabi_test_log(
|
|
void* host_ctx,
|
|
leaf_log_level_t level,
|
|
const char* target,
|
|
const uint8_t* message,
|
|
size_t message_len) {
|
|
(void)host_ctx; (void)level; (void)target; (void)message; (void)message_len;
|
|
usleep(1);
|
|
}
|
|
|
|
static HostCallbacks leafabi_test_callbacks(uintptr_t host_ctx) {
|
|
HostCallbacks callbacks;
|
|
callbacks.size = sizeof(HostCallbacks);
|
|
callbacks.log = leafabi_test_log;
|
|
callbacks.wake = leafabi_test_wake;
|
|
callbacks.host_ctx = (void*)host_ctx;
|
|
return callbacks;
|
|
}
|
|
*/
|
|
import "C"
|
|
|
|
// testHost is a Host whose callbacks are real C functions and whose host_ctx
|
|
// is the given value. leaf passes an instance number there, not an address;
|
|
// the ABI says the value is the host's own business.
|
|
func testHost(hostCtx uintptr) Host {
|
|
callbacks := C.leafabi_test_callbacks(C.uintptr_t(hostCtx))
|
|
return hostFromCallbacks(&callbacks)
|
|
}
|