add error callback to network.tcp_connect
This commit is contained in:
+12
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user