Skip to content

Commit

Permalink
Debugger: Poll frequently after stepping.
Browse files Browse the repository at this point in the history
This will make us listen for events slightly less often, so we don't want
to sustain it.
  • Loading branch information
unknownbrackets committed May 1, 2018
1 parent 5de960a commit 99122a8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Core/Debugger/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void HandleDebuggerRequest(const http::Request &request) {
subscriberData.push_back(info.init(eventHandlers));
}

// There's a tradeoff between responsiveness to incoming events, and polling for changes.
int highActivity = 0;
ws->SetTextHandler([&](const std::string &t) {
JsonReader reader(t.c_str(), t.size());
if (!reader.ok()) {
Expand All @@ -148,7 +150,10 @@ void HandleDebuggerRequest(const http::Request &request) {
if (eventFunc != eventHandlers.end()) {
std::lock_guard<std::mutex> guard(lifecycleLock);
eventFunc->second(req);
req.Finish();
if (!req.Finish()) {
// Poll more frequently for a second in case this triggers something.
highActivity = 1000;
}
} else {
req.Fail("Bad message: unknown event");
}
Expand All @@ -157,7 +162,7 @@ void HandleDebuggerRequest(const http::Request &request) {
ws->Send(DebuggerErrorEvent("Bad message", LogTypes::LERROR));
});

while (ws->Process(1.0f / 60.0f)) {
while (ws->Process(highActivity ? 1.0f / 1000.0f : 1.0f / 60.0f)) {
std::lock_guard<std::mutex> guard(lifecycleLock);
// These send events that aren't just responses to requests.
logger.Broadcast(ws);
Expand All @@ -167,6 +172,9 @@ void HandleDebuggerRequest(const http::Request &request) {
if (stopRequested) {
ws->Close(net::WebSocketClose::GOING_AWAY);
}
if (highActivity > 0) {
highActivity--;
}
}

std::lock_guard<std::mutex> guard(lifecycleLock);
Expand Down
4 changes: 3 additions & 1 deletion Core/Debugger/WebSocket/WebSocketUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ JsonWriter &DebuggerRequest::Respond() {
return writer_;
}

void DebuggerRequest::Finish() {
bool DebuggerRequest::Finish() {
if (responseBegun_ && !responseSent_) {
writer_.end();
if (responsePartial_)
Expand All @@ -40,6 +40,8 @@ void DebuggerRequest::Finish() {
responseSent_ = true;
responsePartial_ = false;
}

return responseSent_;
}

void DebuggerRequest::Flush() {
Expand Down
2 changes: 1 addition & 1 deletion Core/Debugger/WebSocket/WebSocketUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct DebuggerRequest {

JsonWriter &Respond();
void Flush();
void Finish();
bool Finish();

private:
JsonWriter writer_;
Expand Down

0 comments on commit 99122a8

Please sign in to comment.