-begin:
- if(!c->outgoing->ai) {
- if(!c->outgoing->cfg) {
- ifdebug(CONNECTIONS) logger(LOG_ERR, "Could not set up a meta connection to %s",
- c->name);
- c->status.remove = true;
- retry_outgoing(c->outgoing);
- c->outgoing = NULL;
+ buffer_read(&c->outbuf, outlen);
+
+ if(!c->outbuf.len) {
+ io_set(&mesh->loop, &c->io, IO_READ);
+ }
+}
+
+static void handle_meta_io(event_loop_t *loop, void *data, int flags) {
+ meshlink_handle_t *mesh = loop->data;
+ connection_t *c = data;
+
+ if(c->status.connecting) {
+ c->status.connecting = false;
+
+ int result;
+ socklen_t len = sizeof(result);
+ getsockopt(c->socket, SOL_SOCKET, SO_ERROR, (void *)&result, &len);
+
+ if(!result) {
+ finish_connecting(mesh, c);
+ } else {
+ logger(mesh, MESHLINK_DEBUG, "Error while connecting to %s: %s", c->name, sockstrerror(result));
+ terminate_connection(mesh, c, false);