1#include <stdio.h> 2#include <kernel/OS.h> 3#include <string.h> 4#include <sys/time.h> 5 6#include "sys/socket.h" 7#include "netinet/in.h" 8#include "arpa/inet.h" 9#include "sys/select.h" 10 11#define THREADS 2 12#define TIME 10 13 14int32 test_thread(void *data) 15{ 16 int tnum = *(int*)data; 17 int sock = 0; 18 uint32 num = 0; 19 bigtime_t tn; 20 21 printf("Thread %d, starting test...\n", tnum + 1); 22 23 tn = real_time_clock(); 24 25 while (real_time_clock() - tn <= TIME) { 26 sock = socket(AF_INET, SOCK_DGRAM , 0); 27 if (sock < 0) { 28 printf("Failed! Socket could not be created.\n"); 29 printf("Error was %d [%s]\n", sock, strerror(sock)); 30 printf("This was after I had created %ld socket%s\n", 31 num, num == 1 ? "" : "s"); 32 return -1; 33 } 34 closesocket(sock); 35 num++; 36 } 37 38 printf( "Thread %d:\n" 39 " sockets created : %5ld\n" 40 " test time : %5d seconds\n" 41 " average : %5ld sockets/sec\n", 42 tnum + 1, num, TIME, num / TIME); 43} 44 45#define TEST_PHRASE "Hello loopback!" 46 47int main(int argc, char **argv) 48{ 49 thread_id t[THREADS]; 50 int i; 51 status_t retval; 52 53 for (i=0;i<THREADS;i++) { 54 t[i] = spawn_thread(test_thread, "socket test thread", 55 B_NORMAL_PRIORITY, &i); 56 if (t[i] >= 0) 57 resume_thread(t[i]); 58 } 59 60 for (i=0;i<THREADS;i++) { 61 wait_for_thread(t[i], &retval); 62 } 63 64 printf("Test complete.\n"); 65 66 return (0); 67} 68 69 70