blob: 5f12aa62a7a6ea60b552748d8735f80b3b3b5bcc [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
Benny Prijono32177c02008-06-20 22:44:47 +00003 * Copyright (C)2003-2008 Benny Prijono <benny@prijono.org>
Benny Prijono5dcb38d2005-11-21 01:55:47 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include "test.h"
20
21#include <pj/string.h>
22#include <pj/sock.h>
23#include <pj/log.h>
Benny Prijonoed811d72006-03-10 12:57:12 +000024#include <stdio.h>
Benny Prijono5dcb38d2005-11-21 01:55:47 +000025
26extern int param_echo_sock_type;
27extern const char *param_echo_server;
28extern int param_echo_port;
29
30
31//#if defined(PJ_WIN32) && PJ_WIN32!=0
32#if 0
33#include <windows.h>
34static void boost(void)
35{
36 SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
37}
38#else
39#define boost()
40#endif
41
42#if defined(PJ_SUNOS) && PJ_SUNOS!=0
43#include <signal.h>
44static void init_signals()
45{
46 struct sigaction act;
47
48 memset(&act, 0, sizeof(act));
49 act.sa_handler = SIG_IGN;
50
51 sigaction(SIGALRM, &act, NULL);
52}
53
54#else
55#define init_signals()
56#endif
57
58int main(int argc, char *argv[])
59{
60 int rc;
Benny Prijono8220f902006-01-09 17:20:59 +000061 int interractive = 0;
Benny Prijono5dcb38d2005-11-21 01:55:47 +000062
63 boost();
64 init_signals();
65
66 while (argc > 1) {
67 char *arg = argv[--argc];
68
Benny Prijono8220f902006-01-09 17:20:59 +000069 if (*arg=='-' && *(arg+1)=='i') {
70 interractive = 1;
71
72 } else if (*arg=='-' && *(arg+1)=='p') {
Benny Prijono5dcb38d2005-11-21 01:55:47 +000073 pj_str_t port = pj_str(argv[--argc]);
74
75 param_echo_port = pj_strtoul(&port);
76
77 } else if (*arg=='-' && *(arg+1)=='s') {
78 param_echo_server = argv[--argc];
79
80 } else if (*arg=='-' && *(arg+1)=='t') {
81 pj_str_t type = pj_str(argv[--argc]);
82
83 if (pj_stricmp2(&type, "tcp")==0)
Benny Prijono8ab968f2007-07-20 08:08:30 +000084 param_echo_sock_type = pj_SOCK_STREAM();
Benny Prijono5dcb38d2005-11-21 01:55:47 +000085 else if (pj_stricmp2(&type, "udp")==0)
Benny Prijono8ab968f2007-07-20 08:08:30 +000086 param_echo_sock_type = pj_SOCK_DGRAM();
Benny Prijono5dcb38d2005-11-21 01:55:47 +000087 else {
88 PJ_LOG(3,("", "error: unknown socket type %s", type.ptr));
89 return 1;
90 }
91 }
92 }
93
94 rc = test_main();
95
Benny Prijono8220f902006-01-09 17:20:59 +000096 if (interractive) {
97 char s[10];
98 puts("");
99 puts("Press <ENTER> to exit");
100 fgets(s, sizeof(s), stdin);
101 }
102
Benny Prijono5dcb38d2005-11-21 01:55:47 +0000103 return rc;
104}
105