Skip to content

Commit

Permalink
Using daemon thread for sync client while Core add support to Thread …
Browse files Browse the repository at this point in the history
…Observer to detach it
  • Loading branch information
nhachicha committed Oct 10, 2023
1 parent aa38a74 commit 01e6d62
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/jni-swig-stub/src/main/jni/realm_api_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ using WebsocketFunctionHandlerCallback = std::function<void(bool, int, const cha

static void websocket_post_func(realm_userdata_t userdata,
realm_sync_socket_callback_t* realm_callback) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread
static JavaClass native_pointer_class(jenv, "io/realm/kotlin/internal/interop/LongPointerWrapper");
static JavaMethod native_pointer_constructor(jenv, native_pointer_class, "<init>", "(JZ)V");

Expand All @@ -705,7 +705,7 @@ static void websocket_post_func(realm_userdata_t userdata,

static realm_sync_socket_timer_t websocket_create_timer_func(
realm_userdata_t userdata, uint64_t delay_ms, realm_sync_socket_callback_t* realm_callback) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread
static JavaClass native_pointer_class(jenv,
"io/realm/kotlin/internal/interop/LongPointerWrapper");
static JavaMethod native_pointer_constructor(jenv, native_pointer_class, "<init>", "(JZ)V");
Expand Down Expand Up @@ -737,7 +737,7 @@ static void websocket_cancel_timer_func(realm_userdata_t userdata,
realm_sync_socket_timer_t timer_userdata) {

if (timer_userdata != nullptr) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread
jobject cancellable_timer = static_cast<jobject>(timer_userdata);

static JavaClass cancellable_timer_class(jenv, "io/realm/kotlin/internal/interop/sync/CancellableTimer");
Expand All @@ -753,7 +753,7 @@ static realm_sync_socket_websocket_t websocket_connect_func(
realm_userdata_t userdata, realm_websocket_endpoint_t endpoint,
realm_websocket_observer_t* realm_websocket_observer) {

auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread

static JavaClass native_pointer_class(jenv, "io/realm/kotlin/internal/interop/LongPointerWrapper");
static JavaMethod native_pointer_constructor(jenv, native_pointer_class, "<init>", "(JZ)V");
Expand Down Expand Up @@ -795,7 +795,7 @@ static void websocket_async_write_func(realm_userdata_t userdata,
realm_sync_socket_websocket_t websocket_userdata,
const char* data, size_t size,
realm_sync_socket_callback_t* realm_callback) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread

static JavaClass native_pointer_class(jenv, "io/realm/kotlin/internal/interop/LongPointerWrapper");
static JavaMethod native_pointer_constructor(jenv, native_pointer_class, "<init>", "(JZ)V");
Expand Down Expand Up @@ -827,7 +827,7 @@ static void websocket_async_write_func(realm_userdata_t userdata,
static void realm_sync_websocket_free(realm_userdata_t userdata,
realm_sync_socket_websocket_t websocket_userdata) {
if (websocket_userdata != nullptr) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread
static jclass websocket_client_class = jenv->FindClass("io/realm/kotlin/internal/interop/sync/WebSocketClient");
static jmethodID close_method = jenv->GetMethodID(websocket_client_class, "closeWebsocket", "()V");

Expand All @@ -840,7 +840,7 @@ static void realm_sync_websocket_free(realm_userdata_t userdata,

static void realm_sync_userdata_free(realm_userdata_t userdata) {
if (userdata != nullptr) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread

static jclass websocket_client_class = jenv->FindClass("io/realm/kotlin/internal/interop/sync/WebSocketTransport");
static jmethodID close_method = jenv->GetMethodID(websocket_client_class, "close", "()V");
Expand Down Expand Up @@ -868,7 +868,7 @@ void realm_sync_websocket_error(int64_t observer_ptr) {
}

bool realm_sync_websocket_message(int64_t observer_ptr, jbyteArray data, size_t size) {
auto jenv = get_env(true);
auto jenv = get_env(true, true); // attach as daemon thread
jbyte* byteData = jenv->GetByteArrayElements(data, NULL);
std::unique_ptr<char[]> charData(new char[size]); // not null terminated (used in util::Span with size parameter)
std::memcpy(charData.get(), byteData, size);
Expand Down

0 comments on commit 01e6d62

Please sign in to comment.