static void handle_accept( const int64 serversocket ) { struct http_data *h; unsigned char ip[4]; uint16 port; tai6464 t; int64 i; while( ( i = socket_accept4( serversocket, (char*)ip, &port) ) != -1 ) { /* Put fd into a non-blocking mode */ io_nonblock( i ); if( !io_fd( i ) || !( h = (struct http_data*)malloc( sizeof( struct http_data ) ) ) ) { io_close( i ); continue; } io_setcookie( i, h ); io_wantread( i ); memset( h, 0, sizeof( struct http_data ) ); memmove( h->ip, ip, sizeof( ip ) ); stats_issue_event( EVENT_ACCEPT, 1, ntohl(*(uint32_t*)ip)); /* That breaks taia encapsulation. But there is no way to take system time this often in FreeBSD and libowfat does not allow to set unix time */ taia_uint( &t, 0 ); /* Clear t */ tai_unix( &(t.sec), (g_now + OT_CLIENT_TIMEOUT) ); io_timeout( i, t ); } if( errno == EAGAIN ) io_eagain( serversocket ); }
void taia_now(struct taia *t) { struct timeval now; gettimeofday(&now, NULL); tai_unix(&t->sec, now.tv_sec); t->nano = 1000 * now.tv_usec + 500; t->atto = 0; }
void taia_now(struct taia * t) { struct timeval now; gettimeofday(&now, (struct timezone *) 0); tai_unix(&t->sec, now.tv_sec); t->nano = 1000 * now.tv_usec + 500; }
/* see http://cr.yp.to/ftp/list/eplf.html */ static int parse_eplf(struct ftpparse *f, char *buf, unsigned int len) { unsigned int start,pos; unsigned long ul; if (buf[0]!='+') return 0; start=1; for (pos = 1;pos < len;pos++) { if ('\t'==buf[pos]) { f->name=buf+pos+1; f->namelen=len-pos-1; if (!f->namelen) return 0; /* huh? */ f->format=FTPPARSE_FORMAT_EPLF; return 1; } if (',' != buf[pos]) continue; switch(buf[start]) { case '/': f->flagtrycwd=1; break; case 'r': f->flagtryretr=1; break; case 's': if (pos-start-1==0) return 0; if (get_uint64(buf+start+1,pos-start-1,&f->size) !=pos-start-1) return 0; f->sizetype=FTPPARSE_SIZE_BINARY; break; case 'm': if (pos-start-1==0) return 0; if (get_ulong(buf+start+1,pos-start-1,&ul)!=pos-start-1) return 0; tai_unix(&f->mtime,ul); f->mtimetype = FTPPARSE_MTIME_LOCAL; break; case 'i': /* refuse zero bytes length ids */ if (pos-start-1==0) return 0; f->idtype = FTPPARSE_ID_FULL; f->id=buf+start+1; f->idlen=pos-start-1; break; } start=pos+1; } return 0; }
void tai_now(struct tai *t) { tai_unix(t,time((time_t *) 0)); }