mirror of
https://github.com/JHUAPL/kvspool.git
synced 2026-01-09 15:37:56 -05:00
npub -f
This commit is contained in:
@@ -158,8 +158,8 @@ int main(int argc, char *argv[]) {
|
|||||||
if ( !(zsocket = zmq_socket(context, pull_mode?ZMQ_PULL:ZMQ_SUB))) goto done;
|
if ( !(zsocket = zmq_socket(context, pull_mode?ZMQ_PULL:ZMQ_SUB))) goto done;
|
||||||
if (remotes_file) if (read_lines(remotes_file,endpoints)) goto done;
|
if (remotes_file) if (read_lines(remotes_file,endpoints)) goto done;
|
||||||
while (optind < argc) utarray_push_back(endpoints,&argv[optind++]);
|
while (optind < argc) utarray_push_back(endpoints,&argv[optind++]);
|
||||||
endpoint=NULL;
|
|
||||||
if (utarray_len(endpoints) == 0) usage(argv[0]);
|
if (utarray_len(endpoints) == 0) usage(argv[0]);
|
||||||
|
endpoint=NULL;
|
||||||
while ( (endpoint=(char**)utarray_next(endpoints,endpoint))) {
|
while ( (endpoint=(char**)utarray_next(endpoints,endpoint))) {
|
||||||
if (verbose) fprintf(stderr,"connecting to %s\n", *endpoint);
|
if (verbose) fprintf(stderr,"connecting to %s\n", *endpoint);
|
||||||
if (zmq_connect(zsocket, *endpoint)) goto done;
|
if (zmq_connect(zsocket, *endpoint)) goto done;
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include "kvspool.h"
|
#include "kvspool.h"
|
||||||
#include "kvsp-bconfig.h"
|
#include "kvsp-bconfig.h"
|
||||||
|
|
||||||
|
char *remotes_file;
|
||||||
char *config_file;
|
char *config_file;
|
||||||
UT_string *tmp;
|
UT_string *tmp;
|
||||||
char *remote; // remote side to which we publish (we do the active open)
|
|
||||||
int sock,eid;
|
int sock,eid;
|
||||||
int verbose;
|
int verbose;
|
||||||
char *spool;
|
char *spool;
|
||||||
@@ -28,11 +28,36 @@ void *set;
|
|||||||
void *sp;
|
void *sp;
|
||||||
|
|
||||||
void usage(char *prog) {
|
void usage(char *prog) {
|
||||||
fprintf(stderr, "usage: %s [-v] -b <cast-config> -d spool <dst-path>\n", prog);
|
fprintf(stderr, "usage: %s [-v] -b <cast-config> -d spool [-f <remotes-file>] [<remote> ...]\n", prog);
|
||||||
fprintf(stderr, " <dst-path> is the nsub peer e.g. tcp://127.0.0.1:1234\n");
|
fprintf(stderr, " <remote> is the nsub peer e.g. tcp://127.0.0.1:1234\n");
|
||||||
exit(-1);
|
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) {
|
int set_to_binary(void *set) {
|
||||||
uint32_t l, u, a,b,c,d,e,f, abcd;
|
uint32_t l, u, a,b,c,d,e,f, abcd;
|
||||||
uint16_t s;
|
uint16_t s;
|
||||||
@@ -117,30 +142,39 @@ int main(int argc, char *argv[]) {
|
|||||||
int opt,rc=-1;
|
int opt,rc=-1;
|
||||||
size_t len;
|
size_t len;
|
||||||
void *buf;
|
void *buf;
|
||||||
|
UT_array *endpoints;
|
||||||
|
char **endpoint;
|
||||||
|
|
||||||
set = kv_set_new();
|
set = kv_set_new();
|
||||||
utarray_new(output_keys, &ut_str_icd);
|
utarray_new(output_keys, &ut_str_icd);
|
||||||
utarray_new(output_defaults, &ut_str_icd);
|
utarray_new(output_defaults, &ut_str_icd);
|
||||||
utarray_new(output_types,&ut_int_icd);
|
utarray_new(output_types,&ut_int_icd);
|
||||||
utstring_new(tmp);
|
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) {
|
switch (opt) {
|
||||||
case 'v': verbose++; break;
|
case 'v': verbose++; break;
|
||||||
case 'd': spool=strdup(optarg); break;
|
case 'd': spool=strdup(optarg); break;
|
||||||
case 'b': config_file=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 (remotes_file) if (read_lines(remotes_file,endpoints)) goto done;
|
||||||
if (!remote) usage(argv[0]);
|
while (optind < argc) utarray_push_back(endpoints,&argv[optind++]);
|
||||||
|
if (utarray_len(endpoints) == 0) usage(argv[0]);
|
||||||
if (spool == NULL) usage(argv[0]);
|
if (spool == NULL) usage(argv[0]);
|
||||||
if (parse_config(config_file) < 0) goto done;
|
if (parse_config(config_file) < 0) goto done;
|
||||||
if ( !(sp = kv_spoolreader_new(spool))) goto done;
|
if ( !(sp = kv_spoolreader_new(spool))) goto done;
|
||||||
rc = -2;
|
rc = -2;
|
||||||
|
|
||||||
if ( (sock = nn_socket(AF_SP, NN_PUSH)) < 0) goto done;
|
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 */
|
while (kv_spool_read(sp,set,1) > 0) { /* read til interrupted by signal */
|
||||||
set_to_binary(set);
|
set_to_binary(set);
|
||||||
@@ -153,14 +187,15 @@ int main(int argc, char *argv[]) {
|
|||||||
rc = 0;
|
rc = 0;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (rc==-2) fprintf(stderr,"nano: %s %s\n", remote, nn_strerror(errno));
|
if (rc==-2) fprintf(stderr,"nano: %s\n", nn_strerror(errno));
|
||||||
if (sock) nn_shutdown(sock,eid);
|
if (sock) nn_close(sock);
|
||||||
if (sp) kv_spoolreader_free(sp);
|
if (sp) kv_spoolreader_free(sp);
|
||||||
kv_set_free(set);
|
kv_set_free(set);
|
||||||
utarray_free(output_keys);
|
utarray_free(output_keys);
|
||||||
utarray_free(output_defaults);
|
utarray_free(output_defaults);
|
||||||
utarray_free(output_types);
|
utarray_free(output_types);
|
||||||
utstring_free(tmp);
|
utstring_free(tmp);
|
||||||
|
utarray_free(endpoints);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user