Lines 198-203
TcpSocketImpl::~TcpSocketImpl ()
|
Link Here
|
---|
|
198 |
m_tcp = 0; |
198 |
m_tcp = 0; |
199 |
delete m_pendingData; //prevents leak |
199 |
delete m_pendingData; //prevents leak |
200 |
m_pendingData = 0; |
200 |
m_pendingData = 0; |
|
|
201 |
CancelAllTimers(); |
201 |
} |
202 |
} |
202 |
|
203 |
|
203 |
void |
204 |
void |
Lines 329-342
TcpSocketImpl::Close (void)
|
Link Here
|
---|
|
329 |
TcpSocketImpl::Close (void) |
330 |
TcpSocketImpl::Close (void) |
330 |
{ |
331 |
{ |
331 |
NS_LOG_FUNCTION_NOARGS (); |
332 |
NS_LOG_FUNCTION_NOARGS (); |
332 |
if (m_pendingData && m_pendingData->Size() != 0) |
333 |
// First we check to see if there is any unread rx data |
|
|
334 |
// Bug number 426 claims we should send reset in this case. |
335 |
if (!m_bufferedData.empty()) |
336 |
{ |
337 |
SendRST(); |
338 |
return 0; |
339 |
} |
340 |
|
341 |
uint32_t remainingData = 0; |
342 |
if (m_pendingData) |
343 |
{ |
344 |
remainingData = m_pendingData->SizeFromSeq (m_firstPendingSequence, |
345 |
m_nextTxSequence); |
346 |
} |
347 |
|
348 |
if (remainingData != 0) |
333 |
{ // App close with pending data must wait until all data transmitted |
349 |
{ // App close with pending data must wait until all data transmitted |
334 |
m_closeOnEmpty = true; |
350 |
m_closeOnEmpty = true; |
335 |
NS_LOG_LOGIC("Socket " << this << |
351 |
NS_LOG_LOGIC("Socket " << this << |
336 |
" deferring close, state " << m_state); |
352 |
" deferring close, state " << m_state); |
337 |
return 0; |
353 |
return 0; |
338 |
} |
354 |
} |
339 |
|
|
|
340 |
Actions_t action = ProcessEvent (APP_CLOSE); |
355 |
Actions_t action = ProcessEvent (APP_CLOSE); |
341 |
ProcessAction (action); |
356 |
ProcessAction (action); |
342 |
return 0; |
357 |
return 0; |
Lines 460-468
int TcpSocketImpl::DoSendTo (Ptr<Packet>
|
Link Here
|
---|
|
460 |
m_errno = ERROR_SHUTDOWN; |
475 |
m_errno = ERROR_SHUTDOWN; |
461 |
return -1; |
476 |
return -1; |
462 |
} |
477 |
} |
|
|
478 |
// Get the size before sending to tcp, as the sent callback cares |
479 |
// about payload sent, not with headers |
480 |
uint32_t sentSize = p->GetSize(); |
463 |
m_tcp->Send (p, m_endPoint->GetLocalAddress (), ipv4, |
481 |
m_tcp->Send (p, m_endPoint->GetLocalAddress (), ipv4, |
464 |
m_endPoint->GetLocalPort (), port); |
482 |
m_endPoint->GetLocalPort (), port); |
465 |
NotifyDataSent (p->GetSize ()); |
483 |
NotifyDataSent (sentSize); |
466 |
return 0; |
484 |
return 0; |
467 |
} |
485 |
} |
468 |
|
486 |
|
Lines 638-643
TcpSocketImpl::ForwardUp (Ptr<Packet> pa
|
Link Here
|
---|
|
638 |
TcpHeader tcpHeader; |
656 |
TcpHeader tcpHeader; |
639 |
packet->RemoveHeader (tcpHeader); |
657 |
packet->RemoveHeader (tcpHeader); |
640 |
|
658 |
|
|
|
659 |
if (tcpHeader.GetFlags () & TcpHeader::RST) |
660 |
{ // Got an RST, just shut everything down |
661 |
NotifyErrorClose(); |
662 |
CancelAllTimers(); |
663 |
m_endPoint->SetDestroyCallback(MakeNullCallback<void>()); |
664 |
m_tcp->DeAllocate (m_endPoint); |
665 |
m_endPoint = 0; |
666 |
return; |
667 |
} |
668 |
|
641 |
if (tcpHeader.GetFlags () & TcpHeader::ACK) |
669 |
if (tcpHeader.GetFlags () & TcpHeader::ACK) |
642 |
{ |
670 |
{ |
643 |
Time m = m_rtt->AckSeq (tcpHeader.GetAckNumber () ); |
671 |
Time m = m_rtt->AckSeq (tcpHeader.GetAckNumber () ); |
Lines 677-682
Actions_t TcpSocketImpl::ProcessEvent (E
|
Link Here
|
---|
|
677 |
{ |
705 |
{ |
678 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " sending RST from state " |
706 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " sending RST from state " |
679 |
<< saveState << " event " << e); |
707 |
<< saveState << " event " << e); |
|
|
708 |
SendRST(); |
709 |
return NO_ACT; |
680 |
} |
710 |
} |
681 |
bool needCloseNotify = (stateAction.state == CLOSED && m_state != CLOSED |
711 |
bool needCloseNotify = (stateAction.state == CLOSED && m_state != CLOSED |
682 |
&& e != TIMEOUT); |
712 |
&& e != TIMEOUT); |
Lines 692-698
Actions_t TcpSocketImpl::ProcessEvent (E
|
Link Here
|
---|
|
692 |
// the handshaking |
722 |
// the handshaking |
693 |
{ |
723 |
{ |
694 |
Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this); |
724 |
Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this); |
695 |
//NotifyConnectionSucceeded (); |
|
|
696 |
m_connected = true; |
725 |
m_connected = true; |
697 |
m_endPoint->SetPeer (m_remoteAddress, m_remotePort); |
726 |
m_endPoint->SetPeer (m_remoteAddress, m_remotePort); |
698 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!"); |
727 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!"); |
Lines 708-713
Actions_t TcpSocketImpl::ProcessEvent (E
|
Link Here
|
---|
|
708 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " |
737 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " |
709 |
<< m_state << " event " << e << " closeNot " << m_closeNotified |
738 |
<< m_state << " event " << e << " closeNot " << m_closeNotified |
710 |
<< " action " << stateAction.action); |
739 |
<< " action " << stateAction.action); |
|
|
740 |
NotifyNormalClose(); |
711 |
m_closeNotified = true; |
741 |
m_closeNotified = true; |
712 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE" |
742 |
NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE" |
713 |
<< " origState " << saveState |
743 |
<< " origState " << saveState |
Lines 732-737
Actions_t TcpSocketImpl::ProcessEvent (E
|
Link Here
|
---|
|
732 |
m_endPoint->SetDestroyCallback(MakeNullCallback<void>()); |
762 |
m_endPoint->SetDestroyCallback(MakeNullCallback<void>()); |
733 |
m_tcp->DeAllocate (m_endPoint); |
763 |
m_tcp->DeAllocate (m_endPoint); |
734 |
m_endPoint = 0; |
764 |
m_endPoint = 0; |
|
|
765 |
CancelAllTimers(); |
735 |
} |
766 |
} |
736 |
|
767 |
|
737 |
return stateAction.action; |
768 |
return stateAction.action; |
Lines 776-781
void TcpSocketImpl::SendEmptyPacket (uin
|
Link Here
|
---|
|
776 |
} |
807 |
} |
777 |
} |
808 |
} |
778 |
|
809 |
|
|
|
810 |
// This function closes the endpoint completely |
811 |
void TcpSocketImpl::SendRST() |
812 |
{ |
813 |
SendEmptyPacket(TcpHeader::RST); |
814 |
NotifyErrorClose(); |
815 |
CancelAllTimers(); |
816 |
m_endPoint->SetDestroyCallback(MakeNullCallback<void>()); |
817 |
m_tcp->DeAllocate (m_endPoint); |
818 |
m_endPoint = 0; |
819 |
} |
820 |
|
821 |
|
779 |
bool TcpSocketImpl::ProcessAction (Actions_t a) |
822 |
bool TcpSocketImpl::ProcessAction (Actions_t a) |
780 |
{ // These actions do not require a packet or any TCP Headers |
823 |
{ // These actions do not require a packet or any TCP Headers |
781 |
NS_LOG_FUNCTION (this << a); |
824 |
NS_LOG_FUNCTION (this << a); |
Lines 976-981
bool TcpSocketImpl::ProcessPacketAction
|
Link Here
|
---|
|
976 |
break; |
1019 |
break; |
977 |
case PEER_CLOSE: |
1020 |
case PEER_CLOSE: |
978 |
{ |
1021 |
{ |
|
|
1022 |
NS_LOG_LOGIC("Got Peer Close"); |
979 |
// First we have to be sure the FIN packet was not received |
1023 |
// First we have to be sure the FIN packet was not received |
980 |
// out of sequence. If so, note pending close and process |
1024 |
// out of sequence. If so, note pending close and process |
981 |
// new sequence rx |
1025 |
// new sequence rx |
Lines 1002-1007
bool TcpSocketImpl::ProcessPacketAction
|
Link Here
|
---|
|
1002 |
{ |
1046 |
{ |
1003 |
NS_LOG_LOGIC ("TCP " << this |
1047 |
NS_LOG_LOGIC ("TCP " << this |
1004 |
<< " calling AppCloseRequest"); |
1048 |
<< " calling AppCloseRequest"); |
|
|
1049 |
NotifyNormalClose(); |
1005 |
m_closeRequestNotified = true; |
1050 |
m_closeRequestNotified = true; |
1006 |
} |
1051 |
} |
1007 |
NS_LOG_LOGIC ("TcpSocketImpl " << this |
1052 |
NS_LOG_LOGIC ("TcpSocketImpl " << this |
Lines 1132-1139
bool TcpSocketImpl::SendPendingData (boo
|
Link Here
|
---|
|
1132 |
m_endPoint->GetLocalAddress (), |
1177 |
m_endPoint->GetLocalAddress (), |
1133 |
m_remoteAddress); |
1178 |
m_remoteAddress); |
1134 |
m_rtt->SentSeq(m_nextTxSequence, sz); // notify the RTT |
1179 |
m_rtt->SentSeq(m_nextTxSequence, sz); // notify the RTT |
1135 |
// Notify the application |
1180 |
// Notify the application of the data being sent |
1136 |
Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, p->GetSize ()); |
1181 |
Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, sz); |
1137 |
nPacketsSent++; // Count sent this loop |
1182 |
nPacketsSent++; // Count sent this loop |
1138 |
m_nextTxSequence += sz; // Advance next tx sequence |
1183 |
m_nextTxSequence += sz; // Advance next tx sequence |
1139 |
// Note the high water mark |
1184 |
// Note the high water mark |
Lines 1406-1412
void TcpSocketImpl::CommonNewAck (Sequen
|
Link Here
|
---|
|
1406 |
// and MUST be called by any subclass, from the NewAck function |
1451 |
// and MUST be called by any subclass, from the NewAck function |
1407 |
// Always cancel any pending re-tx timer on new acknowledgement |
1452 |
// Always cancel any pending re-tx timer on new acknowledgement |
1408 |
NS_LOG_FUNCTION (this << ack << skipTimer); |
1453 |
NS_LOG_FUNCTION (this << ack << skipTimer); |
1409 |
//DEBUG(1,(cout << "TCP " << this << "Cancelling retx timer " << endl)); |
|
|
1410 |
if (!skipTimer) |
1454 |
if (!skipTimer) |
1411 |
{ |
1455 |
{ |
1412 |
NS_LOG_LOGIC (this<<" Cancelled ReTxTimeout event which was set to expire at " |
1456 |
NS_LOG_LOGIC (this<<" Cancelled ReTxTimeout event which was set to expire at " |
Lines 1465-1470
void TcpSocketImpl::CommonNewAck (Sequen
|
Link Here
|
---|
|
1465 |
SendPendingData (m_connected); |
1509 |
SendPendingData (m_connected); |
1466 |
} |
1510 |
} |
1467 |
|
1511 |
|
|
|
1512 |
void TcpSocketImpl::CancelAllTimers() |
1513 |
{ |
1514 |
m_retxEvent.Cancel (); |
1515 |
m_persistEvent.Cancel (); |
1516 |
m_delAckEvent.Cancel(); |
1517 |
m_lastAckEvent.Cancel (); |
1518 |
} |
1519 |
|
1468 |
Ptr<TcpSocketImpl> TcpSocketImpl::Copy () |
1520 |
Ptr<TcpSocketImpl> TcpSocketImpl::Copy () |
1469 |
{ |
1521 |
{ |
1470 |
return CopyObject<TcpSocketImpl> (this); |
1522 |
return CopyObject<TcpSocketImpl> (this); |