Skip to content
Open
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
17 changes: 17 additions & 0 deletions src/statsd_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ StatsdClient::StatsdClient(const string& host, int port, const string& ns)
config(host, port, ns);
srandom(time(NULL));
}

StatsdClient::StatsdClient(const StatsdClient &original)
{
// Must create our own storage for ClientData object; don't share original's
d = new _StatsdClientData;
*d = *original.d;

// Don't share original's socket, either.
d->sock = -1;
}

StatsdClient::~StatsdClient()
{
Expand Down Expand Up @@ -84,6 +94,13 @@ int StatsdClient::init()
return -1;
}

// Don't block on stats sends....
int flags = fcntl(d->sock, F_GETFL, 0);
if (fcntl(d->sock, F_SETFL, flags | O_NONBLOCK) == -1) {
snprintf(d->errmsg, sizeof(d->errmsg), "could not enabled non blocking IO, err=%m");
return -1;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not that useful on its own. The code that does the writing must also be modified to handle the situation where it will receive an E_AGAIN. Otherwise you will send part of a message then break out of writing because you would block. You will have to write more code to either continue later or ...

memset(&d->server, 0, sizeof(d->server));
d->server.sin_family = AF_INET;
d->server.sin_port = htons(d->port);
Expand Down
1 change: 1 addition & 0 deletions src/statsd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct _StatsdClientData;
class StatsdClient {
public:
StatsdClient(const std::string& host="127.0.0.1", int port=8125, const std::string& ns = "");
StatsdClient(const StatsdClient &original);
~StatsdClient();

public:
Expand Down