mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-01-07 16:43:10 +00:00
rm some Waku leftover references
This commit is contained in:
parent
75251fb721
commit
803744dd29
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2025 Waku
|
Copyright (c) 2025 Logos Messaging
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@ -69,19 +69,19 @@ proc sendRequestToFFIThread*(
|
|||||||
if fireSyncRes.get() == false:
|
if fireSyncRes.get() == false:
|
||||||
return err("Couldn't fireSync in time")
|
return err("Couldn't fireSync in time")
|
||||||
|
|
||||||
## wait until the Waku Thread properly received the request
|
## wait until the FFI working thread properly received the request
|
||||||
let res = ctx.reqReceivedSignal.waitSync(timeout)
|
let res = ctx.reqReceivedSignal.waitSync(timeout)
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
return err("Couldn't receive reqReceivedSignal signal")
|
return err("Couldn't receive reqReceivedSignal signal")
|
||||||
|
|
||||||
## Notice that in case of "ok", the deallocShared(req) is performed by the Waku Thread in the
|
## Notice that in case of "ok", the deallocShared(req) is performed by the FFI Thread in the
|
||||||
## process proc. See the 'waku_thread_request.nim' module for more details.
|
## process proc.
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
type Foo = object
|
type Foo = object
|
||||||
registerReqFFI(WatchdogReq, foo: ptr Foo):
|
registerReqFFI(WatchdogReq, foo: ptr Foo):
|
||||||
proc(): Future[Result[string, string]] {.async.} =
|
proc(): Future[Result[string, string]] {.async.} =
|
||||||
return ok("waku thread is not blocked")
|
return ok("FFI thread is not blocked")
|
||||||
|
|
||||||
type JsonNotRespondingEvent = object
|
type JsonNotRespondingEvent = object
|
||||||
eventType: string
|
eventType: string
|
||||||
@ -93,16 +93,15 @@ proc `$`(event: JsonNotRespondingEvent): string =
|
|||||||
$(%*event)
|
$(%*event)
|
||||||
|
|
||||||
proc onNotResponding*(ctx: ptr FFIContext) =
|
proc onNotResponding*(ctx: ptr FFIContext) =
|
||||||
callEventCallback(ctx, "onWakuNotResponsive"):
|
callEventCallback(ctx, "onNotResponding"):
|
||||||
$JsonNotRespondingEvent.init()
|
$JsonNotRespondingEvent.init()
|
||||||
|
|
||||||
proc watchdogThreadBody(ctx: ptr FFIContext) {.thread.} =
|
proc watchdogThreadBody(ctx: ptr FFIContext) {.thread.} =
|
||||||
## Watchdog thread that monitors the Waku thread and notifies the library user if it hangs.
|
## Watchdog thread that monitors the FFI thread and notifies the library user if it hangs.
|
||||||
|
|
||||||
let watchdogRun = proc(ctx: ptr FFIContext) {.async.} =
|
let watchdogRun = proc(ctx: ptr FFIContext) {.async.} =
|
||||||
const WatchdogStartDelay = 10.seconds
|
const WatchdogStartDelay = 10.seconds
|
||||||
const WatchdogTimeinterval = 1.seconds
|
const WatchdogTimeinterval = 1.seconds
|
||||||
const WakuNotRespondingTimeout = 3.seconds
|
|
||||||
|
|
||||||
# Give time for the node to be created and up before sending watchdog requests
|
# Give time for the node to be created and up before sending watchdog requests
|
||||||
await sleepAsync(WatchdogStartDelay)
|
await sleepAsync(WatchdogStartDelay)
|
||||||
@ -113,7 +112,7 @@ proc watchdogThreadBody(ctx: ptr FFIContext) {.thread.} =
|
|||||||
debug "Watchdog thread exiting because FFIContext is not running"
|
debug "Watchdog thread exiting because FFIContext is not running"
|
||||||
break
|
break
|
||||||
|
|
||||||
let wakuCallback = proc(
|
let callback = proc(
|
||||||
callerRet: cint, msg: ptr cchar, len: csize_t, userData: pointer
|
callerRet: cint, msg: ptr cchar, len: csize_t, userData: pointer
|
||||||
) {.cdecl, gcsafe, raises: [].} =
|
) {.cdecl, gcsafe, raises: [].} =
|
||||||
discard ## Don't do anything. Just respecting the callback signature.
|
discard ## Don't do anything. Just respecting the callback signature.
|
||||||
@ -121,7 +120,7 @@ proc watchdogThreadBody(ctx: ptr FFIContext) {.thread.} =
|
|||||||
|
|
||||||
trace "Sending watchdog request to FFI thread"
|
trace "Sending watchdog request to FFI thread"
|
||||||
|
|
||||||
sendRequestToFFIThread(ctx, WatchdogReq.ffiNewReq(wakuCallback, nilUserData)).isOkOr:
|
sendRequestToFFIThread(ctx, WatchdogReq.ffiNewReq(callback, nilUserData)).isOkOr:
|
||||||
error "Failed to send watchdog request to FFI thread", error = $error
|
error "Failed to send watchdog request to FFI thread", error = $error
|
||||||
onNotResponding(ctx)
|
onNotResponding(ctx)
|
||||||
|
|
||||||
@ -174,7 +173,7 @@ proc createFFIContext*[T](): Result[ptr FFIContext[T], string] =
|
|||||||
createThread(ctx.ffiThread, ffiThreadBody[T], ctx)
|
createThread(ctx.ffiThread, ffiThreadBody[T], ctx)
|
||||||
except ValueError, ResourceExhaustedError:
|
except ValueError, ResourceExhaustedError:
|
||||||
freeShared(ctx)
|
freeShared(ctx)
|
||||||
return err("failed to create the Waku thread: " & getCurrentExceptionMsg())
|
return err("failed to create the FFI thread: " & getCurrentExceptionMsg())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
createThread(ctx.watchdogThread, watchdogThreadBody, ctx)
|
createThread(ctx.watchdogThread, watchdogThreadBody, ctx)
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
## This file contains the base message request type that will be handled.
|
## This file contains the base message request type that will be handled.
|
||||||
## The requests are created by the main thread and processed by
|
## The requests are created by the main thread and processed by
|
||||||
## the Waku Thread.
|
## the FFI Thread.
|
||||||
|
|
||||||
import std/[json, macros], results, tables
|
import std/[json, macros], results, tables
|
||||||
import chronos, chronos/threadsync
|
import chronos, chronos/threadsync
|
||||||
import ./ffi_types, ./internal/ffi_macro, ./alloc, ./ffi_context
|
import ./ffi_types, ./internal/ffi_macro, ./alloc, ./ffi_context
|
||||||
import waku/factory/waku
|
|
||||||
|
|
||||||
type FFIThreadRequest* = object
|
type FFIThreadRequest* = object
|
||||||
callback: FFICallBack
|
callback: FFICallBack
|
||||||
@ -42,7 +41,7 @@ proc handleRes[T: string | void](
|
|||||||
|
|
||||||
if res.isErr():
|
if res.isErr():
|
||||||
foreignThreadGc:
|
foreignThreadGc:
|
||||||
let msg = "libwaku error: handleRes fireSyncRes error: " & $res.error
|
let msg = "ffi error: handleRes fireSyncRes error: " & $res.error
|
||||||
request[].callback(
|
request[].callback(
|
||||||
RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), request[].userData
|
RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), request[].userData
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user