-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This tries to do as little as possible on top of zeromq, which might not work. It sends an "id" field with each message to keep some state. Probably this should be inherited through the environment. Signed-off-by: Jeff King <[email protected]>
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "cache.h" | ||
#include "dumpstat/dumpstat.h" | ||
|
||
#ifndef DUMPSTAT_ZEROMQ | ||
struct dumpstat_writer *dumpstat_to_zeromq(const char *endpoint) | ||
{ | ||
warning("zeromq dumpstat support not built"); | ||
return NULL; | ||
} | ||
|
||
#else | ||
|
||
#include <zmq.h> | ||
|
||
static char id[256]; | ||
static void *context; | ||
static void *mq; | ||
|
||
static int dumpstat_zeromq_write(const char *buf, size_t len) | ||
{ | ||
zmq_msg_t msg; | ||
|
||
zmq_msg_init_size(&msg, len); | ||
memcpy(zmq_msg_data(&msg), buf, len); | ||
if (zmq_send(mq, &msg, 0) < 0) { | ||
warning("unable to write to zeromq: %s", strerror(errno)); | ||
return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
struct dumpstat_writer *dumpstat_to_zeromq(const char *endpoint) | ||
{ | ||
static struct dumpstat_writer writer = { | ||
dumpstat_zeromq_write | ||
}; | ||
int len; | ||
|
||
len = snprintf(id, sizeof(id), "%d@", (int)getpid()); | ||
if (gethostname(id + len, sizeof(id) - len) < 0) { | ||
warning("unable to gethostname: %s", strerror(errno)); | ||
return NULL; | ||
} | ||
|
||
context = zmq_init(1); | ||
mq = zmq_socket(context, ZMQ_PUB); | ||
if (!mq || zmq_connect(mq, endpoint) < 0) { | ||
warning("unable to open zeromq socket: %s", strerror(errno)); | ||
return NULL; | ||
} | ||
|
||
return &writer; | ||
} | ||
|
||
#endif /* DUMPSTAT_ZEROMQ */ |