~ubuntu-branches/ubuntu/trusty/syslog-ng/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/ivykis/lib/test/server.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS), Gergely Nagy
  • Date: 2011-10-11 14:30:48 UTC
  • mfrom: (1.3.7)
  • Revision ID: package-import@ubuntu.com-20111011143048-r1iljux9xbvj3lwh
Tags: 3.3.1.dfsg-1
* New upstream release with important fixes from upstream git tree with
  non-free manpages removed.
* Drop syslog-ng.conf(5) (closes: #496521).
* syslog-ng(8) is generated, and does not mention -Q anymore
  (closes: #616069).
* Supports CAP_SYSLOG on recent kernels (closes: #630172).
* Does not use g_timeout_add_seconds anymore (closes: #609154).

[ Gergely Nagy <algernon@madhouse-project.org> ]
* Update debian/copyright to DEP-5 format.
* Simplified the logrotate file by merging identical entries.
* Include local configuration files from /etc/syslog-ng/conf.d/ (Closes:
  #609050).
* Update syslog-ng.conf to be fully 3.3 compliant.
* Compress both source and binaries (except the syslog-ng meta
  package) with xz, instead of gzip.
* Use dpkg triggers to restart syslog-ng when appropriate.
* Include DFSG-free manual pages for all binaries.
* Build with Hardening enabled.
* Mention syslog(3) in /etc/default/syslog-ng, instead of
  <linux/kernel.h> (Closes: #608605)
* Support 'status' in the init script.
  Patch from Peter Eisentraut <petere@debian.org> (Closes: #644458)
* Build-Depend on libevtlog-dev (>= 0.2.12-5~) for correct shlibs.
* Use [linux-any] in Build-Depends instead of hardcoded links.
  (Closes: #634715)
* Use $SYSLOGNG_OPTS in the init script when reloading syslog-ng.
  (Closes: #589081)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ivykis, an event handling library
 
3
 * Copyright (C) 2002, 2003 Lennert Buytenhek
 
4
 * Dedicated to Marija Kulikova.
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
19
 */
 
20
 
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <errno.h>
 
24
#include <fcntl.h>
 
25
#include <iv.h>
 
26
#include <netinet/in.h>
 
27
#include <signal.h>
 
28
#include <sys/socket.h>
 
29
#include <sys/types.h>
 
30
#include <time.h>
 
31
#include <unistd.h>
 
32
 
 
33
struct handle {
 
34
        struct iv_fd fd;
 
35
        int port;
 
36
};
 
37
 
 
38
 
 
39
static int conns;
 
40
 
 
41
static void handler(void *_h)
 
42
{
 
43
        struct handle *h = (struct handle *)_h;
 
44
        struct sockaddr_in addr;
 
45
        socklen_t addrlen;
 
46
        int ret;
 
47
 
 
48
        addrlen = sizeof(addr);
 
49
        ret = accept(h->fd.fd, (struct sockaddr *)&addr, &addrlen);
 
50
        if (ret > 0) {
 
51
                char buf[128];
 
52
                int len;
 
53
 
 
54
                len = snprintf(buf, 128, "this is port %d\n", h->port);
 
55
                write(ret, buf, len);
 
56
                shutdown(ret, 2);
 
57
                close(ret);
 
58
 
 
59
                if (!(++conns % 10000))
 
60
                        printf("%i\n", conns);
 
61
        }
 
62
}
 
63
 
 
64
static void create_handle(struct handle *h, int port)
 
65
{
 
66
        struct sockaddr_in addr;
 
67
        int sock;
 
68
        int yes;
 
69
 
 
70
        sock = socket(AF_INET, SOCK_STREAM, 0);
 
71
        if (sock < 0) {
 
72
                perror("socket");
 
73
                exit(1);
 
74
        }
 
75
 
 
76
        yes = 1;
 
77
        if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
 
78
                       &yes, sizeof(yes)) < 0) {
 
79
                perror("setsockopt");
 
80
                exit(1);
 
81
        }
 
82
 
 
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) {
 
87
                perror("bind");
 
88
                exit(1);
 
89
        }
 
90
 
 
91
        listen(sock, 5);
 
92
 
 
93
        IV_FD_INIT(&h->fd);
 
94
        h->fd.fd = sock;
 
95
        h->fd.handler_in = handler;
 
96
        h->fd.handler_out = NULL;
 
97
        h->fd.cookie = h;
 
98
        h->port = port;
 
99
        iv_fd_register(&h->fd);
 
100
}
 
101
 
 
102
static void create_run_handles(int fp, int numhandles)
 
103
{
 
104
        struct handle hh[numhandles];
 
105
        int i;
 
106
 
 
107
        printf("entering main loop for ports %d..%d\n",
 
108
               fp, fp + numhandles - 1);
 
109
 
 
110
        for (i = 0; i < numhandles; i++)
 
111
                create_handle(hh + i, fp + i);
 
112
 
 
113
        iv_main();
 
114
 
 
115
        iv_deinit();
 
116
}
 
117
 
 
118
 
 
119
#ifdef THREAD
 
120
#include <pthread.h>
 
121
 
 
122
static void *thr(void *_fp)
 
123
{
 
124
        int fp = (int)(unsigned long)_fp;
 
125
 
 
126
        iv_init();
 
127
 
 
128
        create_run_handles(fp, 100);
 
129
 
 
130
        return NULL;
 
131
}
 
132
 
 
133
int main()
 
134
{
 
135
        int i;
 
136
 
 
137
        iv_init();
 
138
 
 
139
        for (i = 1; i < 10; i++) {
 
140
                unsigned long fp = 20000 + i * 100;
 
141
                pthread_t id;
 
142
 
 
143
                pthread_create(&id, NULL, thr, (void *)fp);
 
144
        }
 
145
 
 
146
        create_run_handles(20000, 100);
 
147
 
 
148
        return 0;
 
149
}
 
150
#else
 
151
int main()
 
152
{
 
153
        iv_init();
 
154
 
 
155
        create_run_handles(20000, 1000);
 
156
 
 
157
        return 0;
 
158
}
 
159
#endif