-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This way it looks much cleaner and naturally doesn't leak any implementation details to clients. Also, now it's much easier to provide native connection address implementations for each backend implementation. Signed-off-by: Pavel Solodovnikov <[email protected]>
- Loading branch information
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
This file is part of Warzone 2100. | ||
Copyright (C) 2024 Warzone 2100 Project | ||
Warzone 2100 is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
Warzone 2100 is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Warzone 2100; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#pragma once | ||
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Fedora :LATEST [GCC]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Alpine :LATEST [GCC]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Arch :LATEST [Clang]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Arch :LATEST [GCC]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Fedora :LATEST [GCC -m32]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Ubuntu 22.04 [GCC]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Ubuntu 22.04 [Clang]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Ubuntu 20.04 [GCC]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / Ubuntu 24.04 [Clang]
Check warning on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / wasm32
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / arm64 [LLVM_MINGW]
Check failure on line 17 in lib/netplay/tcp/tcp_connection_address.cpp GitHub Actions / x86 [LLVM_MINGW]
|
||
|
||
#include "lib/netplay/tcp/tcp_connection_address.h" | ||
|
||
#include "lib/netplay/tcp/netsocket.h" // for `freeaddrinfo` | ||
#include "lib/framework/frame.h" // for `ASSERT` | ||
|
||
TCPConnectionAddress::TCPConnectionAddress(SocketAddress* addr) | ||
: addr_(addr) | ||
{} | ||
|
||
TCPConnectionAddress::~TCPConnectionAddress() | ||
{ | ||
ASSERT(addr_ != nullptr, "Invalid addrinfo stored in the connection address"); | ||
freeaddrinfo(addr_); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
This file is part of Warzone 2100. | ||
Copyright (C) 2024 Warzone 2100 Project | ||
Warzone 2100 is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
Warzone 2100 is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Warzone 2100; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "lib/netplay/connection_address.h" | ||
|
||
#if defined WZ_OS_UNIX | ||
# include <netdb.h> | ||
#elif defined WZ_OS_WIN | ||
# include <ws2tcpip.h> | ||
#endif | ||
|
||
typedef struct addrinfo SocketAddress; | ||
|
||
class TCPConnectionAddress : public IConnectionAddress | ||
{ | ||
public: | ||
|
||
/// Assumes ownership of `addr` | ||
explicit TCPConnectionAddress(SocketAddress* addr); | ||
virtual ~TCPConnectionAddress() override; | ||
|
||
// NOTE: The lifetime of the returned `addrinfo` struct is bounded by the parent object's lifetime! | ||
const SocketAddress* asRawSocketAddress() const { return addr_; } | ||
|
||
private: | ||
|
||
SocketAddress* addr_; | ||
}; |