diff --git a/src/node.c b/src/node.c index 0c5db40fb..7cd236c60 100644 --- a/src/node.c +++ b/src/node.c @@ -40,7 +40,7 @@ int node_connect(struct node *n) /* Create socket */ n->sd = socket(AF_INET, SOCK_DGRAM, 0); if (n->sd < 0) - error("Failed to create socket: %s", strerror(errno)); + perror("Failed to create socket"); /* Set socket options */ int prio = SOCKET_PRIO; @@ -49,14 +49,9 @@ int node_connect(struct node *n) /* Bind socket for receiving */ if (bind(n->sd, (struct sockaddr *) &n->local, sizeof(struct sockaddr_in))) - error("Failed to bind socket: %s", strerror(errno)); + perror("Failed to bind to socket"); debug(1, " We listen for node %s at %s:%u", n->name, inet_ntoa(n->local.sin_addr), ntohs(n->local.sin_port)); - - /* Connect socket for sending */ - /*if (connect(n->sd, (struct sockaddr *) &n->remote, sizeof(struct sockaddr_in))) - error("Failed to connect socket: %s", strerror(errno));*/ - debug(1, " We sent to node %s at %s:%u", n->name, inet_ntoa(n->remote.sin_addr), ntohs(n->remote.sin_port)); return 0; diff --git a/src/path.c b/src/path.c index 06873c93c..861da62c7 100644 --- a/src/path.c +++ b/src/path.c @@ -13,8 +13,6 @@ #include "utils.h" #include "path.h" -extern struct config config; - int path_create(struct path *p, struct node *in, struct node *out) { /* Reset counters */ diff --git a/src/send.c b/src/send.c index 3472dffc2..b3759ed72 100644 --- a/src/send.c +++ b/src/send.c @@ -33,14 +33,16 @@ int main(int argc, char *argv[]) struct sockaddr_in sa; if (argc != 2) { - printf("Usage: %s REMOTE\n", argv[0]); - printf(" REMOTE is a IP:PORT combination of the remote host\n\n"); + printf("Usage: %s REMOTE VALUES\n", argv[0]); + printf(" REMOTE is a IP:PORT combination of the remote host\n"); + printf(" VALUES is the number of values to be read from stdin\n\n"); printf("s2ss Simulator2Simulator Server v%s\n", VERSION); printf("Copyright 2014, Institute for Automation of Complex Power Systems, EONERC\n"); exit(EXIT_FAILURE); } const char *remote_str = argv[1]; + int values = atoi(argv[2]); /* Setup signals */ struct sigaction sa_quit = { @@ -63,19 +65,17 @@ int main(int argc, char *argv[]) if (sd < 0) perror("Failed to create socket"); - // TODO: remove workaround - struct msg msg = { - .length = 5 * sizeof(double) - }; - /* Connect socket */ if (connect(sd, (struct sockaddr *) &remote, sizeof(struct sockaddr_in))) perror("Failed to connect socket"); + struct msg m; + m.length = values * sizeof(double); + while (!feof(stdin)) { - msg_fscan(stdin, &msg); - send(sd, &msg, 8 + msg.length, 0); - msg_fprint(stdout, &msg); + msg_fscan(stdin, &m); + send(sd, &m, 8 + m.length, 0); + msg_fprint(stdout, &m); } return 0;