#endif
#if defined(SOL_TCP) && defined(TCP_NODELAY)
- option = 1;
- setsockopt(c->socket, SOL_TCP, TCP_NODELAY, (void *)&option, sizeof option);
+ int nodelay = 1;
+ setsockopt(c->socket, SOL_TCP, TCP_NODELAY, (void *)&nodelay, sizeof nodelay);
#endif
#if defined(SOL_IP) && defined(IP_TOS) && defined(IPTOS_LOWDELAY)
- option = IPTOS_LOWDELAY;
- setsockopt(c->socket, SOL_IP, IP_TOS, (void *)&option, sizeof option);
+ int lowdelay = IPTOS_LOWDELAY;
+ setsockopt(c->socket, SOL_IP, IP_TOS, (void *)&lowdelay, sizeof lowdelay);
#endif
}
if(c->outbuf.len <= c->outbuf.offset)
return;
- ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, 0);
+ ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, MSG_NOSIGNAL);
if(outlen <= 0) {
if(!errno || errno == EPIPE) {
logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection closed by %s (%s)", c->name, c->hostname);
*space = 0;
} else {
// TODO: Only allow Address statements?
- if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port))
- port = xstrdup("655");
+ if(!get_config_string(lookup_config(outgoing->config_tree, "Port"), &port)) {
+ logger(DEBUG_CONNECTIONS, LOG_ERR, "No Port known for %s", outgoing->name);
+ retry_outgoing(mesh, outgoing);
+ return false;
+ }
}
outgoing->ai = str2addrinfo(address, port, SOCK_STREAM);
}
void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) {
+ bool blacklisted = false;
timeout_del(&mesh->loop, &outgoing->ev);
node_t *n = lookup_node(mesh, outgoing->name);
read_host_config(mesh, outgoing->config_tree, outgoing->name);
outgoing->cfg = lookup_config(outgoing->config_tree, "Address");
+ get_config_bool(lookup_config(outgoing->config_tree, "blacklisted"), &blacklisted);
+ if (blacklisted) return;
+
if(!outgoing->cfg) {
if(n)
outgoing->aip = outgoing->ai = get_known_addresses(n);
send_id(mesh, c);
}
-static void free_outgoing(meshlink_handle_t *mesh, outgoing_t *outgoing) {
+static void free_outgoing(outgoing_t *outgoing) {
+ meshlink_handle_t *mesh = outgoing->mesh;
+
timeout_del(&mesh->loop, &outgoing->ev);
if(outgoing->ai)
// TODO: Drop support for ConnectTo since AutoConnect is now always on?
for(config_t *cfg = lookup_config(mesh->config, "ConnectTo"); cfg; cfg = lookup_config_next(mesh->config, cfg)) {
char *name;
- bool blacklisted;
get_config_string(cfg, &name);
if(!check_id(name)) {
continue;
}
- get_config_bool(lookup_config(mesh->config, "blacklisted"), &blacklisted);
- if (blacklisted)
- continue;
-
bool found = false;
for list_each(outgoing_t, outgoing, mesh->outgoings) {
if(!found) {
outgoing_t *outgoing = xzalloc(sizeof *outgoing);
+ outgoing->mesh = mesh;
outgoing->name = name;
list_insert_tail(mesh->outgoings, outgoing);
setup_outgoing_connection(mesh, outgoing);