/[resiprocate]/main/resip/dum/test/basicClient.cxx
ViewVC logotype

Contents of /main/resip/dum/test/basicClient.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9885 - (show annotations) (download)
Fri Sep 28 20:06:29 2012 UTC (7 years, 1 month ago) by sgodin
File MIME type: text/plain
File size: 3542 byte(s)
-fix startup delay issue that is seen when building resiprocate into a Windows DLL
 - was related to having socket calls at static initialization time and the following 
   globally scoped static initialization in Helper.cxx:
   static Data localhostname = DnsUtil::getLocalHostName();
 - since function scoped static initialization is prone to multi-threaded issues, a 
   different solution was implemented
 - modified DnsUtil::getLocalHostname to store the hostname on first call in static
   Data - using a gate and a mutex to ensure it is also thread safe
 - this will improve performance for all invocations of DnsUtil::getLocalHostname 
-added initNetwork call in a few places that help, since it won't be called
 from DnsUtil::getLocalHostname at global static init time any longer


1 #if defined(HAVE_CONFIG_HXX)
2 #include "resip/stack/config.hxx"
3 #endif
4
5 #include <cstring>
6 #include <cassert>
7
8 #ifndef __APPLE__
9 bool TRUE=true;
10 bool FALSE=false;
11 #endif
12
13 #include "basicClientUserAgent.hxx"
14 #include <resip/stack/SipStack.hxx>
15 #include <resip/stack/Uri.hxx>
16 #include <rutil/Logger.hxx>
17
18 #ifdef USE_SSL
19 #include <resip/stack/ssl/Security.hxx>
20 #endif
21
22 #include <signal.h>
23
24 using namespace resip;
25 using namespace std;
26
27 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
28
29 static bool exitSignalDetected = false;
30
31 static void
32 signalHandler(int signo)
33 {
34 std::cerr << "Shutting down" << endl;
35 exitSignalDetected = true;
36 }
37
38 int
39 main(int argc, char* argv[])
40 {
41 #ifndef _WIN32
42 if ( signal( SIGPIPE, SIG_IGN) == SIG_ERR)
43 {
44 cerr << "Couldn't install signal handler for SIGPIPE" << endl;
45 exit(-1);
46 }
47 #endif
48
49 if ( signal( SIGINT, signalHandler ) == SIG_ERR )
50 {
51 cerr << "Couldn't install signal handler for SIGINT" << endl;
52 exit( -1 );
53 }
54
55 if ( signal( SIGTERM, signalHandler ) == SIG_ERR )
56 {
57 cerr << "Couldn't install signal handler for SIGTERM" << endl;
58 exit( -1 );
59 }
60
61 // Initialize network
62 initNetwork();
63
64 try
65 {
66 BasicClientUserAgent ua(argc, argv);
67 ua.startup();
68
69 InfoLog(<< argv[0] << " starting");
70
71 while(ua.process(1000)) // Look for exit key every 1 second
72 {
73 if(exitSignalDetected)
74 {
75 ua.shutdown();
76 exitSignalDetected = false;
77 }
78 }
79 }
80 #ifdef USE_SSL
81 catch (BaseSecurity::Exception& e)
82 {
83 WarningLog (<< "Couldn't set up security object: " << e);
84 exit(-1);
85 }
86 #endif
87 catch (BaseException& e)
88 {
89 ErrLog (<< "Caught: " << e);
90 exit(-1);
91 }
92 catch( ... )
93 {
94 ErrLog( << "Caught non-resip exception" );
95 exit(-1);
96 }
97
98 return 0;
99 }
100
101 /* ====================================================================
102
103 Copyright (c) 2011, SIP Spectrum, Inc.
104 All rights reserved.
105
106 Redistribution and use in source and binary forms, with or without
107 modification, are permitted provided that the following conditions are
108 met:
109
110 1. Redistributions of source code must retain the above copyright
111 notice, this list of conditions and the following disclaimer.
112
113 2. Redistributions in binary form must reproduce the above copyright
114 notice, this list of conditions and the following disclaimer in the
115 documentation and/or other materials provided with the distribution.
116
117 3. Neither the name of SIP Spectrum nor the names of its contributors
118 may be used to endorse or promote products derived from this
119 software without specific prior written permission.
120
121 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
122 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
123 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
124 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
125 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
126 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
127 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
128 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
129 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
130 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
131 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
132
133 ==================================================================== */
134

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27