mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
add error callback to network.tcp_connect
This commit is contained in:
parent
553ee8b1f2
commit
f8be3e74f1
6 changed files with 79 additions and 17 deletions
|
|
@ -16,7 +16,10 @@ namespace network {
|
|||
std::unique_ptr<Requests> create_curl_requests();
|
||||
|
||||
std::shared_ptr<TcpConnection> connect_tcp(
|
||||
const std::string& address, int port, runnable callback
|
||||
const std::string& address,
|
||||
int port,
|
||||
runnable callback,
|
||||
stringconsumer errorCallback
|
||||
);
|
||||
|
||||
std::shared_ptr<TcpServer> open_tcp_server(
|
||||
|
|
@ -87,12 +90,19 @@ Server* Network::getServer(u64id_t id, bool includePrivate) const {
|
|||
return found->second.get();
|
||||
}
|
||||
|
||||
u64id_t Network::connectTcp(const std::string& address, int port, consumer<u64id_t> callback) {
|
||||
u64id_t Network::connectTcp(
|
||||
const std::string& address,
|
||||
int port,
|
||||
consumer<u64id_t> callback,
|
||||
ConnectErrorCallback errorCallback
|
||||
) {
|
||||
std::lock_guard lock(connectionsMutex);
|
||||
|
||||
u64id_t id = nextConnection++;
|
||||
auto socket = connect_tcp(address, port, [id, callback]() {
|
||||
callback(id);
|
||||
}, [id, errorCallback](auto errorMessage) {
|
||||
errorCallback(id, errorMessage);
|
||||
});
|
||||
connections[id] = std::move(socket);
|
||||
return id;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue