Skip to content

Commit 875c215

Browse files
xiaoqchShrBox
authored andcommitted
fix: fix HttpServer crash (#249)
1 parent db1285c commit 875c215

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/legacy/api/NetworkAPI.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ void WSClientClass::initListeners() {
156156

157157
ws->OnBinaryReceived(
158158
[nowList{&listeners[int(WSClientEvents::onBinaryReceived)]}](WebSocketClient&, vector<uint8_t> data) {
159-
if (!nowList->empty())
160-
for (auto& listener : *nowList) {
161-
if (!EngineManager::isValid(listener.engine)) return;
162-
EngineScope enter(listener.engine);
163-
NewTimeout(listener.func.get(), {ByteBuffer::newByteBuffer(data.data(), data.size())}, 1);
164-
}
159+
if (!nowList->empty())
160+
for (auto& listener : *nowList) {
161+
if (!EngineManager::isValid(listener.engine)) return;
162+
EngineScope enter(listener.engine);
163+
NewTimeout(listener.func.get(), {ByteBuffer::newByteBuffer(data.data(), data.size())}, 1);
164+
}
165165
}
166166
);
167167

@@ -482,7 +482,7 @@ void ADD_CALLBACK(
482482
}
483483
}
484484
CATCH_CALLBACK_IN_CORO("Fail in NetworkAPI callback")
485-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
485+
}).syncLaunch(ll::thread::ThreadPoolExecutor::getDefault());
486486
};
487487
switch (method) {
488488
case HttpRequestType::Get:
@@ -627,7 +627,7 @@ Local<Value> HttpServerClass::onPreRouting(const Arguments& args) {
627627
resp = *respObj->get();
628628
}
629629
CATCH_CALLBACK_IN_CORO("Fail in onPreRouting");
630-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
630+
}).syncLaunch(ll::thread::ThreadPoolExecutor::getDefault());
631631

632632
return handled ? Server::HandlerResponse::Handled : Server::HandlerResponse::Unhandled;
633633
});
@@ -661,7 +661,7 @@ Local<Value> HttpServerClass::onPostRouting(const Arguments& args) {
661661
resp = *respObj->get();
662662
}
663663
CATCH_CALLBACK_IN_CORO("Fail in onPostRouting");
664-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
664+
}).syncLaunch(ll::thread::ThreadPoolExecutor::getDefault());
665665
});
666666
return this->getScriptObject();
667667
}
@@ -692,7 +692,7 @@ Local<Value> HttpServerClass::onError(const Arguments& args) {
692692
resp = *respObj->get();
693693
}
694694
CATCH_CALLBACK_IN_CORO("Fail in onError");
695-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
695+
}).syncLaunch(ll::thread::ThreadPoolExecutor::getDefault());
696696
});
697697
return this->getScriptObject();
698698
}
@@ -731,7 +731,7 @@ Local<Value> HttpServerClass::onException(const Arguments& args) {
731731
resp = *respObj->get();
732732
}
733733
CATCH_CALLBACK_IN_CORO("Fail in onException");
734-
}).launch(ll::thread::ThreadPoolExecutor::getDefault());
734+
}).syncLaunch(ll::thread::ThreadPoolExecutor::getDefault());
735735
});
736736
return this->getScriptObject();
737737
}

0 commit comments

Comments
 (0)