+ if (client_ == -1 && host != NULL && port != NULL) {
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = 0;
+ hints.ai_flags = 0;
+
+ struct addrinfo *infos;
+ _syscall(getaddrinfo(host, port, &hints, &infos));
+
+ _assert(infos != NULL); try {
+ for (struct addrinfo *info(infos); info != NULL; info = info->ai_next) {
+ int client(_syscall(socket(info->ai_family, info->ai_socktype, info->ai_protocol))); try {
+ _syscall(connect(client, info->ai_addr, info->ai_addrlen));
+ client_ = client;
+ break;
+ } catch (...) {
+ _syscall(close(client));
+ throw;
+ }
+ }
+ } catch (...) {
+ freeaddrinfo(infos);
+ throw;
+ }
+ }
+