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
27 changes: 16 additions & 11 deletions wish/cpp/benchmark/client.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -49,30 +50,34 @@ bool InitConnection(ClientState* client) {
return false;
}

struct sockaddr_in sin;
std::memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(absl::GetFlag(FLAGS_port));

const std::string host = absl::GetFlag(FLAGS_host);

if (inet_pton(AF_INET, host.c_str(), &sin.sin_addr) != 1) {
LOG(ERROR) << "Invalid IPv4 host: " << host;
const std::string port_str = std::to_string(absl::GetFlag(FLAGS_port));

struct addrinfo hints{};
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* res = nullptr;
const int gai_err = getaddrinfo(host.c_str(), port_str.c_str(), &hints, &res);
if (gai_err != 0) {
LOG(ERROR) << "getaddrinfo failed for " << host << ": "
<< gai_strerror(gai_err);
return false;
}

client->bev = bufferevent_socket_new(client->base, -1, BEV_OPT_CLOSE_ON_FREE);
if (!client->bev) {
LOG(ERROR) << "bufferevent_socket_new() failed";
freeaddrinfo(res);
return false;
}

if (bufferevent_socket_connect(client->bev,
reinterpret_cast<struct sockaddr*>(&sin),
sizeof(sin)) < 0) {
if (bufferevent_socket_connect(client->bev, res->ai_addr,
static_cast<int>(res->ai_addrlen)) < 0) {
LOG(ERROR) << "bufferevent_socket_connect() failed";
freeaddrinfo(res);
return false;
}
freeaddrinfo(res);

client->handler = new WishHandler(client->bev, false);
client->handler->SetOnOpen([client]() {
Expand Down
27 changes: 16 additions & 11 deletions wish/cpp/benchmark/high_qps_client.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -167,30 +168,34 @@ bool InitConnection(ClientState* client) {
return false;
}

struct sockaddr_in sin;
std::memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(absl::GetFlag(FLAGS_port));

const std::string host = absl::GetFlag(FLAGS_host);

if (inet_pton(AF_INET, host.c_str(), &sin.sin_addr) != 1) {
LOG(ERROR) << "Invalid IPv4 host: " << host;
const std::string port_str = std::to_string(absl::GetFlag(FLAGS_port));

struct addrinfo hints{};
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* res = nullptr;
const int gai_err = getaddrinfo(host.c_str(), port_str.c_str(), &hints, &res);
if (gai_err != 0) {
LOG(ERROR) << "getaddrinfo failed for " << host << ": "
<< gai_strerror(gai_err);
return false;
}

client->bev = bufferevent_socket_new(client->base, -1, BEV_OPT_CLOSE_ON_FREE);
if (!client->bev) {
LOG(ERROR) << "bufferevent_socket_new() failed";
freeaddrinfo(res);
return false;
}

if (bufferevent_socket_connect(client->bev,
reinterpret_cast<struct sockaddr*>(&sin),
sizeof(sin)) < 0) {
if (bufferevent_socket_connect(client->bev, res->ai_addr,
static_cast<int>(res->ai_addrlen)) < 0) {
LOG(ERROR) << "bufferevent_socket_connect() failed";
freeaddrinfo(res);
return false;
}
freeaddrinfo(res);

client->handler = new WishHandler(client->bev, false);
client->handler->SetOnOpen([client]() {
Expand Down
28 changes: 17 additions & 11 deletions wish/cpp/benchmark/tls_client.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <arpa/inet.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -63,21 +64,24 @@ bool InitConnection(ClientState* client) {
return false;
}

struct sockaddr_in sin;
std::memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(absl::GetFlag(FLAGS_port));

const std::string host = absl::GetFlag(FLAGS_host);

if (inet_pton(AF_INET, host.c_str(), &sin.sin_addr) != 1) {
LOG(ERROR) << "Invalid IPv4 host: " << host;
const std::string port_str = std::to_string(absl::GetFlag(FLAGS_port));

struct addrinfo hints{};
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
struct addrinfo* res = nullptr;
const int gai_err = getaddrinfo(host.c_str(), port_str.c_str(), &hints, &res);
if (gai_err != 0) {
LOG(ERROR) << "getaddrinfo failed for " << host << ": "
<< gai_strerror(gai_err);
return false;
}

SSL* ssl = SSL_new(g_tls_ctx->ssl_ctx());
if (!ssl) {
LOG(ERROR) << "SSL_new() failed";
freeaddrinfo(res);
return false;
}

Expand All @@ -86,15 +90,17 @@ bool InitConnection(ClientState* client) {
if (!client->bev) {
LOG(ERROR) << "bufferevent_openssl_socket_new() failed";
SSL_free(ssl);
freeaddrinfo(res);
return false;
}

if (bufferevent_socket_connect(client->bev,
reinterpret_cast<struct sockaddr*>(&sin),
sizeof(sin)) < 0) {
if (bufferevent_socket_connect(client->bev, res->ai_addr,
static_cast<int>(res->ai_addrlen)) < 0) {
LOG(ERROR) << "bufferevent_socket_connect() failed";
freeaddrinfo(res);
return false;
}
freeaddrinfo(res);

client->handler = new WishHandler(client->bev, false);
client->handler->SetOnOpen([client]() {
Expand Down