From 92ed4b47099bc8357f527a02f6810ea5fc2c6a24 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 5 Jun 2014 09:35:04 +0000 Subject: [PATCH] simplified code git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@35 8ec27952-4edc-4aab-86aa-e87bb2611832 --- include/node.h | 10 ---------- include/path.h | 19 +------------------ src/path.c | 22 +++------------------- src/random.c | 16 ---------------- src/send.c | 2 +- 5 files changed, 5 insertions(+), 64 deletions(-) diff --git a/include/node.h b/include/node.h index b0c799ec7..1f522944f 100644 --- a/include/node.h +++ b/include/node.h @@ -32,9 +32,6 @@ struct node /// The socket descriptor int sd; - /// Reference counter - int ref_cnt; - // Local address of the socket struct sockaddr_in local; @@ -65,13 +62,6 @@ struct msg; /* forward decl */ int node_create(struct node *n, const char *name, enum node_type type, struct sockaddr_in local, struct sockaddr_in remote); -/** - * @brief Delete a node created by node_create() - * - * @param p A pointer to the node struct - */ -void node_destroy(struct node *n); - /** * @brief Connect and bind the UDP socket of this node * diff --git a/include/path.h b/include/path.h index 2f0421c0c..9cdcf8158 100644 --- a/include/path.h +++ b/include/path.h @@ -14,14 +14,6 @@ #include "node.h" #include "msg.h" -enum path_state -{ - UNKNOWN, - CONNECTED, - RUNNING, - STOPPED -}; - /** * @brief The datastructure for a path */ @@ -53,9 +45,7 @@ struct path }; /** - * @brief Create a new path - * - * Memory is allocated dynamically and has to be freed by path_destroy() + * @brief Setup a new path * * @param p A pointer to the path structure * @param in The node we are receiving messages from @@ -67,13 +57,6 @@ struct path */ int path_create(struct path *p, struct node *in, struct node *out); -/** - * @brief Delete a path created by path_create() - * - * @param p A pointer to the path struct - */ -void path_destroy(struct path *p); - /** * @brief Start a path * diff --git a/src/path.c b/src/path.c index 0bca8f3c0..60ba4e072 100644 --- a/src/path.c +++ b/src/path.c @@ -25,22 +25,13 @@ int path_create(struct path *p, struct node *in, struct node *out) return 0; } -void path_destroy(struct path *p) -{ - assert(p); -} - static void * path_run(void *arg) { struct path *p = (struct path *) arg; struct msg m; - assert(p); - - debug(1, "Established path: %12s => %s => %-12s", p->in->name, config.name, p->out->name); - /* main thread loop */ - while (p->state == RUNNING) { + while (1) { /* Receive message */ msg_recv(&m, p->in); @@ -70,22 +61,15 @@ static void * path_run(void *arg) int path_start(struct path *p) { - assert(p); - - p->state = RUNNING; pthread_create(&p->tid, NULL, &path_run, (void *) p); } int path_stop(struct path *p) { - void * ret; - - assert(p); - - p->state = STOPPED; + void *ret; pthread_cancel(p->tid); pthread_join(p->tid, &ret); - return 0; // TODO + return 0; } diff --git a/src/random.c b/src/random.c index 8206b7cb8..be0451c1e 100644 --- a/src/random.c +++ b/src/random.c @@ -21,12 +21,6 @@ #define CLOCKID CLOCK_REALTIME #define SIG SIGRTMIN -void quit(int sig, siginfo_t *si, void *ptr) -{ - debug(1, "Good night"); - exit(EXIT_SUCCESS); -} - void tick(int sig, siginfo_t *si, void *ptr) { struct msg *m = (struct msg*) si->si_value.sival_ptr; @@ -62,17 +56,7 @@ int main(int argc, char *argv[]) .sa_sigaction = tick }; - struct sigaction sa_quit = { - .sa_flags = SA_SIGINFO, - .sa_sigaction = quit - }; - sigemptyset(&sa_tick.sa_mask); - sigemptyset(&sa_quit.sa_mask); - - if (sigaction(SIGINT, &sa_quit, NULL)) { - error("Failed sigaction(): %s", strerror(errno)); - } if (sigaction(SIG, &sa_tick, NULL)) { error("Failed sigaction(): %s", strerror(errno)); diff --git a/src/send.c b/src/send.c index db8ea3de4..ad4a1e233 100644 --- a/src/send.c +++ b/src/send.c @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) while (!feof(stdin)) { msg_fscan(stdin, &msg); - msg_fprint(stdout, &msg); send(sd, &msg, 8 + msg.length, 0); + msg_fprint(stdout, &msg); } return 0;