9 static FILE *Toutputfile;
10 void Tshutdown(void) {
12 static void R_recordtime(void) {
14 struct timeval tv, tvrel;
16 r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin");
17 tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec;
18 tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec;
19 if (tv.tv_usec < 0) { tvrel.tv_usec += 1000000; tvrel.tv_sec--; }
20 Tvbf("\n +%ld.%06ld",(long)tvrel.tv_sec,(long)tvrel.tv_usec);
23 void Tensurerecordfile(void) {
26 if (Toutputfile) return;
28 fdstr= getenv("ADNS_TEST_OUT_FD");
31 Toutputfile= fdopen(fd,"a"); if (!Toutputfile) Tfailed("fdopen ADNS_TEST_OUT_FD");
33 r= gettimeofday(¤ttime,0); if (r) Tfailed("gettimeofday syscallbegin");
34 if (fprintf(Toutputfile," start %ld.%06ld\n",
35 (long)currenttime.tv_sec,(long)currenttime.tv_usec) == EOF) Toutputerr();
38 if (!adns__vbuf_append(&vb,"",1)) Tnomem();
40 if (fprintf(Toutputfile," %s\n",vb.buf) == EOF) Toutputerr();
41 if (fflush(Toutputfile)) Toutputerr();
43 static void R_vb(void) {
46 int Hselect( int max , fd_set *rfds , fd_set *wfds , fd_set *efds , struct timeval *to ) {
48 Qselect( max , rfds , wfds , efds , to );
49 r= select( max , rfds , wfds , efds , to );
53 if (r==-1) { Tvberrno(e); goto x_error; }
55 Tvba(" rfds="); Tvbfdset(max,rfds);
56 Tvba(" wfds="); Tvbfdset(max,wfds);
57 Tvba(" efds="); Tvbfdset(max,efds);
65 int Hpoll( struct pollfd *fds , int nfds , int timeout ) {
67 Qpoll( fds , nfds , timeout );
68 r= poll( fds , nfds , timeout );
72 if (r==-1) { Tvberrno(e); goto x_error; }
74 Tvba(" fds="); Tvbpollfds(fds,nfds);
82 int Hsocket( int domain , int type , int protocol ) {
84 Tmust("socket","domain",domain==AF_INET);
85 Tmust("socket","type",type==SOCK_STREAM || type==SOCK_DGRAM);
87 r= socket( domain , type , protocol );
91 if (r==-1) { Tvberrno(e); goto x_error; }
99 int Hfcntl( int fd , int cmd , ... ) {
101 va_list al; long arg;
102 Tmust("fcntl","cmd",cmd==F_SETFL || cmd==F_GETFL);
103 if (cmd == F_SETFL) {
104 va_start(al,cmd); arg= va_arg(al,long); va_end(al);
108 Qfcntl( fd , cmd , arg );
109 r= fcntl( fd , cmd , arg );
113 if (r==-1) { Tvberrno(e); goto x_error; }
114 if (cmd == F_GETFL) {
115 Tvbf(r & O_NONBLOCK ? "O_NONBLOCK|..." : "~O_NONBLOCK&...");
117 if (cmd == F_SETFL) {
118 Tmust("fcntl","return",!r);
120 Tmust("cmd","F_GETFL/F_SETFL",0);
130 int Hconnect( int fd , const struct sockaddr *addr , int addrlen ) {
132 Qconnect( fd , addr , addrlen );
133 r= connect( fd , addr , addrlen );
137 if (r) { Tvberrno(e); goto x_error; }
145 int Hbind( int fd , const struct sockaddr *addr , int addrlen ) {
147 Qbind( fd , addr , addrlen );
148 r= bind( fd , addr , addrlen );
152 if (r) { Tvberrno(e); goto x_error; }
160 int Hlisten( int fd , int backlog ) {
162 Qlisten( fd , backlog );
163 r= listen( fd , backlog );
167 if (r) { Tvberrno(e); goto x_error; }
175 int Hclose( int fd ) {
182 if (r) { Tvberrno(e); goto x_error; }
190 int Hsendto( int fd , const void *msg , int msglen , unsigned int flags , const struct sockaddr *addr , int addrlen ) {
192 Tmust("sendto","flags",flags==0);
193 Qsendto( fd , msg , msglen , addr , addrlen );
194 r= sendto( fd , msg , msglen , flags , addr , addrlen );
198 if (r==-1) { Tvberrno(e); goto x_error; }
206 int Hrecvfrom( int fd , void *buf , int buflen , unsigned int flags , struct sockaddr *addr , int *addrlen ) {
208 Tmust("recvfrom","flags",flags==0);
209 Tmust("recvfrom","*addrlen",*addrlen>=sizeof(struct sockaddr_in));
210 Qrecvfrom( fd , buflen , *addrlen );
211 r= recvfrom( fd , buf , buflen , flags , addr , addrlen );
215 if (r==-1) { Tvberrno(e); goto x_error; }
216 Tmust("recvfrom","return",r<=buflen);
218 Tvba(" addr="); Tvbaddr(addr,*addrlen);
226 int Hread( int fd , void *buf , size_t buflen ) {
228 Qread( fd , buflen );
229 r= read( fd , buf , buflen );
233 if (r==-1) { Tvberrno(e); goto x_error; }
234 Tmust("read","return",r<=buflen);
243 int Hwrite( int fd , const void *buf , size_t len ) {
245 Qwrite( fd , buf , len );
246 r= write( fd , buf , len );
250 if (r==-1) { Tvberrno(e); goto x_error; }