35 #define T_INACTIVITY 120 41 static char *tcp_prefix(
char *);
42 static char *udp_prefix(
char *);
43 static char *unix_prefix(
char *);
50 inet_client_connect(node, service, socktype, client, to)
58 struct addrinfo hints;
59 struct addrinfo *addrinfo, *rp;
62 ASSERT(node != NULL || service != NULL);
64 if (socktype != SOCK_STREAM && socktype != SOCK_DGRAM)
65 socktype = SOCK_STREAM;
69 socktype == SOCK_STREAM ?
"tcp" :
"udp");
71 memset(&hints, 0,
sizeof (
struct addrinfo));
72 hints.ai_family = AF_UNSPEC;
73 hints.ai_socktype = socktype;
74 hints.ai_flags = AI_PASSIVE;
75 hints.ai_protocol = 0;
77 s = getaddrinfo(node, service, &hints, &addrinfo);
84 for (rp = addrinfo; rp != NULL; rp = rp->ai_next)
86 sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
90 if (
connect_timed(sfd, rp->ai_addr, rp->ai_addrlen, to) != -1)
97 if (rp == NULL || sfd < 0)
99 freeaddrinfo(addrinfo);
103 if (client != NULL && rp != NULL)
105 client->
family = rp->ai_family;
114 freeaddrinfo(addrinfo);
139 if ((spec == NULL) || (strlen(spec) == 0))
142 strlcpy(sbuf, spec,
sizeof (sbuf));
145 for (i = 0; i < sargc; i++)
149 if ((s = tcp_prefix(sargv[i])) != NULL)
151 char sport[32], shost[128];
156 p = sargv[i] + strlen(s);
158 memset(sport, 0,
sizeof (sport));
159 memset(shost, 0,
sizeof (shost));
161 strlcpy(tbuf, p,
sizeof (tbuf));
167 strlcpy(sport, argv[0],
sizeof (sport));
169 strlcpy(shost, argv[1],
sizeof (shost));
171 strlcpy(shost,
"127.0.0.1",
sizeof (shost));
173 ZE_MessageInfo(10,
"Connecting to inet server [%s] on port [%s/tcp]",
176 fd = inet_client_connect(shost, sport, SOCK_STREAM, client, to);
235 if (client != NULL) {
238 shutdown(client->
sd, SHUT_RDWR);
305 n = sendto(client->
sd, p, sz - 1, 0, NULL, 0);
367 if (buf == NULL || size <= 0)
370 memset(buf, 0, size);
390 result = (strlen(buf) > 0);
399 n = recvfrom(client->
sd, p, sz, 0, NULL, NULL);
459 if (buf == NULL || size <= 0)
462 memset(buf, 0, size);
482 result = (strlen(buf) > 0);
491 n = recvfrom(client->
sd, p, 1, MSG_DONTWAIT, NULL, NULL);
512 if (errno == EINTR || errno == EAGAIN)
579 sz = recvfrom(sd, buf,
sizeof (buf), 0, NULL, NULL);
617 set_errors_count(client,
ok)
626 client->lasterr = (time_t) 0;
641 struct sockaddr *sock;
650 if ((flags = fcntl(sockfd, F_GETFL, 0)) < 0)
658 if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) < 0)
667 if ((n = connect(sockfd, sock, socklen)) < 0)
669 if (errno != EINPROGRESS)
680 FD_SET(sockfd, &rset);
686 if ((n = select(sockfd + 1, &rset, &wset, NULL, &tval)) == 0)
695 if (FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset))
697 len =
sizeof (error);
698 if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
710 if (fcntl(sockfd, F_SETFL, flags) < 0)
731 #define STRPREFIX(s,pfx) STRNCASEEQUAL((s),(pfx),strlen(pfx))
#define STRPREFIX(s, pfx)
bool client_send(client_T *client, char *buf, size_t size)
int jfd_ready(int, bool, long)
#define ZE_LogMsgError(level,...)
char spec[CLIENT_SPEC_LEN]
int zeStr2Tokens(char *, int, char **, char *)
int connect_timed(int sockfd, struct sockaddr *sock, socklen_t socklen, int to)
#define ZE_MessageInfo(level,...)
#define ZE_LogSysError(...)
bool client_disconnect(client_T *client, bool incerr)
int client_connect(client_T *client, char *spec, int to)
bool client_recv(client_T *client, char *buf, size_t size)
bool client_flush_read(client_T *client)
bool client_readln(client_T *client, char *buf, size_t size)
bool client_check_state(client_T *client)