int flags = fcntl(c->socket, F_GETFL);
if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0)
- logger(c->mesh, MESHLINK_ERROR, "fcntl for %s: %s", c->hostname, strerror(errno));
+ logger(c->mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "fcntl", strerror(errno));
#elif defined(WIN32)
unsigned long arg = 1;
if(ioctlsocket(c->socket, FIONBIO, &arg) != 0)
- logger(c->mesh, MESHLINK_ERROR, "ioctlsocket for %s: %s", c->hostname, sockstrerror(sockerrno));
+ logger(c->mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "ioctlsocket", sockstrerror(sockerrno));
#endif
#if defined(SOL_TCP) && defined(TCP_NODELAY)
}
void finish_connecting(meshlink_handle_t *mesh, connection_t *c) {
- logger(mesh, MESHLINK_INFO, "Connected to %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Connected to %s", c->name);
c->last_ping_time = mesh->loop.now.tv_sec;
c->status.connecting = false;
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(mesh, MESHLINK_INFO, "Connection closed by %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Connection closed by %s", c->name);
else if(sockwouldblock(sockerrno)) {
- logger(mesh, MESHLINK_DEBUG, "Sending %d bytes to %s (%s) would block", c->outbuf.len - c->outbuf.offset, c->name, c->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Sending %d bytes to %s would block", c->outbuf.len - c->outbuf.offset, c->name);
return;
} else
- logger(mesh, MESHLINK_ERROR, "Could not send %d bytes of data to %s (%s): %s", c->outbuf.len - c->outbuf.offset, c->name, c->hostname, strerror(errno));
+ logger(mesh, MESHLINK_ERROR, "Could not send %d bytes of data to %s: %s", c->outbuf.len - c->outbuf.offset, c->name, strerror(errno));
terminate_connection(mesh, c, c->status.active);
return;
if(!result)
finish_connecting(mesh, c);
else {
- logger(mesh, MESHLINK_DEBUG, "Error while connecting to %s (%s): %s", c->name, c->hostname, sockstrerror(result));
+ logger(mesh, MESHLINK_DEBUG, "Error while connecting to %s: %s", c->name, sockstrerror(result));
terminate_connection(mesh, c, false);
return;
}
memcpy(&c->address, outgoing->aip->ai_addr, outgoing->aip->ai_addrlen);
outgoing->aip = outgoing->aip->ai_next;
- c->hostname = sockaddr2hostname(&c->address);
+ char *hostname = sockaddr2hostname(&c->address);
- logger(mesh, MESHLINK_INFO, "Trying to connect to %s (%s)", outgoing->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Trying to connect to %s at %s", outgoing->name, hostname);
if(!mesh->proxytype) {
c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
proxyai = str2addrinfo(mesh->proxyhost, mesh->proxyport, SOCK_STREAM);
if(!proxyai) {
free_connection(c);
+ free(hostname);
goto begin;
}
logger(mesh, MESHLINK_INFO, "Using proxy at %s port %s", mesh->proxyhost, mesh->proxyport);
}
if(c->socket == -1) {
- logger(mesh, MESHLINK_ERROR, "Creating socket for %s failed: %s", c->hostname, sockstrerror(sockerrno));
+ logger(mesh, MESHLINK_ERROR, "Creating socket for %s at %s failed: %s", c->name, c->hostname, sockstrerror(sockerrno));
free_connection(c);
+ free(hostname);
goto begin;
}
+ free(hostname);
+
#ifdef FD_CLOEXEC
fcntl(c->socket, F_SETFD, FD_CLOEXEC);
#endif
}
if(result == -1 && !sockinprogress(sockerrno)) {
- logger(mesh, MESHLINK_ERROR, "Could not connect to %s (%s): %s", outgoing->name, c->hostname, sockstrerror(sockerrno));
+ logger(mesh, MESHLINK_ERROR, "Could not connect to %s: %s", outgoing->name, sockstrerror(sockerrno));
free_connection(c);
goto begin;
c->outcompression = mesh->self->connection->outcompression;
c->address = sa;
- c->hostname = sockaddr2hostname(&sa);
c->socket = fd;
c->last_ping_time = mesh->loop.now.tv_sec;
+ char *hostname = sockaddr2hostname(&sa);
logger(mesh, MESHLINK_INFO, "Connection from %s", c->hostname);
+ free(hostname);
io_add(&mesh->loop, &c->io, handle_meta_io, c, c->socket, IO_READ);