author | Tom Henderson <tomh@tomh.org> |
Fri, 25 Feb 2011 10:32:35 -0800 | |
changeset 6834 | 036f9a0b9899 |
parent 6694 | src/internet-stack/nsc-tcp-socket-impl.cc@a814f37d15bf |
child 7176 | 9f2663992e99 |
permissions | -rw-r--r-- |
3578 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
* |
|
16 |
* based on tcp-socket-impl.cc, Author: Raj Bhattacharjea <raj.b@gatech.edu> |
|
17 |
* Author: Florian Westphal <fw@strlen.de> |
|
18 |
*/ |
|
19 |
||
5887 | 20 |
#define NS_LOG_APPEND_CONTEXT \ |
21 |
if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; } |
|
22 |
||
3578 | 23 |
#include "ns3/node.h" |
24 |
#include "ns3/inet-socket-address.h" |
|
25 |
#include "ns3/log.h" |
|
26 |
#include "ns3/ipv4.h" |
|
27 |
#include "ipv4-end-point.h" |
|
28 |
#include "nsc-tcp-l4-protocol.h" |
|
29 |
#include "nsc-tcp-socket-impl.h" |
|
30 |
#include "ns3/simulation-singleton.h" |
|
31 |
#include "ns3/simulator.h" |
|
32 |
#include "ns3/packet.h" |
|
33 |
#include "ns3/uinteger.h" |
|
34 |
#include "ns3/trace-source-accessor.h" |
|
35 |
||
36 |
#include <algorithm> |
|
37 |
||
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
38 |
// for ntohs(). |
3578 | 39 |
#include <arpa/inet.h> |
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
40 |
#include <netinet/in.h> |
6694 | 41 |
#include "sim_interface.h" |
3578 | 42 |
|
3635
cddd59578812
compile nsc code unconditionally.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3589
diff
changeset
|
43 |
#include "sim_errno.h" |
3578 | 44 |
|
45 |
NS_LOG_COMPONENT_DEFINE ("NscTcpSocketImpl"); |
|
46 |
||
47 |
using namespace std; |
|
48 |
||
49 |
namespace ns3 { |
|
50 |
||
51 |
NS_OBJECT_ENSURE_REGISTERED (NscTcpSocketImpl); |
|
52 |
||
53 |
TypeId |
|
54 |
NscTcpSocketImpl::GetTypeId () |
|
55 |
{ |
|
56 |
static TypeId tid = TypeId("ns3::NscTcpSocketImpl") |
|
57 |
.SetParent<TcpSocket> () |
|
58 |
.AddTraceSource ("CongestionWindow", |
|
59 |
"The TCP connection's congestion window", |
|
60 |
MakeTraceSourceAccessor (&NscTcpSocketImpl::m_cWnd)) |
|
61 |
; |
|
62 |
return tid; |
|
63 |
} |
|
64 |
||
6694 | 65 |
NscTcpSocketImpl::NscTcpSocketImpl () |
3578 | 66 |
: m_endPoint (0), |
67 |
m_node (0), |
|
68 |
m_tcp (0), |
|
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
69 |
m_localAddress (Ipv4Address::GetZero ()), |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
70 |
m_localPort (0), |
3578 | 71 |
m_peerAddress ("0.0.0.0", 0), |
72 |
m_errno (ERROR_NOTERROR), |
|
73 |
m_shutdownSend (false), |
|
74 |
m_shutdownRecv (false), |
|
75 |
m_connected (false), |
|
76 |
m_state (CLOSED), |
|
77 |
m_closeOnEmpty (false), |
|
78 |
m_txBufferSize (0), |
|
79 |
m_lastMeasuredRtt (Seconds(0.0)) |
|
80 |
{ |
|
81 |
NS_LOG_FUNCTION (this); |
|
82 |
} |
|
83 |
||
84 |
NscTcpSocketImpl::NscTcpSocketImpl(const NscTcpSocketImpl& sock) |
|
85 |
: TcpSocket(sock), //copy the base class callbacks |
|
86 |
m_delAckMaxCount (sock.m_delAckMaxCount), |
|
87 |
m_delAckTimeout (sock.m_delAckTimeout), |
|
88 |
m_endPoint (0), |
|
89 |
m_node (sock.m_node), |
|
90 |
m_tcp (sock.m_tcp), |
|
91 |
m_remoteAddress (sock.m_remoteAddress), |
|
92 |
m_remotePort (sock.m_remotePort), |
|
93 |
m_localAddress (sock.m_localAddress), |
|
94 |
m_localPort (sock.m_localPort), |
|
95 |
m_peerAddress (sock.m_peerAddress), |
|
96 |
m_errno (sock.m_errno), |
|
97 |
m_shutdownSend (sock.m_shutdownSend), |
|
98 |
m_shutdownRecv (sock.m_shutdownRecv), |
|
99 |
m_connected (sock.m_connected), |
|
100 |
m_state (sock.m_state), |
|
101 |
m_closeOnEmpty (sock.m_closeOnEmpty), |
|
6319
2b1bbc8d0c58
bug 906: NSC TCP socket fork did not copy txbuffersize over
Antti Mäkelä <zarhan@cc.hut.fi>
parents:
5971
diff
changeset
|
102 |
m_txBufferSize (sock.m_txBufferSize), |
3578 | 103 |
m_segmentSize (sock.m_segmentSize), |
104 |
m_rxWindowSize (sock.m_rxWindowSize), |
|
105 |
m_advertisedWindowSize (sock.m_advertisedWindowSize), |
|
106 |
m_cWnd (sock.m_cWnd), |
|
107 |
m_ssThresh (sock.m_ssThresh), |
|
108 |
m_initialCWnd (sock.m_initialCWnd), |
|
109 |
m_lastMeasuredRtt (Seconds(0.0)), |
|
110 |
m_cnTimeout (sock.m_cnTimeout), |
|
111 |
m_cnCount (sock.m_cnCount), |
|
112 |
m_rxAvailable (0), |
|
113 |
m_nscTcpSocket (0), |
|
114 |
m_sndBufSize (sock.m_sndBufSize) |
|
115 |
{ |
|
116 |
NS_LOG_FUNCTION_NOARGS (); |
|
117 |
NS_LOG_LOGIC("Invoked the copy constructor"); |
|
118 |
//copy the pending data if necessary |
|
119 |
if(!sock.m_txBuffer.empty () ) |
|
120 |
{ |
|
121 |
m_txBuffer = sock.m_txBuffer; |
|
122 |
} |
|
123 |
//can't "copy" the endpoint just yes, must do this when we know the peer info |
|
124 |
//too; this is in SYN_ACK_TX |
|
125 |
} |
|
126 |
||
127 |
NscTcpSocketImpl::~NscTcpSocketImpl () |
|
128 |
{ |
|
129 |
NS_LOG_FUNCTION(this); |
|
130 |
m_node = 0; |
|
131 |
if (m_endPoint != 0) |
|
132 |
{ |
|
133 |
NS_ASSERT (m_tcp != 0); |
|
134 |
/** |
|
135 |
* Note that this piece of code is a bit tricky: |
|
136 |
* when DeAllocate is called, it will call into |
|
137 |
* Ipv4EndPointDemux::Deallocate which triggers |
|
138 |
* a delete of the associated endPoint which triggers |
|
139 |
* in turn a call to the method ::Destroy below |
|
140 |
* will will zero the m_endPoint field. |
|
141 |
*/ |
|
142 |
NS_ASSERT (m_endPoint != 0); |
|
143 |
m_tcp->DeAllocate (m_endPoint); |
|
144 |
NS_ASSERT (m_endPoint == 0); |
|
145 |
} |
|
146 |
m_tcp = 0; |
|
147 |
} |
|
148 |
||
149 |
void |
|
150 |
NscTcpSocketImpl::SetNode (Ptr<Node> node) |
|
151 |
{ |
|
152 |
m_node = node; |
|
153 |
// Initialize some variables |
|
154 |
m_cWnd = m_initialCWnd * m_segmentSize; |
|
155 |
m_rxWindowSize = m_advertisedWindowSize; |
|
156 |
} |
|
157 |
||
158 |
void |
|
159 |
NscTcpSocketImpl::SetTcp (Ptr<NscTcpL4Protocol> tcp) |
|
160 |
{ |
|
161 |
m_nscTcpSocket = tcp->m_nscStack->new_tcp_socket(); |
|
162 |
m_tcp = tcp; |
|
163 |
} |
|
164 |
||
165 |
||
166 |
enum Socket::SocketErrno |
|
167 |
NscTcpSocketImpl::GetErrno (void) const |
|
168 |
{ |
|
169 |
NS_LOG_FUNCTION_NOARGS (); |
|
170 |
return m_errno; |
|
171 |
} |
|
172 |
||
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
173 |
enum Socket::SocketType |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
174 |
NscTcpSocketImpl::GetSocketType (void) const |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
175 |
{ |
6692
591fb1aa0ca4
Avoid enum name collision in socket
Josh Pelkey <jpelkey@gatech.edu>
parents:
6689
diff
changeset
|
176 |
return NS3_SOCK_STREAM; |
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
177 |
} |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
178 |
|
3578 | 179 |
Ptr<Node> |
180 |
NscTcpSocketImpl::GetNode (void) const |
|
181 |
{ |
|
182 |
NS_LOG_FUNCTION_NOARGS (); |
|
183 |
return m_node; |
|
184 |
} |
|
185 |
||
186 |
void |
|
187 |
NscTcpSocketImpl::Destroy (void) |
|
188 |
{ |
|
189 |
NS_LOG_FUNCTION_NOARGS (); |
|
190 |
m_node = 0; |
|
191 |
m_endPoint = 0; |
|
192 |
m_tcp = 0; |
|
193 |
} |
|
194 |
int |
|
195 |
NscTcpSocketImpl::FinishBind (void) |
|
196 |
{ |
|
197 |
NS_LOG_FUNCTION_NOARGS (); |
|
198 |
if (m_endPoint == 0) |
|
199 |
{ |
|
200 |
return -1; |
|
201 |
} |
|
202 |
m_endPoint->SetRxCallback (MakeCallback (&NscTcpSocketImpl::ForwardUp, Ptr<NscTcpSocketImpl>(this))); |
|
203 |
m_endPoint->SetDestroyCallback (MakeCallback (&NscTcpSocketImpl::Destroy, Ptr<NscTcpSocketImpl>(this))); |
|
204 |
m_localAddress = m_endPoint->GetLocalAddress (); |
|
205 |
m_localPort = m_endPoint->GetLocalPort (); |
|
206 |
return 0; |
|
207 |
} |
|
208 |
||
209 |
int |
|
210 |
NscTcpSocketImpl::Bind (void) |
|
211 |
{ |
|
212 |
NS_LOG_FUNCTION_NOARGS (); |
|
213 |
m_endPoint = m_tcp->Allocate (); |
|
214 |
return FinishBind (); |
|
215 |
} |
|
216 |
int |
|
217 |
NscTcpSocketImpl::Bind (const Address &address) |
|
218 |
{ |
|
219 |
NS_LOG_FUNCTION (this<<address); |
|
220 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
221 |
{ |
|
222 |
return ERROR_INVAL; |
|
223 |
} |
|
224 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
|
225 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
|
226 |
uint16_t port = transport.GetPort (); |
|
227 |
if (ipv4 == Ipv4Address::GetAny () && port == 0) |
|
228 |
{ |
|
229 |
m_endPoint = m_tcp->Allocate (); |
|
5888 | 230 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 231 |
} |
232 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
|
233 |
{ |
|
234 |
m_endPoint = m_tcp->Allocate (port); |
|
5888 | 235 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 236 |
} |
237 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
|
238 |
{ |
|
239 |
m_endPoint = m_tcp->Allocate (ipv4); |
|
5888 | 240 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 241 |
} |
242 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
|
243 |
{ |
|
244 |
m_endPoint = m_tcp->Allocate (ipv4, port); |
|
5888 | 245 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 246 |
} |
247 |
||
248 |
m_localPort = port; |
|
249 |
return FinishBind (); |
|
250 |
} |
|
251 |
||
252 |
int |
|
253 |
NscTcpSocketImpl::ShutdownSend (void) |
|
254 |
{ |
|
255 |
NS_LOG_FUNCTION_NOARGS (); |
|
256 |
m_shutdownSend = true; |
|
257 |
return 0; |
|
258 |
} |
|
259 |
int |
|
260 |
NscTcpSocketImpl::ShutdownRecv (void) |
|
261 |
{ |
|
262 |
NS_LOG_FUNCTION_NOARGS (); |
|
4491
893d48fcf7f3
bug 535: UDP/TCP ShutdownRecv incorrect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3869
diff
changeset
|
263 |
m_shutdownRecv = true; |
3578 | 264 |
return 0; |
265 |
} |
|
266 |
||
267 |
int |
|
268 |
NscTcpSocketImpl::Close (void) |
|
269 |
{ |
|
270 |
NS_LOG_FUNCTION (this << m_state); |
|
271 |
||
272 |
if (m_state == CLOSED) |
|
273 |
{ |
|
274 |
return -1; |
|
275 |
} |
|
276 |
if (!m_txBuffer.empty ()) |
|
277 |
{ // App close with pending data must wait until all data transmitted |
|
278 |
m_closeOnEmpty = true; |
|
279 |
NS_LOG_LOGIC("Socket " << this << |
|
280 |
" deferring close, state " << m_state); |
|
281 |
return 0; |
|
282 |
} |
|
283 |
||
5888 | 284 |
NS_LOG_LOGIC("NscTcp socket " << this << " calling disconnect(); moving to CLOSED"); |
3578 | 285 |
m_nscTcpSocket->disconnect(); |
286 |
m_state = CLOSED; |
|
287 |
ShutdownSend (); |
|
288 |
return 0; |
|
289 |
} |
|
290 |
||
291 |
int |
|
292 |
NscTcpSocketImpl::Connect (const Address & address) |
|
293 |
{ |
|
294 |
NS_LOG_FUNCTION (this << address); |
|
295 |
if (m_endPoint == 0) |
|
296 |
{ |
|
297 |
if (Bind () == -1) |
|
298 |
{ |
|
299 |
NS_ASSERT (m_endPoint == 0); |
|
300 |
return -1; |
|
301 |
} |
|
302 |
NS_ASSERT (m_endPoint != 0); |
|
303 |
} |
|
304 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
|
305 |
m_remoteAddress = transport.GetIpv4 (); |
|
306 |
m_remotePort = transport.GetPort (); |
|
307 |
||
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
308 |
std::ostringstream ss; |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
309 |
m_remoteAddress.Print(ss); |
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
310 |
std::string ipstring = ss.str (); |
3578 | 311 |
|
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
312 |
m_nscTcpSocket->connect(ipstring.c_str (), m_remotePort); |
3578 | 313 |
m_state = SYN_SENT; |
314 |
return 0; |
|
315 |
} |
|
316 |
||
317 |
int |
|
318 |
NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags) |
|
319 |
{ |
|
320 |
NS_LOG_FUNCTION (this << p); |
|
321 |
||
322 |
NS_ASSERT (p->GetSize () > 0); |
|
323 |
if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) |
|
324 |
{ |
|
325 |
if (p->GetSize () > GetTxAvailable ()) |
|
326 |
{ |
|
327 |
m_errno = ERROR_MSGSIZE; |
|
328 |
return -1; |
|
329 |
} |
|
330 |
||
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
331 |
uint32_t sent = p->GetSize (); |
3578 | 332 |
if (m_state == ESTABLISHED) |
333 |
{ |
|
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
334 |
m_txBuffer.push(p); |
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
335 |
m_txBufferSize += sent; |
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
336 |
SendPendingData(); |
3578 | 337 |
} |
338 |
else |
|
339 |
{ // SYN_SET -- Queue Data |
|
340 |
m_txBuffer.push(p); |
|
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
341 |
m_txBufferSize += sent; |
3578 | 342 |
} |
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
343 |
return sent; |
3578 | 344 |
} |
345 |
else |
|
346 |
{ |
|
347 |
m_errno = ERROR_NOTCONN; |
|
348 |
return -1; |
|
349 |
} |
|
350 |
} |
|
351 |
||
352 |
int |
|
353 |
NscTcpSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address) |
|
354 |
{ |
|
355 |
NS_LOG_FUNCTION (this << address << p); |
|
356 |
if (!m_connected) |
|
357 |
{ |
|
358 |
m_errno = ERROR_NOTCONN; |
|
359 |
return -1; |
|
360 |
} |
|
361 |
else |
|
362 |
{ |
|
363 |
return Send (p, flags); //drop the address according to BSD manpages |
|
364 |
} |
|
365 |
} |
|
366 |
||
367 |
uint32_t |
|
368 |
NscTcpSocketImpl::GetTxAvailable (void) const |
|
369 |
{ |
|
370 |
NS_LOG_FUNCTION_NOARGS (); |
|
371 |
if (m_txBufferSize != 0) |
|
372 |
{ |
|
373 |
NS_ASSERT (m_txBufferSize <= m_sndBufSize); |
|
374 |
return m_sndBufSize - m_txBufferSize; |
|
375 |
} |
|
376 |
else |
|
377 |
{ |
|
378 |
return m_sndBufSize; |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
int |
|
3772
f0d8608ab155
Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents:
3711
diff
changeset
|
383 |
NscTcpSocketImpl::Listen (void) |
3578 | 384 |
{ |
3772
f0d8608ab155
Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents:
3711
diff
changeset
|
385 |
NS_LOG_FUNCTION (this); |
3578 | 386 |
m_nscTcpSocket->listen(m_localPort); |
387 |
m_state = LISTEN; |
|
388 |
return 0; |
|
389 |
} |
|
390 |
||
391 |
||
392 |
void |
|
393 |
NscTcpSocketImpl::NSCWakeup () |
|
394 |
{ |
|
395 |
switch (m_state) { |
|
396 |
case SYN_SENT: |
|
397 |
if (!m_nscTcpSocket->is_connected()) |
|
398 |
break; |
|
399 |
m_state = ESTABLISHED; |
|
400 |
Simulator::ScheduleNow(&NscTcpSocketImpl::ConnectionSucceeded, this); |
|
401 |
// fall through to schedule read/write events |
|
402 |
case ESTABLISHED: |
|
403 |
if (!m_txBuffer.empty ()) |
|
404 |
Simulator::ScheduleNow(&NscTcpSocketImpl::SendPendingData, this); |
|
405 |
Simulator::ScheduleNow(&NscTcpSocketImpl::ReadPendingData, this); |
|
406 |
break; |
|
407 |
case LISTEN: |
|
408 |
Simulator::ScheduleNow(&NscTcpSocketImpl::Accept, this); |
|
409 |
break; |
|
410 |
case CLOSED: break; |
|
411 |
default: |
|
412 |
NS_LOG_DEBUG (this << " invalid state: " << m_state); |
|
413 |
} |
|
414 |
} |
|
415 |
||
416 |
Ptr<Packet> |
|
417 |
NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) |
|
418 |
{ |
|
419 |
NS_LOG_FUNCTION_NOARGS (); |
|
420 |
if (m_deliveryQueue.empty() ) |
|
421 |
{ |
|
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
422 |
m_errno = ERROR_AGAIN; |
3578 | 423 |
return 0; |
424 |
} |
|
425 |
Ptr<Packet> p = m_deliveryQueue.front (); |
|
426 |
if (p->GetSize () <= maxSize) |
|
427 |
{ |
|
428 |
m_deliveryQueue.pop (); |
|
429 |
m_rxAvailable -= p->GetSize (); |
|
430 |
} |
|
431 |
else |
|
432 |
{ |
|
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
433 |
m_errno = ERROR_AGAIN; |
3578 | 434 |
p = 0; |
435 |
} |
|
436 |
return p; |
|
437 |
} |
|
438 |
||
439 |
Ptr<Packet> |
|
440 |
NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, |
|
441 |
Address &fromAddress) |
|
442 |
{ |
|
443 |
NS_LOG_FUNCTION (this << maxSize << flags); |
|
444 |
Ptr<Packet> packet = Recv (maxSize, flags); |
|
445 |
if (packet != 0) |
|
446 |
{ |
|
447 |
SocketAddressTag tag; |
|
448 |
bool found; |
|
4523
b8bdc36a3355
use packet tags rather than byte tags to match TcpSocketImpl and UdpSocketImpl
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4516
diff
changeset
|
449 |
found = packet->PeekPacketTag (tag); |
3578 | 450 |
NS_ASSERT (found); |
451 |
fromAddress = tag.GetAddress (); |
|
452 |
} |
|
453 |
return packet; |
|
454 |
} |
|
455 |
||
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
456 |
int |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
457 |
NscTcpSocketImpl::GetSockName (Address &address) const |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
458 |
{ |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
459 |
NS_LOG_FUNCTION_NOARGS (); |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
460 |
address = InetSocketAddress(m_localAddress, m_localPort); |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
461 |
return 0; |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
462 |
} |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
463 |
|
3578 | 464 |
uint32_t |
465 |
NscTcpSocketImpl::GetRxAvailable (void) const |
|
466 |
{ |
|
467 |
NS_LOG_FUNCTION_NOARGS (); |
|
468 |
// We separately maintain this state to avoid walking the queue |
|
469 |
// every time this might be called |
|
470 |
return m_rxAvailable; |
|
471 |
} |
|
472 |
||
473 |
void |
|
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
474 |
NscTcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
475 |
Ptr<Ipv4Interface> incomingInterface) |
3578 | 476 |
{ |
477 |
NSCWakeup(); |
|
478 |
} |
|
479 |
||
480 |
void NscTcpSocketImpl::CompleteFork(void) |
|
481 |
{ |
|
482 |
// The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort) |
|
483 |
// are bogus, but this isn't important at the moment, because |
|
484 |
// address <-> Socket handling is done by NSC internally. |
|
485 |
// We only need to add the new ns-3 socket to the list of sockets, so |
|
486 |
// we use plain Allocate() instead of Allocate(m_localAddress, ... ) |
|
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
487 |
struct sockaddr_in sin; |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
488 |
size_t sin_len = sizeof(sin); |
3578 | 489 |
|
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
490 |
if (0 == m_nscTcpSocket->getpeername((struct sockaddr*) &sin, &sin_len)) { |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
491 |
m_remotePort = ntohs(sin.sin_port); |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
492 |
m_remoteAddress = m_remoteAddress.Deserialize((const uint8_t*) &sin.sin_addr); |
3578 | 493 |
m_peerAddress = InetSocketAddress(m_remoteAddress, m_remotePort); |
494 |
} |
|
495 |
||
496 |
m_endPoint = m_tcp->Allocate (); |
|
497 |
||
498 |
//the cloned socket with be in listen state, so manually change state |
|
499 |
NS_ASSERT(m_state == LISTEN); |
|
500 |
m_state = ESTABLISHED; |
|
501 |
||
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
502 |
sin_len = sizeof(sin); |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
503 |
|
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
504 |
if (0 == m_nscTcpSocket->getsockname((struct sockaddr *) &sin, &sin_len)) |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
505 |
m_localAddress = m_localAddress.Deserialize((const uint8_t*) &sin.sin_addr); |
3578 | 506 |
|
507 |
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from " |
|
508 |
<< m_remoteAddress << ":" << m_remotePort |
|
509 |
<< " to " << m_localAddress << ":" << m_localPort); |
|
510 |
//equivalent to FinishBind |
|
511 |
m_endPoint->SetRxCallback (MakeCallback (&NscTcpSocketImpl::ForwardUp, Ptr<NscTcpSocketImpl>(this))); |
|
512 |
m_endPoint->SetDestroyCallback (MakeCallback (&NscTcpSocketImpl::Destroy, Ptr<NscTcpSocketImpl>(this))); |
|
513 |
||
514 |
NotifyNewConnectionCreated (this, m_peerAddress); |
|
515 |
} |
|
516 |
||
517 |
void NscTcpSocketImpl::ConnectionSucceeded() |
|
518 |
{ // We would preferred to have scheduled an event directly to |
|
519 |
// NotifyConnectionSucceeded, but (sigh) these are protected |
|
520 |
// and we can get the address of it :( |
|
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
521 |
struct sockaddr_in sin; |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
522 |
size_t sin_len = sizeof(sin); |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
523 |
if (0 == m_nscTcpSocket->getsockname((struct sockaddr *) &sin, &sin_len)) { |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
524 |
m_localAddress = m_localAddress.Deserialize((const uint8_t*)&sin.sin_addr); |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
525 |
m_localPort = ntohs(sin.sin_port); |
3578 | 526 |
} |
527 |
||
528 |
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to " |
|
529 |
<< m_remoteAddress << ":" << m_remotePort |
|
530 |
<< " from " << m_localAddress << ":" << m_localPort); |
|
531 |
NotifyConnectionSucceeded(); |
|
532 |
} |
|
533 |
||
534 |
||
535 |
bool NscTcpSocketImpl::Accept (void) |
|
536 |
{ |
|
537 |
if (m_state == CLOSED) |
|
538 |
{ // Happens if application closes listening socket after Accept() was scheduled. |
|
539 |
return false; |
|
540 |
} |
|
541 |
NS_ASSERT (m_state == LISTEN); |
|
542 |
||
543 |
if (!m_nscTcpSocket->is_listening()) |
|
544 |
{ |
|
545 |
return false; |
|
546 |
} |
|
547 |
INetStreamSocket *newsock; |
|
548 |
int res = m_nscTcpSocket->accept(&newsock); |
|
549 |
if (res != 0) |
|
550 |
{ |
|
551 |
return false; |
|
552 |
} |
|
553 |
// We could obtain a fromAddress using getpeername, but we've already |
|
554 |
// finished the tcp handshake here, i.e. this is a new connection |
|
555 |
// and not a connection request. |
|
556 |
// if (!NotifyConnectionRequest(fromAddress)) |
|
557 |
// return true; |
|
558 |
||
559 |
// Clone the socket |
|
560 |
Ptr<NscTcpSocketImpl> newSock = Copy (); |
|
561 |
newSock->m_nscTcpSocket = newsock; |
|
562 |
NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock); |
|
563 |
||
564 |
Simulator::ScheduleNow (&NscTcpSocketImpl::CompleteFork, newSock); |
|
565 |
return true; |
|
566 |
} |
|
567 |
||
568 |
bool NscTcpSocketImpl::ReadPendingData (void) |
|
569 |
{ |
|
570 |
if (m_state != ESTABLISHED) |
|
571 |
{ |
|
572 |
return false; |
|
573 |
} |
|
574 |
int len, err; |
|
575 |
uint8_t buffer[8192]; |
|
576 |
len = sizeof(buffer); |
|
577 |
m_errno = ERROR_NOTERROR; |
|
578 |
err = m_nscTcpSocket->read_data(buffer, &len); |
|
579 |
if (err == 0 && len == 0) |
|
580 |
{ |
|
581 |
NS_LOG_LOGIC ("ReadPendingData got EOF from socket"); |
|
5889
526381e48c1d
Fix NSC improper response to FIN
Tom Henderson <tomh@tomh.org>
parents:
5888
diff
changeset
|
582 |
m_state = CLOSE_WAIT; |
3578 | 583 |
return false; |
584 |
} |
|
585 |
m_errno = GetNativeNs3Errno(err); |
|
586 |
switch (m_errno) |
|
587 |
{ |
|
588 |
case ERROR_NOTERROR: break; // some data was sent |
|
589 |
case ERROR_AGAIN: return false; |
|
590 |
default: |
|
591 |
NS_LOG_WARN ("Error (" << err << ") " << |
|
592 |
"during read_data, ns-3 errno set to" << m_errno); |
|
593 |
m_state = CLOSED; |
|
594 |
return false; |
|
595 |
} |
|
596 |
||
597 |
Ptr<Packet> p = Create<Packet> (buffer, len); |
|
598 |
||
599 |
SocketAddressTag tag; |
|
600 |
||
601 |
tag.SetAddress (m_peerAddress); |
|
4523
b8bdc36a3355
use packet tags rather than byte tags to match TcpSocketImpl and UdpSocketImpl
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4516
diff
changeset
|
602 |
p->AddPacketTag (tag); |
3578 | 603 |
m_deliveryQueue.push (p); |
604 |
m_rxAvailable += p->GetSize (); |
|
605 |
||
606 |
NotifyDataRecv (); |
|
607 |
return true; |
|
608 |
} |
|
609 |
||
610 |
bool NscTcpSocketImpl::SendPendingData (void) |
|
611 |
{ |
|
612 |
NS_LOG_FUNCTION (this); |
|
613 |
NS_LOG_LOGIC ("ENTERING SendPendingData"); |
|
614 |
||
615 |
if (m_txBuffer.empty ()) |
|
616 |
{ |
|
617 |
return false; |
|
618 |
} |
|
619 |
||
620 |
int ret; |
|
621 |
size_t size, written = 0; |
|
622 |
||
623 |
do { |
|
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
624 |
NS_ASSERT (!m_txBuffer.empty ()); |
3578 | 625 |
Ptr<Packet> &p = m_txBuffer.front (); |
626 |
size = p->GetSize (); |
|
627 |
NS_ASSERT (size > 0); |
|
628 |
||
629 |
m_errno = ERROR_NOTERROR; |
|
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
630 |
|
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
631 |
uint8_t *buf = new uint8_t[size]; |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
632 |
p->CopyData (buf, size); |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
633 |
ret = m_nscTcpSocket->send_data((const char *)buf, size); |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
634 |
delete[] buf; |
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
635 |
|
3578 | 636 |
if (ret <= 0) |
637 |
{ |
|
638 |
break; |
|
639 |
} |
|
640 |
written += ret; |
|
641 |
||
642 |
NS_ASSERT (m_txBufferSize >= (size_t)ret); |
|
643 |
m_txBufferSize -= ret; |
|
644 |
||
645 |
if ((size_t)ret < size) |
|
646 |
{ |
|
647 |
p->RemoveAtStart(ret); |
|
648 |
break; |
|
649 |
} |
|
650 |
||
651 |
m_txBuffer.pop (); |
|
652 |
||
653 |
if (m_txBuffer.empty ()) |
|
654 |
{ |
|
655 |
if (m_closeOnEmpty) |
|
656 |
{ |
|
657 |
m_nscTcpSocket->disconnect(); |
|
658 |
m_state = CLOSED; |
|
659 |
} |
|
660 |
break; |
|
661 |
} |
|
662 |
} while ((size_t) ret == size); |
|
663 |
||
664 |
if (written > 0) |
|
665 |
{ |
|
666 |
Simulator::ScheduleNow(&NscTcpSocketImpl::NotifyDataSent, this, ret); |
|
667 |
return true; |
|
668 |
} |
|
669 |
return false; |
|
670 |
} |
|
671 |
||
672 |
Ptr<NscTcpSocketImpl> NscTcpSocketImpl::Copy () |
|
673 |
{ |
|
674 |
return CopyObject<NscTcpSocketImpl> (this); |
|
675 |
} |
|
676 |
||
677 |
void |
|
678 |
NscTcpSocketImpl::SetSndBufSize (uint32_t size) |
|
679 |
{ |
|
680 |
m_sndBufSize = size; |
|
681 |
} |
|
682 |
||
683 |
uint32_t |
|
684 |
NscTcpSocketImpl::GetSndBufSize (void) const |
|
685 |
{ |
|
686 |
return m_sndBufSize; |
|
687 |
} |
|
688 |
||
689 |
void |
|
690 |
NscTcpSocketImpl::SetRcvBufSize (uint32_t size) |
|
691 |
{ |
|
692 |
m_rcvBufSize = size; |
|
693 |
} |
|
694 |
||
695 |
uint32_t |
|
696 |
NscTcpSocketImpl::GetRcvBufSize (void) const |
|
697 |
{ |
|
698 |
return m_rcvBufSize; |
|
699 |
} |
|
700 |
||
701 |
void |
|
702 |
NscTcpSocketImpl::SetSegSize (uint32_t size) |
|
703 |
{ |
|
704 |
m_segmentSize = size; |
|
705 |
} |
|
706 |
||
707 |
uint32_t |
|
708 |
NscTcpSocketImpl::GetSegSize (void) const |
|
709 |
{ |
|
710 |
return m_segmentSize; |
|
711 |
} |
|
712 |
||
713 |
void |
|
714 |
NscTcpSocketImpl::SetAdvWin (uint32_t window) |
|
715 |
{ |
|
716 |
m_advertisedWindowSize = window; |
|
717 |
} |
|
718 |
||
719 |
uint32_t |
|
720 |
NscTcpSocketImpl::GetAdvWin (void) const |
|
721 |
{ |
|
722 |
return m_advertisedWindowSize; |
|
723 |
} |
|
724 |
||
725 |
void |
|
726 |
NscTcpSocketImpl::SetSSThresh (uint32_t threshold) |
|
727 |
{ |
|
728 |
m_ssThresh = threshold; |
|
729 |
} |
|
730 |
||
731 |
uint32_t |
|
732 |
NscTcpSocketImpl::GetSSThresh (void) const |
|
733 |
{ |
|
734 |
return m_ssThresh; |
|
735 |
} |
|
736 |
||
737 |
void |
|
738 |
NscTcpSocketImpl::SetInitialCwnd (uint32_t cwnd) |
|
739 |
{ |
|
740 |
m_initialCWnd = cwnd; |
|
741 |
} |
|
742 |
||
743 |
uint32_t |
|
744 |
NscTcpSocketImpl::GetInitialCwnd (void) const |
|
745 |
{ |
|
746 |
return m_initialCWnd; |
|
747 |
} |
|
748 |
||
749 |
void |
|
750 |
NscTcpSocketImpl::SetConnTimeout (Time timeout) |
|
751 |
{ |
|
752 |
m_cnTimeout = timeout; |
|
753 |
} |
|
754 |
||
755 |
Time |
|
756 |
NscTcpSocketImpl::GetConnTimeout (void) const |
|
757 |
{ |
|
758 |
return m_cnTimeout; |
|
759 |
} |
|
760 |
||
761 |
void |
|
762 |
NscTcpSocketImpl::SetConnCount (uint32_t count) |
|
763 |
{ |
|
764 |
m_cnCount = count; |
|
765 |
} |
|
766 |
||
767 |
uint32_t |
|
768 |
NscTcpSocketImpl::GetConnCount (void) const |
|
769 |
{ |
|
770 |
return m_cnCount; |
|
771 |
} |
|
772 |
||
773 |
void |
|
774 |
NscTcpSocketImpl::SetDelAckTimeout (Time timeout) |
|
775 |
{ |
|
776 |
m_delAckTimeout = timeout; |
|
777 |
} |
|
778 |
||
779 |
Time |
|
780 |
NscTcpSocketImpl::GetDelAckTimeout (void) const |
|
781 |
{ |
|
782 |
return m_delAckTimeout; |
|
783 |
} |
|
784 |
||
785 |
void |
|
786 |
NscTcpSocketImpl::SetDelAckMaxCount (uint32_t count) |
|
787 |
{ |
|
788 |
m_delAckMaxCount = count; |
|
789 |
} |
|
790 |
||
791 |
uint32_t |
|
792 |
NscTcpSocketImpl::GetDelAckMaxCount (void) const |
|
793 |
{ |
|
794 |
return m_delAckMaxCount; |
|
795 |
} |
|
796 |
||
6694 | 797 |
void |
798 |
NscTcpSocketImpl::SetPersistTimeout (Time timeout) |
|
799 |
{ |
|
800 |
m_persistTimeout = timeout; |
|
801 |
} |
|
802 |
||
803 |
Time |
|
804 |
NscTcpSocketImpl::GetPersistTimeout (void) const |
|
805 |
{ |
|
806 |
return m_persistTimeout; |
|
807 |
} |
|
808 |
||
3578 | 809 |
enum Socket::SocketErrno |
810 |
NscTcpSocketImpl::GetNativeNs3Errno(int error) const |
|
811 |
{ |
|
812 |
enum nsc_errno err; |
|
813 |
||
814 |
if (error >= 0) |
|
815 |
{ |
|
816 |
return ERROR_NOTERROR; |
|
817 |
} |
|
818 |
err = (enum nsc_errno) error; |
|
819 |
switch (err) |
|
820 |
{ |
|
821 |
case NSC_EADDRINUSE: // fallthrough |
|
822 |
case NSC_EADDRNOTAVAIL: return ERROR_AFNOSUPPORT; |
|
823 |
case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not. |
|
824 |
case NSC_EAGAIN: return ERROR_AGAIN; |
|
825 |
case NSC_EISCONN: // fallthrough |
|
826 |
case NSC_EALREADY: return ERROR_ISCONN; |
|
827 |
case NSC_ECONNREFUSED: return ERROR_NOROUTETOHOST; // XXX, better mapping? |
|
828 |
case NSC_ECONNRESET: // for no, all of these fall through |
|
829 |
case NSC_EHOSTDOWN: |
|
830 |
case NSC_ENETUNREACH: |
|
831 |
case NSC_EHOSTUNREACH: return ERROR_NOROUTETOHOST; |
|
832 |
case NSC_EMSGSIZE: return ERROR_MSGSIZE; |
|
833 |
case NSC_ENOTCONN: return ERROR_NOTCONN; |
|
834 |
case NSC_ESHUTDOWN: return ERROR_SHUTDOWN; |
|
835 |
case NSC_ETIMEDOUT: return ERROR_NOTCONN; // XXX - this mapping isn't correct |
|
836 |
case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally, |
|
837 |
// but is triggered by e.g. show_config(). |
|
838 |
case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping |
|
839 |
} |
|
840 |
NS_ASSERT_MSG(0, "Unknown NSC error"); |
|
841 |
return ERROR_INVAL; |
|
842 |
} |
|
843 |
||
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
844 |
bool |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
845 |
NscTcpSocketImpl::SetAllowBroadcast (bool allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
846 |
{ |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
847 |
if (allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
848 |
{ |
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
849 |
return false; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
850 |
} |
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
851 |
return true; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
852 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
853 |
|
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
854 |
bool |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
855 |
NscTcpSocketImpl::GetAllowBroadcast () const |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
856 |
{ |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
857 |
return false; |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
858 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
859 |
|
3578 | 860 |
}//namespace ns3 |