7 #include "sys/socket.h"
8 #include "netinet/in.h"
10 #include "sys/select.h"
18 int32
test_thread(void *data
)
20 int tnum
= *(int*)data
;
24 struct sockaddr_in sa
;
27 sa
.sin_len
= sizeof(sa
);
29 sa
.sin_addr
.s_addr
= htonl(INADDR_LOOPBACK
);
30 sa
.sin_family
= AF_INET
;
31 memset(&sa
.sin_zero
, 0, sizeof(sa
.sin_zero
));
33 printf("Thread %d, starting test...\n", tnum
+ 1);
35 tn
= real_time_clock();
37 while (real_time_clock() - tn
<= TIME
) {
38 sock
= socket(AF_INET
, SOCK_DGRAM
, 0);
40 err(sock
, "Socket couldn't be created");
41 rv
= bind(sock
, (struct sockaddr
*)&sa
, sizeof(sa
));
43 err(rv
, "Socket could not be bound to an ephemereal port");
48 printf( "Thread %d:\n"
49 " sockets created : %5ld\n"
50 " test time : %5d seconds\n"
51 " average : %5ld sockets/sec\n",
52 tnum
+ 1, num
, TIME
, num
/ TIME
);
55 int main(int argc
, char **argv
)
61 test_banner("Socket creation and bind() test");
63 for (i
=0;i
<THREADS
;i
++) {
64 t
[i
] = spawn_thread(test_thread
, "socket test thread",
65 B_NORMAL_PRIORITY
, &i
);
70 for (i
=0;i
<THREADS
;i
++) {
71 wait_for_thread(t
[i
], &retval
);