43 printf(
"send message to ZMQ recipient, to use with the zmq filters\n");
44 printf(
"usage: zmqsend [OPTIONS]\n");
47 "-b ADDRESS set bind address\n"
48 "-h print this help\n"
49 "-i INFILE set INFILE as input file, stdin if omitted\n");
52 int main(
int argc,
char **argv)
55 char c, *src_buf, *recv_buf;
56 int recv_buf_size, ret;
57 void *zmq_ctx, *socket;
58 const char *bind_address =
"tcp://localhost:5555";
59 const char *infilename =
NULL;
63 while ((c =
getopt(argc, argv,
"b:hi:")) != -1) {
79 if (!infilename || !strcmp(infilename,
"-")) {
83 infile = fopen(infilename,
"r");
87 "Impossible to open input file '%s': %s\n", infilename, strerror(errno));
91 zmq_ctx = zmq_ctx_new();
94 "Could not create ZMQ context: %s\n", zmq_strerror(errno));
98 socket = zmq_socket(zmq_ctx, ZMQ_REQ);
101 "Could not create ZMQ socket: %s\n", zmq_strerror(errno));
106 if (zmq_connect(socket, bind_address) == -1) {
108 bind_address, zmq_strerror(errno));
115 while ((c = fgetc(infile)) != EOF)
127 if (zmq_send(socket, src_buf, strlen(src_buf), 0) == -1) {
133 if (zmq_msg_init(&msg) == -1) {
135 "Could not initialize receiving message: %s\n", zmq_strerror(errno));
140 if (zmq_msg_recv(&msg, socket, 0) == -1) {
142 "Could not receive message: %s\n", zmq_strerror(errno));
148 recv_buf_size = zmq_msg_size(&msg) + 1;
152 "Could not allocate receiving message buffer\n");
157 memcpy(recv_buf, zmq_msg_data(&msg), recv_buf_size);
158 recv_buf[recv_buf_size-1] = 0;
159 printf(
"%s\n", recv_buf);
165 zmq_ctx_destroy(zmq_ctx);
memory handling functions
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
static av_cold int end(AVCodecContext *avctx)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_BPRINT_SIZE_UNLIMITED
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
static int getopt(int argc, char *argv[], char *opts)
int main(int argc, char **argv)
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.