2
* ivykis, an event handling library
3
* Copyright (C) 2002, 2003 Lennert Buytenhek
4
* Dedicated to Marija Kulikova.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License version
8
* 2.1 as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License version 2.1 for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License version 2.1 along with this program; if not, write to the
17
* Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18
* Boston, MA 02110-1301, USA.
26
#include <netinet/in.h>
28
#include <sys/socket.h>
29
#include <sys/types.h>
41
static void handler(void *_h)
43
struct handle *h = (struct handle *)_h;
44
struct sockaddr_in addr;
48
addrlen = sizeof(addr);
49
ret = accept(h->fd.fd, (struct sockaddr *)&addr, &addrlen);
54
len = snprintf(buf, 128, "this is port %d\n", h->port);
59
if (!(++conns % 10000))
60
printf("%i\n", conns);
64
static void create_handle(struct handle *h, int port)
66
struct sockaddr_in addr;
70
sock = socket(AF_INET, SOCK_STREAM, 0);
77
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
78
&yes, sizeof(yes)) < 0) {
83
addr.sin_family = AF_INET;
84
addr.sin_addr.s_addr = htonl(INADDR_ANY);
85
addr.sin_port = htons(port);
86
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
95
h->fd.handler_in = handler;
96
h->fd.handler_out = NULL;
99
iv_fd_register(&h->fd);
102
static void create_run_handles(int fp, int numhandles)
104
struct handle hh[numhandles];
107
printf("entering main loop for ports %d..%d\n",
108
fp, fp + numhandles - 1);
110
for (i = 0; i < numhandles; i++)
111
create_handle(hh + i, fp + i);
122
static void *thr(void *_fp)
124
int fp = (int)(unsigned long)_fp;
128
create_run_handles(fp, 100);
139
for (i = 1; i < 10; i++) {
140
unsigned long fp = 20000 + i * 100;
143
pthread_create(&id, NULL, thr, (void *)fp);
146
create_run_handles(20000, 100);
155
create_run_handles(20000, 1000);