This commit is contained in:
Troy D. Hanson
2016-07-12 22:41:29 -04:00
parent a86dde9b65
commit 6665d727dc
2 changed files with 46 additions and 11 deletions

View File

@@ -158,8 +158,8 @@ int main(int argc, char *argv[]) {
if ( !(zsocket = zmq_socket(context, pull_mode?ZMQ_PULL:ZMQ_SUB))) goto done;
if (remotes_file) if (read_lines(remotes_file,endpoints)) goto done;
while (optind < argc) utarray_push_back(endpoints,&argv[optind++]);
endpoint=NULL;
if (utarray_len(endpoints) == 0) usage(argv[0]);
endpoint=NULL;
while ( (endpoint=(char**)utarray_next(endpoints,endpoint))) {
if (verbose) fprintf(stderr,"connecting to %s\n", *endpoint);
if (zmq_connect(zsocket, *endpoint)) goto done;

View File

@@ -18,9 +18,9 @@
#include "kvspool.h"
#include "kvsp-bconfig.h"
char *remotes_file;
char *config_file;
UT_string *tmp;
char *remote; // remote side to which we publish (we do the active open)
int sock,eid;
int verbose;
char *spool;
@@ -28,11 +28,36 @@ void *set;
void *sp;
void usage(char *prog) {
fprintf(stderr, "usage: %s [-v] -b <cast-config> -d spool <dst-path>\n", prog);
fprintf(stderr, " <dst-path> is the nsub peer e.g. tcp://127.0.0.1:1234\n");
fprintf(stderr, "usage: %s [-v] -b <cast-config> -d spool [-f <remotes-file>] [<remote> ...]\n", prog);
fprintf(stderr, " <remote> is the nsub peer e.g. tcp://127.0.0.1:1234\n");
exit(-1);
}
int read_lines(char *file, UT_array *lines) {
char line[200];
int rc = -1;
char *c;
FILE *f = fopen(file,"r");
if (f==NULL) {
fprintf(stderr,"fopen %s: %s\n", file, strerror(errno));
goto done;
}
while (fgets(line,sizeof(line),f) != NULL) {
for(c=line; (c < line+sizeof(line)) && (*c != '\0'); c++) {
if (*c == '\n') *c='\0';
if (*c == ' ') *c='\0';
}
c = line;
if (strlen(c) == 0) continue;
utarray_push_back(lines,&c);
}
rc = 0;
done:
if (f) fclose(f);
return rc;
}
int set_to_binary(void *set) {
uint32_t l, u, a,b,c,d,e,f, abcd;
uint16_t s;
@@ -117,30 +142,39 @@ int main(int argc, char *argv[]) {
int opt,rc=-1;
size_t len;
void *buf;
UT_array *endpoints;
char **endpoint;
set = kv_set_new();
utarray_new(output_keys, &ut_str_icd);
utarray_new(output_defaults, &ut_str_icd);
utarray_new(output_types,&ut_int_icd);
utstring_new(tmp);
utarray_new(endpoints,&ut_str_icd);
while ( (opt = getopt(argc, argv, "v+d:b:")) != -1) {
while ( (opt = getopt(argc, argv, "v+d:b:f:h")) != -1) {
switch (opt) {
case 'v': verbose++; break;
case 'd': spool=strdup(optarg); break;
case 'b': config_file=strdup(optarg); break;
default: usage(argv[0]); break;
case 'f': remotes_file=strdup(optarg); break;
case 'h': default: usage(argv[0]); break;
}
}
if (optind < argc) remote = argv[optind++];
if (!remote) usage(argv[0]);
if (remotes_file) if (read_lines(remotes_file,endpoints)) goto done;
while (optind < argc) utarray_push_back(endpoints,&argv[optind++]);
if (utarray_len(endpoints) == 0) usage(argv[0]);
if (spool == NULL) usage(argv[0]);
if (parse_config(config_file) < 0) goto done;
if ( !(sp = kv_spoolreader_new(spool))) goto done;
rc = -2;
if ( (sock = nn_socket(AF_SP, NN_PUSH)) < 0) goto done;
if ( (eid = nn_connect(sock, remote)) < 0) goto done;
endpoint=NULL;
while ( (endpoint=(char**)utarray_next(endpoints,endpoint))) {
if (verbose) fprintf(stderr,"connecting to %s\n", *endpoint);
if ( (eid = nn_connect(sock, *endpoint)) < 0) goto done;
}
while (kv_spool_read(sp,set,1) > 0) { /* read til interrupted by signal */
set_to_binary(set);
@@ -153,14 +187,15 @@ int main(int argc, char *argv[]) {
rc = 0;
done:
if (rc==-2) fprintf(stderr,"nano: %s %s\n", remote, nn_strerror(errno));
if (sock) nn_shutdown(sock,eid);
if (rc==-2) fprintf(stderr,"nano: %s\n", nn_strerror(errno));
if (sock) nn_close(sock);
if (sp) kv_spoolreader_free(sp);
kv_set_free(set);
utarray_free(output_keys);
utarray_free(output_defaults);
utarray_free(output_types);
utstring_free(tmp);
utarray_free(endpoints);
return 0;
}