-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
netplay: introduce inheritance chain for connection address objects
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
Showing
9 changed files
with
100 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
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 | ||
*/ | ||
|
||
#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_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters