Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,633 +0,0 @@
1
-/* 
2
- * Copyright (C) 2005 iptelorg GmbH
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-/*!
18
- * \file
19
- * \brief Kamailio core :: tcp io wait common stuff used by tcp_main.c & tcp_read.c
20
- * (see io_wait.h)
21
- * \ingroup core
22
- * Module: \ref core
23
- */
24
-
25
-
26
-
27
-#ifndef NO_IO_WAIT
28
-
29
-#ifdef HAVE_EPOLL
30
-#include <unistd.h> /* close() */
31
-#endif
32
-#ifdef HAVE_DEVPOLL
33
-#include <sys/types.h> /* open */
34
-#include <sys/stat.h>
35
-#include <fcntl.h>
36
-#include <unistd.h> /* close, ioctl */
37
-#endif
38
-
39
-#include <stdlib.h> /* strtol() */
40
-#include "io_wait.h"
41
-#include "ut.h" /* get_sys_ver() */
42
-
43
-
44
-#include "mem/mem.h"
45
-
46
-#ifndef local_malloc
47
-#define local_malloc pkg_malloc
48
-#endif
49
-#ifndef local_free
50
-#define local_free pkg_free
51
-#endif
52
-
53
-char* poll_support="poll"
54
-#ifdef HAVE_EPOLL
55
-", epoll_lt, epoll_et"
56
-#endif
57
-#ifdef HAVE_SIGIO_RT
58
-", sigio_rt"
59
-#endif
60
-#ifdef HAVE_SELECT
61
-", select"
62
-#endif
63
-#ifdef HAVE_KQUEUE
64
-", kqueue"
65
-#endif
66
-#ifdef HAVE_DEVPOLL
67
-", /dev/poll"
68
-#endif
69
-;
70
-
71
-
72
-char* poll_method_str[POLL_END]={ "none", "poll", "epoll_lt", "epoll_et", 
73
-								  "sigio_rt", "select", "kqueue",  "/dev/poll"
74
-								};
75
-
76
-int _os_ver=0; /* os version number */
77
-
78
-#ifdef HAVE_SIGIO_RT
79
-static int _sigio_init=0;
80
-static int _sigio_crt_rtsig;
81
-static sigset_t _sigio_rtsig_used;
82
-#endif
83
-
84
-
85
-
86
-#ifdef HAVE_SIGIO_RT
87
-/* sigio specific init
88
- * returns -1 on error, 0 on success */
89
-static int init_sigio(io_wait_h* h, int rsig)
90
-{
91
-	int r;
92
-	int n;
93
-	int signo;
94
-	int start_sig;
95
-	sigset_t oldset;
96
-	
97
-	if (!_sigio_init){
98
-		_sigio_init=1;
99
-		_sigio_crt_rtsig=SIGRTMIN;
100
-		sigemptyset(&_sigio_rtsig_used);
101
-	}
102
-	h->signo=0;
103
-	
104
-	if (rsig==0){
105
-		start_sig=_sigio_crt_rtsig;
106
-		n=SIGRTMAX-SIGRTMIN;
107
-	}else{
108
-		if ((rsig < SIGRTMIN) || (rsig >SIGRTMAX)){
109
-			LM_CRIT("real time signal %d out of range  [%d, %d]\n",
110
-					rsig, SIGRTMIN, SIGRTMAX);
111
-			goto error;
112
-		}
113
-		start_sig=rsig;
114
-		n=0;
115
-	}
116
-	
117
-	sigemptyset(&h->sset);
118
-	sigemptyset(&oldset);
119
-retry1:
120
-	/* get current block mask */
121
-	if (sigprocmask(SIG_BLOCK, &h->sset, &oldset )==-1){
122
-		if (errno==EINTR) goto retry1;
123
-		LM_ERR("1st sigprocmask failed: %s [%d]\n", strerror(errno), errno);
124
-		/* try to continue */
125
-	}
126
-	
127
-	for (r=start_sig; r<=(n+start_sig); r++){
128
-		signo=(r>SIGRTMAX)?r-SIGRTMAX+SIGRTMIN:r;
129
-		if (! sigismember(&_sigio_rtsig_used, signo) &&
130
-			! sigismember(&oldset, signo)){
131
-			sigaddset(&_sigio_rtsig_used, signo);
132
-			h->signo=signo;
133
-			_sigio_crt_rtsig=(signo<SIGRTMAX)?signo+1:SIGRTMIN;
134
-			break;
135
-		}
136
-	}
137
-	
138
-	if (h->signo==0){
139
-			LM_CRIT("%s\n", rsig?"could not assign requested real-time signal":
140
-						 "out of real-time signals");
141
-			goto error;
142
-	}
143
-
144
-	LM_DBG("trying signal %d... \n", h->signo);
145
-	
146
-	if (sigaddset(&h->sset, h->signo)==-1){
147
-		LM_ERR("sigaddset failed for %d: %s [%d]\n",
148
-				h->signo, strerror(errno), errno);
149
-		goto error;
150
-	}
151
-	if (sigaddset(&h->sset, SIGIO)==-1){
152
-		LM_ERR("sigaddset failed for %d: %s [%d]\n",
153
-				SIGIO, strerror(errno), errno);
154
-		goto error;
155
-	}
156
-retry:
157
-	if (sigprocmask(SIG_BLOCK, &h->sset, 0)==-1){
158
-		if (errno==EINTR) goto retry;
159
-		LM_ERR("sigprocmask failed: %s [%d]\n",
160
-				strerror(errno), errno);
161
-		goto error;
162
-	}
163
-	return 0;
164
-error:
165
-	h->signo=0;
166
-	sigemptyset(&h->sset);
167
-	return -1;
168
-}
169
-
170
-
171
-
172
-/* sigio specific destroy */
173
-static void destroy_sigio(io_wait_h* h)
174
-{
175
-	if (h->signo){
176
-		sigprocmask(SIG_UNBLOCK, &h->sset, 0);
177
-		sigemptyset(&h->sset);
178
-		sigdelset(&_sigio_rtsig_used, h->signo);
179
-		h->signo=0;
180
-	}
181
-}
182
-#endif
183
-
184
-
185
-
186
-#ifdef HAVE_EPOLL
187
-/* epoll specific init
188
- * returns -1 on error, 0 on success */
189
-static int init_epoll(io_wait_h* h)
190
-{
191
-again:
192
-	h->epfd=epoll_create(h->max_fd_no);
193
-	if (h->epfd==-1){
194
-		if (errno==EINTR) goto again;
195
-		LM_ERR("epoll_create: %s [%d]\n", strerror(errno), errno);
196
-		return -1;
197
-	}
198
-	return 0;
199
-}
200
-
201
-
202
-
203
-static void destroy_epoll(io_wait_h* h)
204
-{
205
-	if (h->epfd!=-1){
206
-		close(h->epfd);
207
-		h->epfd=-1;
208
-	}
209
-}
210
-#endif
211
-
212
-
213
-
214
-#ifdef HAVE_KQUEUE
215
-/* kqueue specific init
216
- * returns -1 on error, 0 on success */
217
-static int init_kqueue(io_wait_h* h)
218
-{
219
-again:
220
-	h->kq_fd=kqueue();
221
-	if (h->kq_fd==-1){
222
-		if (errno==EINTR) goto again;
223
-		LM_ERR("kqueue: %s [%d]\n", strerror(errno), errno);
224
-		return -1;
225
-	}
226
-	return 0;
227
-}
228
-
229
-
230
-
231
-static void destroy_kqueue(io_wait_h* h)
232
-{
233
-	if (h->kq_fd!=-1){
234
-		close(h->kq_fd);
235
-		h->kq_fd=-1;
236
-	}
237
-}
238
-#endif
239
-
240
-
241
-
242
-#ifdef HAVE_DEVPOLL
243
-/* /dev/poll specific init
244
- * returns -1 on error, 0 on success */
245
-static int init_devpoll(io_wait_h* h)
246
-{
247
-again:
248
-	h->dpoll_fd=open("/dev/poll", O_RDWR);
249
-	if (h->dpoll_fd==-1){
250
-		if (errno==EINTR) goto again;
251
-		LM_ERR("open: %s [%d]\n", strerror(errno), errno);
252
-		return -1;
253
-	}
254
-	return 0;
255
-}
256
-
257
-
258
-
259
-static void destroy_devpoll(io_wait_h* h)
260
-{
261
-	if (h->dpoll_fd!=-1){
262
-		close(h->dpoll_fd);
263
-		h->dpoll_fd=-1;
264
-	}
265
-}
266
-#endif
267
-
268
-
269
-
270
-#ifdef HAVE_SELECT
271
-static int init_select(io_wait_h* h)
272
-{
273
-	FD_ZERO(&h->master_rset);
274
-	FD_ZERO(&h->master_wset);
275
-	return 0;
276
-}
277
-#endif
278
-
279
-
280
-/*
281
- * returns 0 on success, and an error message on error
282
- */
283
-char* check_poll_method(enum poll_types poll_method)
284
-{
285
-	char* ret;
286
-
287
-	ret=0;
288
-	if (_os_ver==0) 
289
-		_os_ver=get_sys_version(0,0,0);
290
-	switch(poll_method){
291
-		case POLL_NONE:
292
-			break;
293
-		case POLL_POLL:
294
-			/* always supported */
295
-			break;
296
-		case POLL_SELECT:
297
-			/* should be always supported */
298
-#ifndef HAVE_SELECT
299
-			ret="select not supported, try re-compiling with -DHAVE_SELECT";
300
-#endif
301
-			break;
302
-		case POLL_EPOLL_LT:
303
-		case POLL_EPOLL_ET:
304
-#ifndef HAVE_EPOLL
305
-			ret="epoll not supported, try re-compiling with -DHAVE_EPOLL";
306
-#else
307
-			/* only on 2.6 + */
308
-			if (_os_ver<0x020542) /* if ver < 2.5.66 */
309
-			 	ret="epoll not supported on kernels < 2.6";
310
-#endif
311
-			break;
312
-		case POLL_SIGIO_RT:
313
-#ifndef HAVE_SIGIO_RT
314
-			ret="sigio_rt not supported, try re-compiling with"
315
-				" -DHAVE_SIGIO_RT";
316
-#else
317
-			/* only on 2.2 +  ?? */
318
-			if (_os_ver<0x020200) /* if ver < 2.2.0 */
319
-			 	ret="epoll not supported on kernels < 2.2 (?)";
320
-#endif
321
-			break;
322
-		case POLL_KQUEUE:
323
-#ifndef HAVE_KQUEUE
324
-			ret="kqueue not supported, try re-compiling with -DHAVE_KQUEUE";
325
-#else
326
-		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin, DragonFly */
327
-	#ifdef __OS_freebsd
328
-		/* all DragonFly versions have kqueque */
329
-		#ifndef __OS_dragonfly
330
-			if (_os_ver<0x0401) /* if ver < 4.1 */
331
-				ret="kqueue not supported on FreeBSD < 4.1";
332
-		#endif /* __OS_dragonfly */
333
-	#elif defined (__OS_netbsd)
334
-			if (_os_ver<0x020000) /* if ver < 2.0 */
335
-				ret="kqueue not supported on NetBSD < 2.0";
336
-	#elif defined (__OS_openbsd)
337
-			if (_os_ver<0x0209) /* if ver < 2.9 ? */
338
-				ret="kqueue not supported on OpenBSD < 2.9 (?)";
339
-	#endif /* assume that the rest support kqueue ifdef HAVE_KQUEUE */
340
-#endif
341
-			break;
342
-		case POLL_DEVPOLL:
343
-#ifndef HAVE_DEVPOLL
344
-			ret="/dev/poll not supported, try re-compiling with"
345
-					" -DHAVE_DEVPOLL";
346
-#else
347
-	/* only in Solaris >= 7.0 (?) */
348
-	#ifdef __OS_solaris
349
-		if (_os_ver<0x0507) /* ver < 5.7 */
350
-			ret="/dev/poll not supported on Solaris < 7.0 (SunOS 5.7)";
351
-	#endif
352
-#endif
353
-			break;
354
-
355
-		default:
356
-			ret="unknown not supported method";
357
-	}
358
-	return ret;
359
-}
360
-
361
-
362
-
363
-enum poll_types choose_poll_method()
364
-{
365
-	enum poll_types poll_method;
366
-
367
-	if (_os_ver==0)
368
-		_os_ver=get_sys_version(0,0,0);	
369
-	poll_method=0;
370
-#ifdef HAVE_EPOLL
371
-	if (_os_ver>=0x020542) /* if ver >= 2.5.66 */
372
-		poll_method=POLL_EPOLL_LT; /* or POLL_EPOLL_ET */
373
-		
374
-#endif
375
-#ifdef HAVE_KQUEUE
376
-	if (poll_method==0)
377
-		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin, DragonFly */
378
-	#ifdef __OS_freebsd
379
-		/* all DragonFly versions have kqueque */
380
-		#ifndef __OS_dragonfly
381
-		if (_os_ver>=0x0401) /* if ver >= 4.1 */
382
-		#endif /**__OS_dragonfly */
383
-	#elif defined (__OS_netbsd)
384
-		if (_os_ver>=0x020000) /* if ver >= 2.0 */
385
-	#elif defined (__OS_openbsd)
386
-		if (_os_ver>=0x0209) /* if ver >= 2.9 (?) */
387
-	#endif /* assume that the rest support kqueue ifdef HAVE_KQUEUE */
388
-			poll_method=POLL_KQUEUE;
389
-#endif
390
-#ifdef HAVE_DEVPOLL
391
-	#ifdef __OS_solaris
392
-	if (poll_method==0)
393
-		/* only in Solaris >= 7.0 (?) */
394
-		if (_os_ver>=0x0507) /* if ver >=SunOS 5.7 */
395
-			poll_method=POLL_DEVPOLL;
396
-	#endif
397
-#endif
398
-#ifdef  HAVE_SIGIO_RT
399
-		if (poll_method==0) 
400
-			if (_os_ver>=0x020200) /* if ver >= 2.2.0 */
401
-				poll_method=POLL_SIGIO_RT;
402
-#endif
403
-		if (poll_method==0) poll_method=POLL_POLL;
404
-	return poll_method;
405
-}
406
-
407
-
408
-
409
-char* poll_method_name(enum poll_types poll_method)
410
-{
411
-	if ((poll_method>=POLL_NONE) && (poll_method<POLL_END))
412
-		return poll_method_str[poll_method];
413
-	else
414
-		return "invalid poll method";
415
-}
416
-
417
-
418
-
419
-
420
-/* converts a string into a poll_method
421
- * returns POLL_NONE (0) on error, else the corresponding poll type */
422
-enum poll_types get_poll_type(char* s)
423
-{
424
-	int r;
425
-	int l;
426
-	
427
-	l=strlen(s);
428
-	for (r=POLL_END-1; r>POLL_NONE; r--)
429
-		if ((strlen(poll_method_str[r])==l) &&
430
-			(strncasecmp(poll_method_str[r], s, l)==0))
431
-			break;
432
-	return r; 
433
-}
434
-
435
-
436
-
437
-/* initializes the static vars/arrays
438
- * params:      h - pointer to the io_wait_h that will be initialized
439
- *         max_fd - maximum allowed fd number
440
- *         poll_m - poll method (0 for automatic best fit)
441
- */
442
-int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
443
-{
444
-	char * poll_err;
445
-	
446
-	if (_os_ver==0) _os_ver=get_sys_version(0,0,0);
447
-	memset(h, 0, sizeof(*h));
448
-	h->max_fd_no=max_fd;
449
-#ifdef HAVE_EPOLL
450
-	h->epfd=-1;
451
-#endif
452
-#ifdef HAVE_KQUEUE
453
-	h->kq_fd=-1;
454
-#endif
455
-#ifdef HAVE_DEVPOLL
456
-	h->dpoll_fd=-1;
457
-#endif
458
-	poll_err=check_poll_method(poll_method);
459
-	
460
-	/* set an appropiate poll method */
461
-	if (poll_err || (poll_method==0)){
462
-		poll_method=choose_poll_method();
463
-		if (poll_err){
464
-			LM_ERR("%s, using %s instead\n",
465
-					poll_err, poll_method_str[poll_method]);
466
-		}else{
467
-			LM_INFO("using %s as the io watch method (auto detected)\n",
468
-					poll_method_str[poll_method]);
469
-		}
470
-	}
471
-	
472
-	h->poll_method=poll_method;
473
-	
474
-	/* common stuff, everybody has fd_hash */
475
-	h->fd_hash=local_malloc(sizeof(*(h->fd_hash))*h->max_fd_no);
476
-	if (h->fd_hash==0){
477
-		LM_CRIT("could not alloc fd hashtable (%ld bytes)\n",
478
-					(long)sizeof(*(h->fd_hash))*h->max_fd_no );
479
-		goto error;
480
-	}
481
-	memset((void*)h->fd_hash, 0, sizeof(*(h->fd_hash))*h->max_fd_no);
482
-	
483
-	switch(poll_method){
484
-		case POLL_POLL:
485
-#ifdef HAVE_SELECT
486
-		case POLL_SELECT:
487
-#endif
488
-#ifdef HAVE_SIGIO_RT
489
-		case POLL_SIGIO_RT:
490
-#endif
491
-#ifdef HAVE_DEVPOLL
492
-		case POLL_DEVPOLL:
493
-#endif
494
-			h->fd_array=local_malloc(sizeof(*(h->fd_array))*h->max_fd_no);
495
-			if (h->fd_array==0){
496
-				LM_CRIT("could not alloc fd array (%ld bytes)\n",
497
-						(long)sizeof(*(h->fd_hash))*h->max_fd_no);
498
-				goto error;
499
-			}
500
-			memset((void*)h->fd_array, 0, sizeof(*(h->fd_array))*h->max_fd_no);
501
-#ifdef HAVE_SIGIO_RT
502
-			if ((poll_method==POLL_SIGIO_RT) && (init_sigio(h, 0)<0)){
503
-				LM_CRIT("sigio init failed\n");
504
-				goto error;
505
-			}
506
-#endif
507
-#ifdef HAVE_DEVPOLL
508
-			if ((poll_method==POLL_DEVPOLL) && (init_devpoll(h)<0)){
509
-				LM_CRIT("/dev/poll init failed\n");
510
-				goto error;
511
-			}
512
-#endif
513
-#ifdef HAVE_SELECT
514
-			if ((poll_method==POLL_SELECT) && (init_select(h)<0)){
515
-				LM_CRIT("select init failed\n");
516
-				goto error;
517
-			}
518
-#endif
519
-			
520
-			break;
521
-#ifdef HAVE_EPOLL
522
-		case POLL_EPOLL_LT:
523
-		case POLL_EPOLL_ET:
524
-			h->ep_array=local_malloc(sizeof(*(h->ep_array))*h->max_fd_no);
525
-			if (h->ep_array==0){
526
-				LM_CRIT("could not alloc epoll array\n");
527
-				goto error;
528
-			}
529
-			memset((void*)h->ep_array, 0, sizeof(*(h->ep_array))*h->max_fd_no);
530
-			if (init_epoll(h)<0){
531
-				LM_CRIT("epoll init failed\n");
532
-				goto error;
533
-			}
534
-			break;
535
-#endif
536
-#ifdef HAVE_KQUEUE
537
-		case POLL_KQUEUE:
538
-			h->kq_changes_size=KQ_CHANGES_ARRAY_SIZE;
539
-			/* kevent returns different events for read & write
540
-			   => to get all the possible events in one call we
541
-			   need twice the number of added fds + space
542
-			   for possible changelist errors.
543
-			   OTOH if memory is to be saved at all costs, one can
544
-			   decrease the array size.
545
-			 */
546
-			h->kq_array_size=2 * h->max_fd_no + h->kq_changes_size;
547
-			h->kq_array=local_malloc(sizeof(*(h->kq_array))*h->kq_array_size);
548
-			if (h->kq_array==0){
549
-				LM_CRIT("could not alloc kqueue event array\n");
550
-				goto error;
551
-			}
552
-			h->kq_changes=local_malloc(sizeof(*(h->kq_changes))*
553
-										h->kq_changes_size);
554
-			if (h->kq_changes==0){
555
-				LM_CRIT("could not alloc kqueue changes array\n");
556
-				goto error;
557
-			}
558
-			h->kq_nchanges=0;
559
-			memset((void*)h->kq_array, 0,
560
-						sizeof(*(h->kq_array))*h->kq_array_size);
561
-			memset((void*)h->kq_changes, 0,
562
-						sizeof(*(h->kq_changes))* h->kq_changes_size);
563
-			if (init_kqueue(h)<0){
564
-				LM_CRIT("kqueue init failed\n");
565
-				goto error;
566
-			}
567
-			break;
568
-#endif
569
-		default:
570
-			LM_CRIT("unknown/unsupported poll method %s (%d)\n",
571
-						poll_method_str[poll_method], poll_method);
572
-			goto error;
573
-	}
574
-	return 0;
575
-error:
576
-	return -1;
577
-}
578
-
579
-
580
-
581
-/* destroys everything init_io_wait allocated */
582
-void destroy_io_wait(io_wait_h* h)
583
-{
584
-	switch(h->poll_method){
585
-#ifdef HAVE_EPOLL
586
-		case POLL_EPOLL_LT:
587
-		case POLL_EPOLL_ET:
588
-			destroy_epoll(h);
589
-			if (h->ep_array){
590
-				local_free(h->ep_array);
591
-				h->ep_array=0;
592
-			}
593
-		break;
594
-#endif
595
-#ifdef HAVE_KQUEUE
596
-		case POLL_KQUEUE:
597
-			destroy_kqueue(h);
598
-			if (h->kq_array){
599
-				local_free(h->kq_array);
600
-				h->kq_array=0;
601
-			}
602
-			if (h->kq_changes){
603
-				local_free(h->kq_changes);
604
-				h->kq_changes=0;
605
-			}
606
-			break;
607
-#endif
608
-#ifdef HAVE_SIGIO_RT
609
-		case POLL_SIGIO_RT:
610
-			destroy_sigio(h);
611
-			break;
612
-#endif
613
-#ifdef HAVE_DEVPOLL
614
-		case POLL_DEVPOLL:
615
-			destroy_devpoll(h);
616
-			break;
617
-#endif
618
-		default: /*do  nothing*/
619
-			;
620
-	}
621
-		if (h->fd_array){
622
-			local_free(h->fd_array);
623
-			h->fd_array=0;
624
-		}
625
-		if (h->fd_hash){
626
-			local_free(h->fd_hash);
627
-			h->fd_hash=0;
628
-		}
629
-}
630
-
631
-
632
-
633
-#endif /*ifndef NO_IO_WAIT */
Browse code

io_wait.c: logging: DBG -> LM_DBG

Ovidiu Sas authored on 13/01/2015 15:48:39
Showing 1 changed files
... ...
@@ -141,7 +141,7 @@ retry1:
141 141
 			goto error;
142 142
 	}
143 143
 
144
-	DBG("init_sigio: trying signal %d... \n", h->signo);
144
+	LM_DBG("trying signal %d... \n", h->signo);
145 145
 	
146 146
 	if (sigaddset(&h->sset, h->signo)==-1){
147 147
 		LM_ERR("sigaddset failed for %d: %s [%d]\n",
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /* 
2
- * $Id$
3
- * 
4 2
  * Copyright (C) 2005 iptelorg GmbH
5 3
  *
6 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -15,21 +13,11 @@
15 13
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 14
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 15
  */
18
-/* 
19
- * tcp io wait common stuff used by tcp_main.c & tcp_read.c
20
- * (see io_wait.h)
21
- */
22
-/* 
23
- * History:
24
- * --------
25
- *  2005-06-15  created by andrei
26
- *  2005-06-26  added kqueue (andrei)
27
- *  2005-07-04  added /dev/poll (andrei)
28
- */
29 16
 
30 17
 /*!
31 18
  * \file
32
- * \brief SIP-router core :: 
19
+ * \brief Kamailio core :: tcp io wait common stuff used by tcp_main.c & tcp_read.c
20
+ * (see io_wait.h)
33 21
  * \ingroup core
34 22
  * Module: \ref core
35 23
  */
Browse code

io_wait.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 03/10/2014 20:07:26
Showing 1 changed files
... ...
@@ -118,8 +118,8 @@ static int init_sigio(io_wait_h* h, int rsig)
118 118
 		n=SIGRTMAX-SIGRTMIN;
119 119
 	}else{
120 120
 		if ((rsig < SIGRTMIN) || (rsig >SIGRTMAX)){
121
-			LOG(L_CRIT, "ERROR: init_sigio: real time signal %d out of"
122
-					          " range  [%d, %d]\n", rsig, SIGRTMIN, SIGRTMAX);
121
+			LM_CRIT("real time signal %d out of range  [%d, %d]\n",
122
+					rsig, SIGRTMIN, SIGRTMAX);
123 123
 			goto error;
124 124
 		}
125 125
 		start_sig=rsig;
... ...
@@ -132,8 +132,7 @@ retry1:
132 132
 	/* get current block mask */
133 133
 	if (sigprocmask(SIG_BLOCK, &h->sset, &oldset )==-1){
134 134
 		if (errno==EINTR) goto retry1;
135
-		LOG(L_ERR, "ERROR: init_sigio: 1st sigprocmask failed: %s [%d]\n",
136
-				strerror(errno), errno);
135
+		LM_ERR("1st sigprocmask failed: %s [%d]\n", strerror(errno), errno);
137 136
 		/* try to continue */
138 137
 	}
139 138
 	
... ...
@@ -149,8 +148,7 @@ retry1:
149 148
 	}
150 149
 	
151 150
 	if (h->signo==0){
152
-			LOG(L_CRIT, "ERROR: init_sigio: %s\n",
153
-					rsig?"could not assign requested real-time signal":
151
+			LM_CRIT("%s\n", rsig?"could not assign requested real-time signal":
154 152
 						 "out of real-time signals");
155 153
 			goto error;
156 154
 	}
... ...
@@ -158,19 +156,19 @@ retry1:
158 156
 	DBG("init_sigio: trying signal %d... \n", h->signo);
159 157
 	
160 158
 	if (sigaddset(&h->sset, h->signo)==-1){
161
-		LOG(L_ERR, "ERROR: init_sigio: sigaddset failed for %d: %s [%d]\n",
159
+		LM_ERR("sigaddset failed for %d: %s [%d]\n",
162 160
 				h->signo, strerror(errno), errno);
163 161
 		goto error;
164 162
 	}
165 163
 	if (sigaddset(&h->sset, SIGIO)==-1){
166
-		LOG(L_ERR, "ERROR: init_sigio: sigaddset failed for %d: %s [%d]\n",
164
+		LM_ERR("sigaddset failed for %d: %s [%d]\n",
167 165
 				SIGIO, strerror(errno), errno);
168 166
 		goto error;
169 167
 	}
170 168
 retry:
171 169
 	if (sigprocmask(SIG_BLOCK, &h->sset, 0)==-1){
172 170
 		if (errno==EINTR) goto retry;
173
-		LOG(L_ERR, "ERROR: init_sigio: sigprocmask failed: %s [%d]\n",
171
+		LM_ERR("sigprocmask failed: %s [%d]\n",
174 172
 				strerror(errno), errno);
175 173
 		goto error;
176 174
 	}
... ...
@@ -206,8 +204,7 @@ again:
206 204
 	h->epfd=epoll_create(h->max_fd_no);
207 205
 	if (h->epfd==-1){
208 206
 		if (errno==EINTR) goto again;
209
-		LOG(L_ERR, "ERROR: init_epoll: epoll_create: %s [%d]\n",
210
-				strerror(errno), errno);
207
+		LM_ERR("epoll_create: %s [%d]\n", strerror(errno), errno);
211 208
 		return -1;
212 209
 	}
213 210
 	return 0;
... ...
@@ -235,8 +232,7 @@ again:
235 232
 	h->kq_fd=kqueue();
236 233
 	if (h->kq_fd==-1){
237 234
 		if (errno==EINTR) goto again;
238
-		LOG(L_ERR, "ERROR: init_kqueue: kqueue: %s [%d]\n",
239
-				strerror(errno), errno);
235
+		LM_ERR("kqueue: %s [%d]\n", strerror(errno), errno);
240 236
 		return -1;
241 237
 	}
242 238
 	return 0;
... ...
@@ -264,8 +260,7 @@ again:
264 260
 	h->dpoll_fd=open("/dev/poll", O_RDWR);
265 261
 	if (h->dpoll_fd==-1){
266 262
 		if (errno==EINTR) goto again;
267
-		LOG(L_ERR, "ERROR: init_/dev/poll: open: %s [%d]\n",
268
-				strerror(errno), errno);
263
+		LM_ERR("open: %s [%d]\n", strerror(errno), errno);
269 264
 		return -1;
270 265
 	}
271 266
 	return 0;
... ...
@@ -478,11 +473,11 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
478 473
 	if (poll_err || (poll_method==0)){
479 474
 		poll_method=choose_poll_method();
480 475
 		if (poll_err){
481
-			LOG(L_ERR, "ERROR: init_io_wait: %s, using %s instead\n",
476
+			LM_ERR("%s, using %s instead\n",
482 477
 					poll_err, poll_method_str[poll_method]);
483 478
 		}else{
484
-			LOG(L_INFO, "init_io_wait: using %s as the io watch method"
485
-					" (auto detected)\n", poll_method_str[poll_method]);
479
+			LM_INFO("using %s as the io watch method (auto detected)\n",
480
+					poll_method_str[poll_method]);
486 481
 		}
487 482
 	}
488 483
 	
... ...
@@ -491,8 +486,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
491 486
 	/* common stuff, everybody has fd_hash */
492 487
 	h->fd_hash=local_malloc(sizeof(*(h->fd_hash))*h->max_fd_no);
493 488
 	if (h->fd_hash==0){
494
-		LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
495
-					" fd hashtable (%ld bytes)\n",
489
+		LM_CRIT("could not alloc fd hashtable (%ld bytes)\n",
496 490
 					(long)sizeof(*(h->fd_hash))*h->max_fd_no );
497 491
 		goto error;
498 492
 	}
... ...
@@ -511,27 +505,26 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
511 505
 #endif
512 506
 			h->fd_array=local_malloc(sizeof(*(h->fd_array))*h->max_fd_no);
513 507
 			if (h->fd_array==0){
514
-				LOG(L_CRIT, "ERROR: init_io_wait: could not"
515
-							" alloc fd array (%ld bytes)\n",
516
-							(long)sizeof(*(h->fd_hash))*h->max_fd_no);
508
+				LM_CRIT("could not alloc fd array (%ld bytes)\n",
509
+						(long)sizeof(*(h->fd_hash))*h->max_fd_no);
517 510
 				goto error;
518 511
 			}
519 512
 			memset((void*)h->fd_array, 0, sizeof(*(h->fd_array))*h->max_fd_no);
520 513
 #ifdef HAVE_SIGIO_RT
521 514
 			if ((poll_method==POLL_SIGIO_RT) && (init_sigio(h, 0)<0)){
522
-				LOG(L_CRIT, "ERROR: init_io_wait: sigio init failed\n");
515
+				LM_CRIT("sigio init failed\n");
523 516
 				goto error;
524 517
 			}
525 518
 #endif
526 519
 #ifdef HAVE_DEVPOLL
527 520
 			if ((poll_method==POLL_DEVPOLL) && (init_devpoll(h)<0)){
528
-				LOG(L_CRIT, "ERROR: init_io_wait: /dev/poll init failed\n");
521
+				LM_CRIT("/dev/poll init failed\n");
529 522
 				goto error;
530 523
 			}
531 524
 #endif
532 525
 #ifdef HAVE_SELECT
533 526
 			if ((poll_method==POLL_SELECT) && (init_select(h)<0)){
534
-				LOG(L_CRIT, "ERROR: init_io_wait: select init failed\n");
527
+				LM_CRIT("select init failed\n");
535 528
 				goto error;
536 529
 			}
537 530
 #endif
... ...
@@ -542,13 +535,12 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
542 535
 		case POLL_EPOLL_ET:
543 536
 			h->ep_array=local_malloc(sizeof(*(h->ep_array))*h->max_fd_no);
544 537
 			if (h->ep_array==0){
545
-				LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
546
-							" epoll array\n");
538
+				LM_CRIT("could not alloc epoll array\n");
547 539
 				goto error;
548 540
 			}
549 541
 			memset((void*)h->ep_array, 0, sizeof(*(h->ep_array))*h->max_fd_no);
550 542
 			if (init_epoll(h)<0){
551
-				LOG(L_CRIT, "ERROR: init_io_wait: epoll init failed\n");
543
+				LM_CRIT("epoll init failed\n");
552 544
 				goto error;
553 545
 			}
554 546
 			break;
... ...
@@ -566,15 +558,13 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
566 558
 			h->kq_array_size=2 * h->max_fd_no + h->kq_changes_size;
567 559
 			h->kq_array=local_malloc(sizeof(*(h->kq_array))*h->kq_array_size);
568 560
 			if (h->kq_array==0){
569
-				LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
570
-							" kqueue event array\n");
561
+				LM_CRIT("could not alloc kqueue event array\n");
571 562
 				goto error;
572 563
 			}
573 564
 			h->kq_changes=local_malloc(sizeof(*(h->kq_changes))*
574 565
 										h->kq_changes_size);
575 566
 			if (h->kq_changes==0){
576
-				LOG(L_CRIT, "ERROR: init_io_wait: could not alloc"
577
-							" kqueue changes array\n");
567
+				LM_CRIT("could not alloc kqueue changes array\n");
578 568
 				goto error;
579 569
 			}
580 570
 			h->kq_nchanges=0;
... ...
@@ -583,14 +573,13 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
583 573
 			memset((void*)h->kq_changes, 0,
584 574
 						sizeof(*(h->kq_changes))* h->kq_changes_size);
585 575
 			if (init_kqueue(h)<0){
586
-				LOG(L_CRIT, "ERROR: init_io_wait: kqueue init failed\n");
576
+				LM_CRIT("kqueue init failed\n");
587 577
 				goto error;
588 578
 			}
589 579
 			break;
590 580
 #endif
591 581
 		default:
592
-			LOG(L_CRIT, "BUG: init_io_wait: unknown/unsupported poll"
593
-						" method %s (%d)\n",
582
+			LM_CRIT("unknown/unsupported poll method %s (%d)\n",
594 583
 						poll_method_str[poll_method], poll_method);
595 584
 			goto error;
596 585
 	}
Browse code

Merge remote branch 'origin/andrei/tcp_tls_changes'

Asynchronous TLS support and various TCP and io_wait fixes
(especially on BSDs).

* origin/andrei/tcp_tls_changes: (67 commits)
tls: fix partial write on write-wants-read queue flush
tls: more config vars displayed by the tls.options RPC
tls: fix trailing space in new modparams
tls: verbose debugging for SSL_ERROR_WANT_WRITE
tls: add lib64 to LIBS path
tls: doc - notes about enabling debugging
tls: added debug log level modparam
tls: modparams for ct write queue params
tls: doc - new & async related config options
tls: no tls_bio debugging by default
tls: change read_ahead, buffers and freelist defaults
tcp: verbose and safer close()
tls: enable PARTIAL_WRITE by default
tls: partial SSL_write support when reading (tls_read_f)
tls: don't report SSL protocol errors as bugs
tls: more consistent low memory checking
io_wait: kqueue: use the entire array during too many errors fallback
tcp: fix dispatching closed connections to tcp readers
tcp: more complete error messages
tls: support for partial encoding and reseting send_flags
tcp: support for tls partial encoding
tls: update & fix repeated send & delayed send
tcp: change tls send callback interface
tsend: s/char*/const char*/ in function params.
tls: very verbose debug logging
tls: fix tls_send out-of-mem on new connection
tcp: force eof after read if write side hangup
tcp: don't reset read_flags on RD_CONN_REPEAT_READ
tls: deal with internal openssl buffering
tls: fix initial state error handling
tcp: more consistent IO_FD_CLOSING usage
io_wait: kqueue: use a bigger array
io_wait: kqueue: handle ENOENT and more robust error handling
io_wait: fix kqueue io_wait_add & POLLIN
io_wait: don't update FD watched status on error
io_wait: fix kqueue and too many errors in changelist
io_wait: fix: check for EV_ERROR for kqueue()
tcp: fix fd passing bug
tls: config option for sending close notify alerts
tls: SSL_shutdown() only fully established connections
tls: ssl_flush() fix and re-worked error reporting
tls: tls.list rpc: fix timeout & ip display
tls: fix queue accounting
tls: rpc: tls.list and tls.options update
tls: config options for the internal queues
tls: fix wrong wbio usage
tls: fix empty files treatment
tls: added tls.options rpc
tls: migrated to the runtime cfg framework
db_flatstore: updated get_abs_pathname use
core: get_abs_pathname() uses now pkg_malloc()
core: str.h - s/NULL/0/
tls: doc - removed handshake_timeout and send_timeout
tls: removed handshake_timeout and send_timeout
tls: s/tls_cfg/tls_domains_cfg
tls: added tls_info rpc
tls: fix unregistered rpc commands
tls: async support (major tls core rewrite)
tls: tls_bio ctrl cmd support, fixes and debug
tls: clear text write queue implementation
tls: added a minimum overhead shm buffer queue
tls: safer destroy_cfg
tcp: new tls hooks interface and async tls changes
tls: added custom memory based bio
tcp: minor cleanups & spelling
tcp: tcp_send() split in 3 smaller functions
tcp: comments & new internal command

Andrei Pelinescu-Onciul authored on 16/08/2010 00:18:57
Showing 0 changed files
Browse code

core: fix unclosed comment

Andrei Pelinescu-Onciul authored on 13/08/2010 20:25:34
Showing 1 changed files
... ...
@@ -396,7 +396,7 @@ enum poll_types choose_poll_method()
396 396
 		/* all DragonFly versions have kqueque */
397 397
 		#ifndef __OS_dragonfly
398 398
 		if (_os_ver>=0x0401) /* if ver >= 4.1 */
399
-		#endif /**__OS_dragonfly
399
+		#endif /**__OS_dragonfly */
400 400
 	#elif defined (__OS_netbsd)
401 401
 		if (_os_ver>=0x020000) /* if ver >= 2.0 */
402 402
 	#elif defined (__OS_openbsd)
Browse code

core: DragonFly kqueue support enabled

- fixed kqueue support check for DragonFly (seems to be always
supported since it was forked from FreeBSD 4.8).
- in dragonfly case define both __OS_freebsd and __OS_dragonfly so
that we can make some exceptions for dragonfly (e.g. no >= 4.1
version check at runtime before enabling kqueue).
- assume SCTP in 2.6 is at least on par with SCTP in FreeBSD 7.1.

Andrei Pelinescu-Onciul authored on 13/08/2010 09:45:39
Showing 1 changed files
... ...
@@ -340,10 +340,13 @@ char* check_poll_method(enum poll_types poll_method)
340 340
 #ifndef HAVE_KQUEUE
341 341
 			ret="kqueue not supported, try re-compiling with -DHAVE_KQUEUE";
342 342
 #else
343
-		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin */
343
+		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin, DragonFly */
344 344
 	#ifdef __OS_freebsd
345
+		/* all DragonFly versions have kqueque */
346
+		#ifndef __OS_dragonfly
345 347
 			if (_os_ver<0x0401) /* if ver < 4.1 */
346 348
 				ret="kqueue not supported on FreeBSD < 4.1";
349
+		#endif /* __OS_dragonfly */
347 350
 	#elif defined (__OS_netbsd)
348 351
 			if (_os_ver<0x020000) /* if ver < 2.0 */
349 352
 				ret="kqueue not supported on NetBSD < 2.0";
... ...
@@ -388,9 +391,12 @@ enum poll_types choose_poll_method()
388 391
 #endif
389 392
 #ifdef HAVE_KQUEUE
390 393
 	if (poll_method==0)
391
-		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin */
394
+		/* only in FreeBSD 4.1, NETBSD 2.0, OpenBSD 2.9, Darwin, DragonFly */
392 395
 	#ifdef __OS_freebsd
396
+		/* all DragonFly versions have kqueque */
397
+		#ifndef __OS_dragonfly
393 398
 		if (_os_ver>=0x0401) /* if ver >= 4.1 */
399
+		#endif /**__OS_dragonfly
394 400
 	#elif defined (__OS_netbsd)