Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/pistache/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@
#define UNUSED(x) (void)(x);

namespace Pistache {

// RAII class for address info
class AddressInfo {
public:
AddressInfo(const char* host, const char* port,
const struct addrinfo& hints, struct addrinfo**addrs) {
addressInfo = addrs;
TRY(::getaddrinfo(host, port, &hints, addressInfo));
}

~AddressInfo() {
freeaddrinfo(*addressInfo);
}

private:
struct addrinfo **addressInfo;
};

namespace Const {

static constexpr int MaxBacklog = 128;
Expand Down
1 change: 1 addition & 0 deletions include/pistache/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class Queue {

virtual ~Queue() {
while (auto *e = pop()) delete e;
delete tail;
}

template<typename U>
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Connection::connect(Address addr)

const auto& host = addr.host();
const auto& port = addr.port().toString();
TRY(::getaddrinfo(host.c_str(), port.c_str(), &hints, &addrs));
AddressInfo addressInfo(host.c_str(), port.c_str(), hints, &addrs);

int sfd = -1;

Expand Down
2 changes: 1 addition & 1 deletion src/server/listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Listener::bind(const Address& address) {
const auto& host = addr_.host();
const auto& port = addr_.port().toString();
struct addrinfo *addrs;
TRY(::getaddrinfo(host.c_str(), port.c_str(), &hints, &addrs));
AddressInfo addressInfo(host.c_str(), port.c_str(), hints, &addrs);

int fd = -1;

Expand Down