-#ifndef WIN32
-int connect_socket(struct ClientSocket *client) {
- if((client->flags & SOCKET_FLAG_CONNECTED)) return 1;
- int sock;
-
- struct addrinfo hints, *res;
- struct sockaddr_in *ip4 = NULL;
- struct sockaddr_in6 *ip6 = NULL;
- memset (&hints, 0, sizeof (hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags |= AI_CANONNAME;
- if (getaddrinfo (client->host, NULL, &hints, &res)) {
- return 0;
- }
- while (res) {
- switch (res->ai_family) {
- case AF_INET:
- ip4 = (struct sockaddr_in *) res->ai_addr;
- break;
- case AF_INET6:
- ip6 = (struct sockaddr_in6 *) res->ai_addr;
- break;
- }
- res = res->ai_next;
- }
-
- if(ip6) {
- sock = socket(AF_INET6, SOCK_STREAM, 0);
- if(sock == -1) {
- perror("socket() failed");
- return 0;
- }
-
- ip6->sin6_family = AF_INET6;
- ip6->sin6_port = htons(client->port);
-
- struct sockaddr_in6 *ip6vhost = NULL;
- if (client->bind && !getaddrinfo(client->bind, NULL, &hints, &res)) {
- while (res) {
- switch (res->ai_family) {
- case AF_INET6:
- ip6vhost = (struct sockaddr_in6 *) res->ai_addr;
- break;
- }
- res = res->ai_next;
- }
- }
- if(ip6vhost) {
- ip6vhost->sin6_family = AF_INET6;
- ip6vhost->sin6_port = htons(0);
- bind(sock, (struct sockaddr*)ip6vhost, sizeof(*ip6vhost));
- }
-
- if (connect(sock, (struct sockaddr*)ip6, sizeof(*ip6)) == -1) {
- perror("connect() failed");
- return 0;
- }
-
- } else if(ip4) {
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if(sock == -1) {
- perror("socket() failed");
- return 0;
- }
-
- ip4->sin_family = AF_INET;
- ip4->sin_port = htons(client->port);
-
- struct sockaddr_in *ip4vhost = NULL;
- if (client->bind && !getaddrinfo(client->bind, NULL, &hints, &res)) {
- while (res) {
- switch (res->ai_family) {
- case AF_INET:
- ip4vhost = (struct sockaddr_in *) res->ai_addr;
- break;
- }
- res = res->ai_next;
- }
- }
- if(ip4vhost) {
- ip4vhost->sin_family = AF_INET;
- ip4vhost->sin_port = htons(0);
- bind(sock, (struct sockaddr*)ip4vhost, sizeof(*ip4vhost));
- }
+void connect_socket(struct ClientSocket *client) {
+ client->iofd = iohandler_connect(client->host, client->port, ((client->flags & SOCKET_FLAG_SSL) ? 1 : 0), client->bind, socket_callback);
+ client->iofd->data = client;
+ client->flags |= SOCKET_FLAG_RECONNECT;
+}
+
+static int _close_socket(struct ClientSocket *client) {
+ if(client == NULL) return 0;
+ if((client->flags & SOCKET_FLAG_CONNECTED)) {
+ iohandler_printf(client->iofd, "QUIT :[NeonServ %s.%d] disconnect requested.\n", NEONSERV_VERSION, patchlevel);