vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / test2.c
blob968e6b28dc91af14821fbf243b0a0b6012ffa6ec
1 #include <stdio.h>
2 #include <kernel/OS.h>
3 #include <string.h>
4 #include <sys/time.h>
5 #include <malloc.h>
7 #include "sys/socket.h"
8 #include "netinet/in.h"
9 #include "arpa/inet.h"
10 #include "sys/select.h"
12 #include "ufunc.h"
14 #define THREADS 2
15 #define TIME 10
18 int32 test_thread(void *data)
20 int tnum = *(int*)data;
21 int sock = 0;
22 uint32 num = 0;
23 int rv;
24 struct sockaddr_in sa;
25 bigtime_t tn;
27 sa.sin_len = sizeof(sa);
28 sa.sin_port = 0;
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);
39 if (sock < 0)
40 err(sock, "Socket couldn't be created");
41 rv = bind(sock, (struct sockaddr *)&sa, sizeof(sa));
42 if (rv < 0)
43 err(rv, "Socket could not be bound to an ephemereal port");
44 closesocket(sock);
45 num++;
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)
57 thread_id t[THREADS];
58 int i;
59 status_t retval;
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);
66 if (t[i] >= 0)
67 resume_thread(t[i]);
70 for (i=0;i<THREADS;i++) {
71 wait_for_thread(t[i], &retval);
74 return (0);