X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=ofproto%2Fcollectors.c;h=5b2921236c74de63779350a6264687fa339aeeff;hb=b476e2f21b1f20bd0d24c0522e4d745603599582;hp=58d6abbc3fa666c5dead179904f40634c3f963c0;hpb=d98e60075528c3065ad453f7add4b30f22edcde3;p=cascardo%2Fovs.git diff --git a/ofproto/collectors.c b/ofproto/collectors.c index 58d6abbc3..5b2921236 100644 --- a/ofproto/collectors.c +++ b/ofproto/collectors.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira Networks. + * Copyright (c) 2008, 2009, 2010, 2011, 2013, 2014 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,9 @@ #include #include "socket-util.h" -#include "svec.h" +#include "sset.h" #include "util.h" -#include "vlog.h" +#include "openvswitch/vlog.h" VLOG_DEFINE_THIS_MODULE(collectors); @@ -47,41 +47,35 @@ struct collectors { * added, otherwise to a new collectors object if at least one was successfully * added. Thus, even on a failure return, it is possible that '*collectorsp' * is nonnull, and even on a successful return, it is possible that - * '*collectorsp' is null, if 'target's is an empty svec. */ + * '*collectorsp' is null, if 'target's is an empty sset. */ int -collectors_create(const struct svec *targets_, uint16_t default_port, +collectors_create(const struct sset *targets, uint16_t default_port, struct collectors **collectorsp) { struct collectors *c; - struct svec targets; + const char *name; int retval = 0; - size_t i; - - svec_clone(&targets, targets_); - svec_sort_unique(&targets); c = xmalloc(sizeof *c); - c->fds = xmalloc(sizeof *c->fds * targets.n); + c->fds = xmalloc(sizeof *c->fds * sset_count(targets)); c->n_fds = 0; - for (i = 0; i < targets.n; i++) { - const char *name = targets.names[i]; + SSET_FOR_EACH (name, targets) { int error; int fd; - error = inet_open_active(SOCK_DGRAM, name, default_port, NULL, &fd); + error = inet_open_active(SOCK_DGRAM, name, default_port, NULL, &fd, 0); if (fd >= 0) { c->fds[c->n_fds++] = fd; } else { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); VLOG_WARN_RL(&rl, "couldn't open connection to collector %s (%s)", - name, strerror(error)); + name, ovs_strerror(error)); if (!retval) { retval = error; } } } - svec_destroy(&targets); if (c->n_fds) { *collectorsp = c; @@ -101,7 +95,7 @@ collectors_destroy(struct collectors *c) size_t i; for (i = 0; i < c->n_fds; i++) { - close(c->fds[i]); + closesocket(c->fds[i]); } free(c->fds); free(c); @@ -118,8 +112,10 @@ collectors_send(const struct collectors *c, const void *payload, size_t n) for (i = 0; i < c->n_fds; i++) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); if (send(c->fds[i], payload, n, 0) == -1) { - VLOG_WARN_RL(&rl, "sending to collector failed: %s", - strerror(errno)); + char *s = describe_fd(c->fds[i]); + VLOG_WARN_RL(&rl, "%s: sending to collector failed (%s)", + s, ovs_strerror(errno)); + free(s); } } }