/[resiprocate]/main/resip/stack/test/Transceiver.cxx
ViewVC logotype

Annotation of /main/resip/stack/test/Transceiver.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5948 - (hide annotations) (download)
Fri Feb 17 15:30:16 2006 UTC (13 years, 11 months ago) by dworley
File MIME type: text/plain
File size: 6115 byte(s)
Setting more svn: properties, and adding EOLs to the ends of files
that need it.

1 derekm 676 #include <sys/time.h>
2     #include <sys/types.h>
3     #include <unistd.h>
4     #include <iostream>
5    
6     #include <sys/socket.h>
7     #include <netinet/in.h>
8     #include <arpa/inet.h>
9    
10     #include "Transceiver.hxx"
11 jason 5276 #include "rutil/Logger.hxx"
12     #include "rutil/DataStream.hxx"
13     #include "rutil/DnsUtil.hxx"
14     #include "rutil/Timer.hxx"
15 derekm 676
16    
17 jason 1305 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
18 derekm 676
19     using namespace std;
20 jason 1305 using namespace resip;
21 derekm 676 using namespace Loadgen;
22    
23     Transceiver::Transceiver(int port)
24 jason 1746 : mUdp(mReceived, port)
25 derekm 676 {
26 davidb 1800 mContactUri.host() = DnsUtil::getLocalHostName();
27 derekm 676 mContactUri.port() = mUdp.port();
28     mContactUri.param(p_transport) = Transport::toData(mUdp.transport());
29     }
30    
31     void
32     Transceiver::send(SipMessage& message)
33     {
34     Uri target;
35     if (message.isRequest())
36     {
37     if (message.header(h_Routes).size() && !message.header(h_Routes).front().exists(p_lr))
38     {
39     target = message.header(h_Routes).front().uri();
40     }
41     else
42     {
43     target = message.header(h_RequestLine).uri();
44     }
45     }
46     else if (message.isResponse())
47     {
48     assert (!message.header(h_Vias).empty());
49     const Via& via = message.header(h_Vias).front();
50    
51     // should look at via.transport()
52     target.param(p_transport) = Symbols::UDP; // !jf!
53     target.host() = via.sentHost();
54     target.port() = via.sentPort();
55    
56     if (via.exists(p_received))
57     {
58     target.host() = via.param(p_received);
59     }
60     if (via.exists(p_rport))
61     {
62 davidb 1087 target.port() = via.param(p_rport).port();
63 derekm 676 }
64     }
65     else
66     {
67     assert(0);
68     }
69    
70     // do a dns lookup !jf!
71     // should only do this once and store in the SipMessage (or somewhere)
72     DebugLog(<<"Trying to resolve target: " << target);
73     Resolver resolver(target);
74    
75     send(target, message);
76     }
77    
78    
79     void
80     Transceiver::send(const Resolver& target,
81     SipMessage& message)
82     {
83     DebugLog(<< message.header(h_Vias).size() );
84    
85     if (message.isRequest())
86     {
87     assert(!message.header(h_Vias).empty());
88     message.header(h_Vias).front().transport() = Transport::toData(mUdp.transport());
89 davidb 1800 message.header(h_Vias).front().sentHost() = DnsUtil::getLocalHostName();
90 derekm 676 message.header(h_Vias).front().sentPort() = mUdp.port();
91     }
92    
93     Data& encoded = message.getEncoded();
94     DataStream strm(encoded);
95     message.encode(strm);
96     strm.flush();
97     mUdp.send(target.mNextHops.front(), encoded, "bogus");
98     mUdp.process(mFdset);
99     }
100    
101     SipMessage*
102     Transceiver::receive(int waitMs)
103     {
104     UInt64 startTime = Timer::getTimeMs();
105    
106     UInt64 currentTime = Timer::getTimeMs();
107    
108 fluffy 712 while( UInt64(waitMs) > currentTime - startTime)
109 derekm 676 {
110     int timeLeft = waitMs - (currentTime - startTime);
111     if (!mReceived.messageAvailable())
112     {
113     mUdp.buildFdSet(mFdset);
114    
115 derekm 1009 int err = mFdset.selectMilliSeconds(timeLeft);
116 derekm 676 int e = errno;
117     if ( err == -1 )
118     {
119     InfoLog(<< "Error " << e << " " << strerror(e) << " in select");
120     }
121    
122     DebugLog(<<"Calling process in Transceiver::receive");
123     mUdp.process(mFdset);
124     }
125    
126     if (mReceived.messageAvailable())
127     {
128     Message* msg = mReceived.getNext();
129     DebugLog(<<"Received a message in the transceiver, " << msg);
130    
131     SipMessage* next = dynamic_cast<SipMessage*>(msg);
132     DebugLog(<<"Dynamic cast resulted in: " << next);
133     if (next)
134     {
135     DebugLog(<<"Received a sip message in the transceiver.");
136     return next;
137     }
138     else
139     {
140     DebugLog(<<"Which was apparently not a sip message.");
141     delete msg;
142     }
143     }
144     currentTime = Timer::getTimeMs();
145     }
146     return 0;
147     }
148 fluffy 1796 /* ====================================================================
149     * The Vovida Software License, Version 1.0
150     *
151     * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
152     *
153     * Redistribution and use in source and binary forms, with or without
154     * modification, are permitted provided that the following conditions
155     * are met:
156     *
157     * 1. Redistributions of source code must retain the above copyright
158     * notice, this list of conditions and the following disclaimer.
159     *
160     * 2. Redistributions in binary form must reproduce the above copyright
161     * notice, this list of conditions and the following disclaimer in
162     * the documentation and/or other materials provided with the
163     * distribution.
164     *
165     * 3. The names "VOCAL", "Vovida Open Communication Application Library",
166     * and "Vovida Open Communication Application Library (VOCAL)" must
167     * not be used to endorse or promote products derived from this
168     * software without prior written permission. For written
169     * permission, please contact vocal@vovida.org.
170     *
171     * 4. Products derived from this software may not be called "VOCAL", nor
172     * may "VOCAL" appear in their name, without prior written
173     * permission of Vovida Networks, Inc.
174     *
175     * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
176     * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
177     * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
178     * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
179     * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
180     * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
181     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
182     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
183     * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
184     * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
185     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
186     * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
187     * DAMAGE.
188     *
189     * ====================================================================
190     *
191     * This software consists of voluntary contributions made by Vovida
192     * Networks, Inc. and many individuals on behalf of Vovida Networks,
193     * Inc. For more information on Vovida Networks, Inc., please see
194     * <http://www.vovida.org/>.
195     *
196     */

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