Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | a771a51 | 2007-02-19 01:13:53 +0000 | [diff] [blame] | 3 | * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 4 | * |
| 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 Prijono | ed811d7 | 2006-03-10 12:57:12 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 25 | |
| 26 | extern int param_echo_sock_type; |
| 27 | extern const char *param_echo_server; |
| 28 | extern int param_echo_port; |
| 29 | |
| 30 | |
| 31 | //#if defined(PJ_WIN32) && PJ_WIN32!=0 |
| 32 | #if 0 |
| 33 | #include <windows.h> |
| 34 | static 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> |
| 44 | static 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 | |
| 58 | int main(int argc, char *argv[]) |
| 59 | { |
| 60 | int rc; |
Benny Prijono | 8220f90 | 2006-01-09 17:20:59 +0000 | [diff] [blame] | 61 | int interractive = 0; |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 62 | |
| 63 | boost(); |
| 64 | init_signals(); |
| 65 | |
| 66 | while (argc > 1) { |
| 67 | char *arg = argv[--argc]; |
| 68 | |
Benny Prijono | 8220f90 | 2006-01-09 17:20:59 +0000 | [diff] [blame] | 69 | if (*arg=='-' && *(arg+1)=='i') { |
| 70 | interractive = 1; |
| 71 | |
| 72 | } else if (*arg=='-' && *(arg+1)=='p') { |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 73 | 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) |
| 84 | param_echo_sock_type = PJ_SOCK_STREAM; |
| 85 | else if (pj_stricmp2(&type, "udp")==0) |
| 86 | param_echo_sock_type = PJ_SOCK_DGRAM; |
| 87 | 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 Prijono | 8220f90 | 2006-01-09 17:20:59 +0000 | [diff] [blame] | 96 | if (interractive) { |
| 97 | char s[10]; |
| 98 | puts(""); |
| 99 | puts("Press <ENTER> to exit"); |
| 100 | fgets(s, sizeof(s), stdin); |
| 101 | } |
| 102 | |
Benny Prijono | 5dcb38d | 2005-11-21 01:55:47 +0000 | [diff] [blame] | 103 | return rc; |
| 104 | } |
| 105 | |