Skip to content

Commit 96691f5

Browse files
committed
moved SB async handle cleanup
1 parent 7ae6ece commit 96691f5

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

code/core/OS/Net/NetPeer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class INetPeer : public OS::Ref, public OS::LinkedList<INetPeer *> {
5050
static void write_callback(uv_write_t *req, int status);
5151

5252
static void close_callback(uv_handle_t *handle);
53-
void CloseSocket();
53+
virtual void CloseSocket();
5454
protected:
5555
static void read_alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
5656
buf->base = (char*)malloc(suggested_size);

code/serverbrowsing/server/SBPeer.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,19 @@ namespace SB {
9292
peer->FlushPendingRequests();
9393
}
9494

95-
void Peer::Delete(bool timeout) {
96-
if(!m_delete_flag) {
95+
/*
96+
This override exists to close the handle in the main thread, as this CloseSocket is only called there
97+
98+
while this was originally only for sockets, it should maybe be renamed CloseHandles
99+
*/
100+
void Peer::CloseSocket() {
101+
if(!m_socket_deleted) { //this will get set to true by INetPeer::CloseSocket on first call, so its only ever called once
97102
IncRef();
98103
uv_close((uv_handle_t*)&mp_pending_request_flush_async, close_callback);
99104
}
105+
INetPeer::CloseSocket();
106+
}
107+
void Peer::Delete(bool timeout) {
100108
m_timeout_flag = timeout;
101109
m_delete_flag = true;
102110
}

code/serverbrowsing/server/SBPeer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace SB {
4848
virtual void OnRecievedGameInfoPair(const OS::GameData game_data_first, const OS::GameData game_data_second, void *extra) = 0;
4949

5050
virtual void Delete(bool timeout = false);
51+
void CloseSocket();
5152
protected:
5253
int m_version;
5354

0 commit comments

Comments
 (0)