initial CFRunLoop impl
This commit is contained in:
parent
f10df2164c
commit
5365e1bb13
|
@ -88,6 +88,7 @@ extern "C" JSGlobalContextRef RealmReactGetJSGlobalContextForExecutor(id executo
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
GCDWebServer *_webServer;
|
GCDWebServer *_webServer;
|
||||||
std::unique_ptr<RPCServer> _rpcServer;
|
std::unique_ptr<RPCServer> _rpcServer;
|
||||||
|
std::thread _workerThread;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,6 +211,15 @@ RCT_REMAP_METHOD(emit, emitEvent:(NSString *)eventName withObject:(id)object) {
|
||||||
return [ipAddresses copy];
|
return [ipAddresses copy];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
TimerCallback(CFRunLoopTimerRef timer, void *info)
|
||||||
|
{
|
||||||
|
RPCServer* rpcServer = (RPCServer*)info;
|
||||||
|
rpcServer->try_run_task();
|
||||||
|
done:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)startRPC {
|
- (void)startRPC {
|
||||||
[GCDWebServer setLogLevel:3];
|
[GCDWebServer setLogLevel:3];
|
||||||
_webServer = [[GCDWebServer alloc] init];
|
_webServer = [[GCDWebServer alloc] init];
|
||||||
|
@ -250,6 +260,27 @@ RCT_REMAP_METHOD(emit, emitEvent:(NSString *)eventName withObject:(id)object) {
|
||||||
[response setValue:@"http://localhost:8081" forAdditionalHeader:@"Access-Control-Allow-Origin"];
|
[response setValue:@"http://localhost:8081" forAdditionalHeader:@"Access-Control-Allow-Origin"];
|
||||||
return response;
|
return response;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
_workerThread = std::thread([&]() {
|
||||||
|
|
||||||
|
auto timerInterval = 0.5;
|
||||||
|
CFStringRef timerMode = CFSTR("TimerMode");
|
||||||
|
CFRunLoopTimerContext timerContext = { 0, NULL, NULL, NULL, NULL };
|
||||||
|
timerContext.info = &_rpcServer;
|
||||||
|
CFRunLoopTimerRef timerRef = CFRunLoopTimerCreate(kCFAllocatorDefault,
|
||||||
|
CFAbsoluteTimeGetCurrent() + timerInterval,
|
||||||
|
timerInterval,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
TimerCallback,
|
||||||
|
&timerContext);
|
||||||
|
|
||||||
|
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timerRef, timerMode);
|
||||||
|
CFRunLoopRunInMode(timerMode, 4, false);
|
||||||
|
|
||||||
|
|
||||||
|
CFRunLoopRun();
|
||||||
|
});
|
||||||
|
|
||||||
[_webServer startWithPort:WEB_SERVER_PORT bonjourName:nil];
|
[_webServer startWithPort:WEB_SERVER_PORT bonjourName:nil];
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue