Go to the documentation of this file.
17 #define CHANGE_FD_SETSIZE 1
21 #undef CHANGE_FD_SETSIZE
22 #define CHANGE_FD_SETSIZE 0
30 #include <osreldate.h>
31 #if __FreeBSD_version < 220000
32 #undef CHANGE_FD_SETSIZE
33 #define CHANGE_FD_SETSIZE 0
38 #if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
39 #define FD_SETSIZE SQUID_MAXFD
61 #include <sys/socket.h>
64 #include <netinet/in.h>
67 #include <arpa/inet.h>
85 #define READ_BUF_SZ 4096
86 #define URL_BUF_SZ 4096
101 static struct timeval
now;
103 static int debug = 1;
111 return (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000;
126 struct sockaddr_in S;
127 unsigned short port = 80;
128 assert(!strncmp(url,
"http://", 7));
130 if ((t = strchr(host,
'/')))
132 if ((t = strchr(host,
':'))) {
134 port = (
unsigned short) atoi(t + 1);
136 t = strchr(url + 7,
'/');
138 memset(&S,
'\0',
sizeof(S));
142 memcpy(&S.sin_addr.s_addr, h->
h_addr_list[0],
sizeof(S.sin_addr.s_addr));
143 S.sin_port = htons(
port);
144 S.sin_family = AF_INET;
147 fprintf(stderr,
"%s (%s) %d %s\n", host,
inet_ntop(AF_INET, &S.sin_addr,tmp,
sizeof(tmp)), (
int)
port, path);
149 s = socket(PF_INET, SOCK_STREAM, 0);
154 x = connect(s, (
struct sockaddr *) &S,
sizeof(S));
160 "GET %s HTTP/1.1\r\n"
163 "Connection: close\r\n"
190 fprintf(stderr,
"Child PID %d entering child_main_loop\n", (
int) getpid());
192 setbuf(stdout,
NULL);
193 setbuf(stderr,
NULL);
195 t = strchr(buf,
'\n');
199 if (strncmp(buf,
"http://", 7))
201 gettimeofday(&t1,
NULL);
203 gettimeofday(&t2,
NULL);
213 int prfd, pwfd, crfd, cwfd;
224 if ((
pid = fork()) < 0)
230 t = calloc(1,
sizeof(*t));
257 for (i = 0; i < 20; i++) {
261 fprintf(stderr,
"Thing #%d on FD %d/%d\n",
273 if (strncmp(buf,
"http://", 7))
299 x = write(t->
wfd, url, strlen(url));
303 fprintf(stderr,
"dispatched URL to thing PID %d, %d bytes\n", (
int) t->
pid, x);
305 if ((s = strchr(t->
url,
'\n')))
318 x = read(t->
rfd, buf, 128);
321 }
else if (2 == sscanf(buf,
"%d %d", &i, &j)) {
323 printf(
"%d.%06d %9d %9d %s\n", (
int)
now.tv_sec, (
int)
now.tv_usec, i, j, t->
url);
354 if (!FD_ISSET(t->
rfd, &R2))
367 pid = waitpid(-1, &status, WNOHANG);
368 }
while (
pid > 0 || (
pid < 0 && errno == EINTR));
379 for (i = 3; i <=
maxfd; i++)
static thing * get_idle_thing(void)
static void child_main_loop(void)
static void dispatch(thing *t, char *url)
struct hostent * gethostbyname()
static void parent_main_loop(void)
static int get_url(const char *url)
static void read_reply(thing *t)
int main(int argc, char *argv[])
static thing * create_a_thing(char *argv[])
static void create_children(char *argv[])
int tvSubMsec(struct timeval t1, struct timeval t2)
static void sig_child(int sig)
struct _request * request(char *urlin)
static struct timeval now
char * parent_read_url(void)