-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port NetCli/NetGameLib to standard C++ containers #1487
Changes from 1 commit
6193fd9
5b2cc2e
caee7c6
86576c5
bd6b2b2
f931654
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,6 @@ struct CliAuConn : hsRefCnt { | |
void Send (const uintptr_t fields[], unsigned count); | ||
|
||
std::recursive_mutex critsect; | ||
LINK(CliAuConn) link; | ||
AsyncSocket sock; | ||
NetCli * cli; | ||
ST::string name; | ||
|
@@ -1249,7 +1248,7 @@ enum { | |
|
||
static bool s_running; | ||
static std::recursive_mutex s_critsect; | ||
static LISTDECL(CliAuConn, link) s_conns; | ||
static CliAuConn* s_conn = nullptr; | ||
static CliAuConn * s_active; | ||
static ST::string s_accountName; | ||
static ShaDigest s_accountNamePassHash; | ||
|
@@ -1327,8 +1326,7 @@ static CliAuConn * GetConnIncRef (const char tag[]) { | |
} | ||
|
||
//============================================================================ | ||
static void UnlinkAndAbandonConn_CS (CliAuConn * conn) { | ||
s_conns.Unlink(conn); | ||
static void AbandonConn(CliAuConn* conn) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is my last question, but, just to verify... Does the caller not need to have the critical section locked anymore? I'm assuming no because this is no longer accessing any static variables, and you dropped There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. As far as I can tell, the That said, now that I'm re-reading this... maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's all a little muddy, for sure, so I took a look at the code. It looks like Edit: Alternatively, you could just lock There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That seems like the best solution, yeah. |
||
conn->abandoned = true; | ||
|
||
conn->StopAutoReconnect(); | ||
|
@@ -1425,7 +1423,9 @@ static void NotifyConnSocketConnectFailed (CliAuConn * conn) { | |
{ | ||
hsLockGuard(s_critsect); | ||
conn->cancelId = nullptr; | ||
s_conns.Unlink(conn); | ||
if (s_conn == conn) { | ||
s_conn = nullptr; | ||
} | ||
|
||
if (conn == s_active) | ||
s_active = nullptr; | ||
|
@@ -1444,7 +1444,9 @@ static void NotifyConnSocketDisconnect (CliAuConn * conn) { | |
{ | ||
hsLockGuard(s_critsect); | ||
conn->cancelId = nullptr; | ||
s_conns.Unlink(conn); | ||
if (s_conn == conn) { | ||
s_conn = nullptr; | ||
} | ||
|
||
if (conn == s_active) | ||
s_active = nullptr; | ||
|
@@ -1525,13 +1527,13 @@ static void Connect ( | |
|
||
{ | ||
hsLockGuard(s_critsect); | ||
while (CliAuConn * oldConn = s_conns.Head()) { | ||
if (oldConn != conn) | ||
UnlinkAndAbandonConn_CS(oldConn); | ||
else | ||
s_conns.Unlink(oldConn); | ||
if (CliAuConn* oldConn = s_conn) { | ||
s_conn = nullptr; | ||
if (oldConn != conn) { | ||
AbandonConn(oldConn); | ||
} | ||
} | ||
s_conns.Link(conn); | ||
s_conn = conn; | ||
} | ||
|
||
Cli2Auth_Connect connect; | ||
|
@@ -1643,7 +1645,10 @@ void CliAuConn::TimerReconnect () { | |
|
||
if (!s_running) { | ||
hsLockGuard(s_critsect); | ||
UnlinkAndAbandonConn_CS(this); | ||
if (s_conn == this) { | ||
s_conn = nullptr; | ||
} | ||
AbandonConn(this); | ||
} | ||
else { | ||
Ref("Connecting"); | ||
|
@@ -4671,8 +4676,10 @@ void AuthDestroy (bool wait) { | |
|
||
{ | ||
hsLockGuard(s_critsect); | ||
while (CliAuConn * conn = s_conns.Head()) | ||
UnlinkAndAbandonConn_CS(conn); | ||
if (CliAuConn* conn = s_conn) { | ||
s_conn = nullptr; | ||
AbandonConn(conn); | ||
} | ||
s_active = nullptr; | ||
} | ||
|
||
|
@@ -4769,8 +4776,10 @@ void NetCliAuthAutoReconnectEnable (bool enable) { | |
void NetCliAuthDisconnect () { | ||
|
||
hsLockGuard(s_critsect); | ||
while (CliAuConn * conn = s_conns.Head()) | ||
UnlinkAndAbandonConn_CS(conn); | ||
if (CliAuConn* conn = s_conn) { | ||
s_conn = nullptr; | ||
AbandonConn(conn); | ||
} | ||
s_active = nullptr; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there ever any times that
s_conn
ands_active
will not be the same? I'm wondering if we could just uses_active
instead...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I wanted to do initially, but unfortunately the two aren't exactly the same.
s_conns
/s_conn
is always set beforeAsyncSocketConnect
, whereass_active
is only set later once the connection is fully established (e. g. for the auth server only after aAuth2Cli_ClientRegisterReply
is received).This logic can probably be simplified somehow so that it only uses one variable, but I didn't want to do anything too risky as part of the legacy data structure cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a good approach. 👍