Skip to content

Commit 79ee3d6

Browse files
committed
remove redundant token in client code
1 parent 7cb6a05 commit 79ee3d6

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

lute/net/src/client_websocket.cpp

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ struct WebSocketHandle : std::enable_shared_from_this<WebSocketHandle>
442442
std::shared_ptr<Ref> onErrorRef;
443443
std::weak_ptr<WebSocketConnection> connection;
444444
std::atomic<bool> hasScheduledClose{false};
445-
std::atomic<bool> hasPendingToken{false};
446445
bool isActive = false;
447446

448447
std::shared_ptr<WebSocketConnection> lockConnection() const
@@ -507,28 +506,7 @@ struct WebSocketHandle : std::enable_shared_from_this<WebSocketHandle>
507506
void handleClose(int closeCode, std::string closeReason)
508507
{
509508
scheduleCloseCallback(closeCode, std::move(closeReason));
510-
finishTerminalState();
511-
}
512-
513-
void handleError(std::string error)
514-
{
515-
scheduleErrorCallback(std::move(error));
516-
scheduleCloseCallback(1006);
517-
finishTerminalState();
518-
}
519-
520-
void markPendingToken()
521-
{
522-
if (!runtime || hasPendingToken.exchange(true))
523-
return;
524-
525-
runtime->addPendingToken();
526-
}
527-
528-
void releasePendingToken()
529-
{
530-
if (runtime && hasPendingToken.exchange(false))
531-
runtime->releasePendingToken();
509+
releaseConnectionKeepAlive();
532510
}
533511

534512
void releaseConnectionKeepAlive()
@@ -537,9 +515,10 @@ struct WebSocketHandle : std::enable_shared_from_this<WebSocketHandle>
537515
lockedConnection->releaseKeepAliveHandle();
538516
}
539517

540-
void finishTerminalState()
518+
void handleError(std::string error)
541519
{
542-
releasePendingToken();
520+
scheduleErrorCallback(std::move(error));
521+
scheduleCloseCallback(1006);
543522
releaseConnectionKeepAlive();
544523
}
545524

@@ -597,7 +576,7 @@ struct WebSocketHandle : std::enable_shared_from_this<WebSocketHandle>
597576
lockedConnection->releaseKeepAliveHandle();
598577
}
599578

600-
finishTerminalState();
579+
releaseConnectionKeepAlive();
601580
}
602581

603582
~WebSocketHandle()
@@ -801,7 +780,6 @@ int websocket(lua_State* L)
801780
))) std::shared_ptr<WebSocketHandle>(handle);
802781
(void)storage;
803782

804-
handle->markPendingToken();
805783
handle->notifyOpen();
806784
return 1;
807785
}

0 commit comments

Comments
 (0)