111 if (revents & POLLOUT && !(con->
events & POLLOUT) &&
123 con->
events&= (short)~revents;
238 const char *password)
248 if (password == NULL)
309 major= (uint32_t)strtoul(current, &end, 10);
311 minor= (uint32_t)strtoul(current, &end, 10);
313 version= (uint32_t)strtoul(current, &end, 10);
315 return (major * 10000) + (minor * 100) + version;
394 db, strlen(db), strlen(db), ret_ptr);
445 const void *data,
size_t size,
454 "connection not ready");
535 uint8_t protocol_version)
541 const char *server_version)
543 if (server_version == NULL)
560 if (scramble == NULL)
586 uint32_t max_packet_size)
608 size_t *size,
size_t *total,
638 uint8_t *command_data;
647 if (command_data == NULL)
666 while ((offset + size) != (*total))
678 command_data[*total]= 0;
718 char port[NI_MAXSERV];
736 snprintf(port, NI_MAXSERV,
"%u", tcp->
port);
742 memset(&ai, 0,
sizeof(
struct addrinfo));
743 ai.ai_socktype= SOCK_STREAM;
744 ai.ai_protocol= IPPROTO_TCP;
748 ai.ai_flags = AI_PASSIVE;
749 ai.ai_family = AF_UNSPEC;
754 if (tcp->
host == NULL)
760 ret= getaddrinfo(host, port, &ai, &(tcp->
addrinfo));
764 "getaddrinfo:%s", gai_strerror(ret));
793 (void)close(con->
fd);
800 "could not connect");
836 if (errno == EAGAIN || errno == EINTR)
839 if (errno == EINPROGRESS)
846 if (errno == ECONNREFUSED || errno == ENETUNREACH || errno == ETIMEDOUT)
875 else if (con->
revents & (POLLERR | POLLHUP | POLLNVAL))
925 "lost connection to server (EOF)");
928 else if (read_size == -1)
945 else if (errno == ECONNREFUSED)
953 else if (errno == EINTR)
955 else if (errno == EPIPE || errno == ECONNRESET)
958 "lost connection to server (%d)", errno);
992 "lost connection to server (EOF)");
995 else if (write_size == -1)
1012 else if (errno == EINTR)
1014 else if (errno == EPIPE || errno == ECONNRESET)
1017 "lost connection to server (%d)", errno);
1040 char host[NI_MAXHOST];
1041 char port[NI_MAXSERV];
1052 NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV);
1072 ret= setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt,
sizeof(opt));
1086 if (errno == EADDRINUSE)
1100 if (listen(fd, con->
backlog) == -1)
1116 if (new_con == NULL)
1151 struct linger linger;
1152 struct timeval waittime;
1155 ret= setsockopt(con->
fd, IPPROTO_TCP, TCP_NODELAY, &ret,
1156 (socklen_t)
sizeof(
int));
1157 if (ret == -1 && errno != EOPNOTSUPP)
1160 "setsockopt:TCP_NODELAY:%d", errno);
1166 ret= setsockopt(con->
fd, SOL_SOCKET, SO_LINGER, &linger,
1167 (socklen_t)
sizeof(
struct linger));
1171 "setsockopt:SO_LINGER:%d", errno);
1176 waittime.tv_usec= 0;
1177 ret= setsockopt(con->
fd, SOL_SOCKET, SO_SNDTIMEO, &waittime,
1178 (socklen_t)
sizeof(
struct timeval));
1179 if (ret == -1 && errno != ENOPROTOOPT)
1182 "setsockopt:SO_SNDTIMEO:%d", errno);
1186 ret= setsockopt(con->
fd, SOL_SOCKET, SO_RCVTIMEO, &waittime,
1187 (socklen_t)
sizeof(
struct timeval));
1188 if (ret == -1 && errno != ENOPROTOOPT)
1191 "setsockopt:SO_RCVTIMEO:%d", errno);
1196 ret= setsockopt(con->
fd, SOL_SOCKET, SO_SNDBUF, &ret, (socklen_t)
sizeof(
int));
1200 "setsockopt:SO_SNDBUF:%d", errno);
1205 ret= setsockopt(con->
fd, SOL_SOCKET, SO_RCVBUF, &ret, (socklen_t)
sizeof(
int));
1209 "setsockopt:SO_RCVBUF:%d", errno);
1213 ret= fcntl(con->
fd, F_GETFL, 0);
1221 ret= fcntl(con->
fd, F_SETFL, ret | O_NONBLOCK);