-
Notifications
You must be signed in to change notification settings - Fork 12
/
host.cpp
49 lines (36 loc) · 979 Bytes
/
host.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* This file is part of Ark Cpp Client.
*
* (c) Ark Ecosystem <info@ark.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
**/
#include "host/host.h"
#include <cstdio>
#include <string>
namespace Ark {
namespace Client {
Host::Host(const char* ip, int port) : ip_(ip), port_(port) {}
/**/
bool Host::set(const char* ip, int port) {
this->ip_.reserve(IP_MAX_STRING_LEN);
this->ip_ += ip;
this->port_ = port;
return this->port_ == port && this->ip_ == ip;
}
/**/
std::string Host::ip() const noexcept { return this->ip_; };
/**/
int Host::port() const noexcept { return this->port_; };
/**/
std::string Host::toString() {
std::string out;
out.reserve(IP_MAX_STRING_LEN + PORT_MAX_STRING_LEN);
out += (this->ip_);
out += ":";
snprintf(&out[out.find(":") + 1U], PORT_MAX_STRING_LEN, "%d", this->port_);
return out;
}
} // namespace Client
} // namespace Ark