7#include "timeoutconn.h"
11static struct taia now;
12static struct taia deadline;
14static int mywrite(
int fd,
char *
buf,
int len)
20 x.events = IOPAUSE_WRITE;
23 r = iopause(&x,1,&deadline,&now);
24 if (r > 0 && x.revents)
break;
25 if (taia_less(&deadline,&now)) {
30 return write(fd,
buf,len);
33static int myread(
int fd,
char *
buf,
int len)
39 x.events = IOPAUSE_READ;
42 r = iopause(&x,1,&deadline,&now);
43 if (r > 0 && x.revents)
break;
44 if (taia_less(&deadline,&now)) {
49 return read(fd,
buf,len);
56 char strnum[FMT_ULONG];
63 buffer_init(&
b,(ssize_t (*)())mywrite,s,
bspace,
sizeof(
bspace));
65 buffer_put(&
b,
" , ",3);
66 buffer_put(&
b,strnum,fmt_ulong(strnum,
portlocal));
67 buffer_put(&
b,
"\r\n",2);
68 if (buffer_flush(&
b) == -1)
return -1;
70 buffer_init(&
b,(ssize_t (*)())myread,s,
bspace,
sizeof(
bspace));
73 if (buffer_get(&
b,&ch,1) != 1)
return -1;
74 if ((ch ==
' ') || (ch ==
'\t') || (ch ==
'\r'))
continue;
75 if (ch ==
'\n')
return 0;
77 if (ch ==
':') ++numcolons;
80 if (!stralloc_append(out,&ch))
return -1;
81 if (out->len > 256)
return 0;
91 if (!stralloc_copys(out,
""))
return -1;
95 taia_add(&deadline,&now,&deadline);
98 if (s == -1)
return -1;
char bspace[BUFFER_SMALL]
int remoteinfo(stralloc *out, char ipremote[16], uint16 portremote, char iplocal[16], uint16 portlocal, unsigned int timeout, uint32 netif)