Skip to content

Commit 00a37bd

Browse files
committed
wip(core): debugging more device-wakeup issues for udp
1 parent 7a40466 commit 00a37bd

File tree

11 files changed

+85
-35
lines changed

11 files changed

+85
-35
lines changed

api/conduit.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export class Conduit extends EventTarget {
393393
}
394394

395395
this.port = result.data.port
396-
console.log('INTERNAL_STARTED_CONDUIT', { port: this.port })
396+
console.log('>>> INTERNAL_STARTED_CONDUIT', { id: this.id, port: this.port })
397397
this.isErroring = false
398398

399399
this.socket = new WebSocket(this.url)
@@ -418,6 +418,8 @@ export class Conduit extends EventTarget {
418418
this.socket.onclose = (e) => {
419419
if (this.isErroring) return
420420

421+
console.log('>>> INTERNAL_ONCLOSE', { id: this.id })
422+
421423
this.socket = null
422424
this.isConnecting = false
423425
this.isActive = false
@@ -432,6 +434,7 @@ export class Conduit extends EventTarget {
432434
this.isConnecting = false
433435
this.dispatchEvent(new Event('open', e))
434436

437+
console.log('>>> INTERNAL_ONOPEN', { id: this.id })
435438
if (typeof callback === 'function') {
436439
callback(null)
437440
callback = null
@@ -458,8 +461,6 @@ export class Conduit extends EventTarget {
458461

459462
// In the reconnect() method:
460463
async reconnect (options = {}) {
461-
console.log('INTERNAL_WILL_RECONNECT')
462-
463464
if (this.isConnecting) {
464465
return Promise.resolve(this)
465466
}
@@ -471,11 +472,11 @@ export class Conduit extends EventTarget {
471472
} = options
472473

473474
try {
474-
console.log('INTERNAL_RECONNECTING')
475+
console.log('>>> INTERNAL_RECONNECTING', { id: this.id })
475476
await this.connect()
476477
// other modules like dgram will need to know when the conduit has
477478
// reconnected, the reopen event is the correct way to handle it.
478-
console.log('INTERNAL_DID_RECONNECT')
479+
console.log('>>> INTERNAL_RECONNECTED', { id: this.id })
479480
this.dispatchEvent(new CustomEvent('reopen'))
480481
return this
481482
} catch (err) {

src/runtime/app/app.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace ssc::runtime::app {
6868
#elif SOCKET_RUNTIME_PLATFORM_MACOS
6969
[NSApp run];
7070
#elif SOCKET_RUNTIME_PLATFORM_IOS
71+
debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
7172
@autoreleasepool {
7273
return UIApplicationMain(
7374
argc,
@@ -105,22 +106,28 @@ namespace ssc::runtime::app {
105106
}
106107

107108
void App::resume () {
109+
debug(">>> QQQ RESUME");
110+
108111
if (this->paused()) {
109112
this->isPaused = false;
110113
this->runtime.windowManager.emit("applicationresume");
111114

112115
this->dispatch([this]() {
116+
debug(">>> QQQ RESUME (RUNTIME0");
113117
this->runtime.resume();
114118
});
115119
}
116120
}
117121

118122
void App::pause () {
123+
debug(">>> QQQ PAUSE");
124+
119125
if (!this->paused()) {
120126
this->isPaused = true;
121127
this->runtime.windowManager.emit("applicationpause");
122128

123129
this->dispatch([this]() {
130+
debug(">>> QQQ PAUSE (RUNTIME0");
124131
this->runtime.pause();
125132
});
126133
}

src/runtime/app/apple.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ - (void) applicationWillBecomeActive: (NSNotification*) notification {
3737

3838
- (void) applicationWillResignActive: (NSNotification*) notification {
3939
dispatch_async(queue, ^{
40-
// self.app->pause();
40+
self.app->pause();
4141
});
4242
}
4343

src/runtime/core/services.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ namespace ssc::runtime::core {
4949
return false;
5050
}
5151
}
52+
53+
debug(">>> ALL SERVICES STARTED >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
54+
5255
return true;
5356
}
5457

@@ -70,14 +73,17 @@ namespace ssc::runtime::core {
7073
&this->platform,
7174
&this->process,
7275
&this->timers,
73-
&this->udp
76+
// &this->udp
7477
};
7578

7679
for (const auto& service : services) {
7780
if (service->enabled && !service->stop()) {
7881
return false;
7982
}
8083
}
84+
85+
debug(">>> ALL SERVICES STOPPED >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
86+
8187
return true;
8288
}
8389
}

src/runtime/core/services/conduit.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,8 @@ namespace ssc::runtime::core::services {
936936
this->isStarting.store(false);
937937

938938
if (!this->isActive()) {
939-
return false;
939+
debug(">>> CONDUIT::STOP::IS_NOT_ACTIVE");
940+
return true;
940941
}
941942

942943
return this->loop.dispatch([this]() {
@@ -1007,6 +1008,8 @@ namespace ssc::runtime::core::services {
10071008
}
10081009
}
10091010
}
1011+
1012+
debug(">>> STOPPING CONDUIT -- STOPPED");
10101013
});
10111014
}
10121015

src/runtime/core/services/diagnostics.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace ssc::runtime::core::services {
1919

2020
// queued responses diagnostics
2121
do {
22+
debug(">>> ACQUIRE SERVICES");
2223
Lock lock(this->services.mutex);
2324
query.queuedResponses.handles.count = this->context.queuedResponses.size();
2425
for (const auto& entry : this->context.queuedResponses) {
@@ -29,6 +30,7 @@ namespace ssc::runtime::core::services {
2930
#if !SOCKET_RUNTIME_PLATFORM_IOS
3031
// `childProcess` diagnostics
3132
do {
33+
debug(">>> ACQUIRE PROCESS HANDLES");
3234
Lock lock(this->services.process.mutex);
3335
query.childProcess.handles.count = this->services.process.handles.size();
3436
for (const auto& entry : this->services.process.handles) {
@@ -50,6 +52,7 @@ namespace ssc::runtime::core::services {
5052

5153
// fs diagnostics
5254
do {
55+
debug(">>> ACQUIRE PROCESS FS");
5356
Lock lock(this->services.fs.mutex);
5457
query.fs.descriptors.handles.count = this->services.fs.descriptors.size();
5558
query.fs.watchers.handles.count = this->services.fs.watchers.size();
@@ -65,6 +68,7 @@ namespace ssc::runtime::core::services {
6568

6669
// timers diagnostics
6770
do {
71+
debug(">>> ACQUIRE PROCESS TIMERS");
6872
Lock lock(this->services.timers.mutex);
6973
for (const auto& entry : this->services.timers.handles) {
7074
const auto id = entry.first;
@@ -84,6 +88,7 @@ namespace ssc::runtime::core::services {
8488

8589
// udp
8690
do {
91+
debug(">>> ACQUIRE PROCESS UDP HANDLES");
8792
Lock lock(this->services.udp.mutex);
8893
query.udp.handles.count = this->services.udp.manager.sockets.size();
8994
for (const auto& entry : this->services.udp.manager.sockets) {
@@ -93,6 +98,7 @@ namespace ssc::runtime::core::services {
9398

9499
// conduit
95100
do {
101+
debug(">>> ACQUIRE PROCESS CONDUIT HANDLES");
96102
Lock lock(this->services.conduit.mutex);
97103
query.conduit.handles.count = this->services.conduit.clients.size();
98104
query.conduit.isActive = this->services.conduit.isActive();
@@ -103,6 +109,7 @@ namespace ssc::runtime::core::services {
103109

104110
// uv
105111
do {
112+
debug(">>> ACQUIRE PROCESS UV HANDLES");
106113
Lock lock(this->loop.mutex);
107114
uv_metrics_info(this->loop.get(), &query.uv.metrics);
108115
query.uv.idleTime = uv_metrics_idle_time(this->loop.get());

src/runtime/core/services/udp.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,18 @@ namespace ssc::runtime::core::services {
450450

451451
if (socket->hasState(udp::SOCKET_STATE_UDP_RECV_STARTED)) {
452452
auto json = JSON::Object::Entries {
453+
{"source", "udp.readStart"},
454+
{"data", JSON::Object::Entries {
455+
{"id", std::to_string(id)}
456+
}}
457+
};
458+
/* auto json = JSON::Object::Entries {
453459
{"source", "udp.readStart"},
454460
{"err", JSON::Object::Entries {
455461
{"id", std::to_string(id)},
456462
{"message", "Socket is already receiving"}
457463
}}
458-
};
464+
}; */
459465

460466
return callback(seq, json, QueuedResponse{});
461467
}

src/runtime/ipc/routes.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3450,6 +3450,8 @@ static void mapIPCRoutes (Router *router) {
34503450
options.reuseAddr = message.get("reuseAddr") == "true";
34513451
options.address = message.get("address", "0.0.0.0");
34523452

3453+
debug(">>> UDP.BIND ROUTE CALLED %s", message.str().c_str());
3454+
34533455
router->bridge.getRuntime()->services.udp.bind(
34543456
message.seq,
34553457
id,

src/runtime/runtime.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ namespace ssc::runtime {
5555
}
5656

5757
bool Runtime::pause () {
58-
if (!this->services.stop()) {
59-
return false;
60-
}
58+
// if (!this->services.stop()) {
59+
// return false;
60+
// }
6161

62-
#if !SOCKET_RUNTIME_PLATFORM_ANDROID
63-
return this->loop.pause();
64-
#endif
62+
#if !SOCKET_RUNTIME_PLATFORM_ANDROID
63+
return this->loop.pause();
64+
#endif
6565

6666
return true;
6767
}

src/runtime/udp/manager.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ssc::runtime::udp {
1212
this->loop.dispatch([=, this]() {
1313
for (const auto& entry : this->sockets) {
1414
auto& socket = entry.second;
15-
if (socket != nullptr && (socket->isBound() || socket->isConnected())) {
15+
if (socket != nullptr /* && (socket->isBound() || socket->isConnected()) */) {
1616
socket->resume();
1717
}
1818
}
@@ -23,7 +23,7 @@ namespace ssc::runtime::udp {
2323
Lock lock(this->mutex);
2424
for (const auto& entry : this->sockets) {
2525
auto& socket = entry.second;
26-
if (socket != nullptr) {
26+
if (socket != nullptr /* && (socket->isBound() || socket->isConnected()) */) {
2727
socket->pause();
2828
}
2929
}

0 commit comments

Comments
 (0)