diff -r 80601ddf444a examples/tcp-large-transfer.cc --- a/examples/tcp-large-transfer.cc Mon Mar 23 00:06:28 2009 -0400 +++ b/examples/tcp-large-transfer.cc Mon Mar 30 01:49:51 2009 -0400 @@ -212,5 +212,5 @@ return; } } - localSocket->Close (); + localSocket->ShutdownSend (); } diff -r 80601ddf444a src/internet-stack/tcp-socket-impl.cc --- a/src/internet-stack/tcp-socket-impl.cc Mon Mar 23 00:06:28 2009 -0400 +++ b/src/internet-stack/tcp-socket-impl.cc Mon Mar 30 01:49:51 2009 -0400 @@ -73,6 +73,7 @@ m_closeRequestNotified (false), m_closeOnEmpty (false), m_pendingClose (false), + m_closeCalled (false), m_nextTxSequence (0), m_highTxMark (0), m_highestRxAck (0), @@ -112,6 +113,7 @@ m_closeRequestNotified (sock.m_closeRequestNotified), m_closeOnEmpty (sock.m_closeOnEmpty), m_pendingClose (sock.m_pendingClose), + m_closeCalled (sock.m_closeCalled), m_nextTxSequence (sock.m_nextTxSequence), m_highTxMark (sock.m_highTxMark), m_highestRxAck (sock.m_highestRxAck), @@ -294,6 +296,16 @@ TcpSocketImpl::ShutdownSend (void) { NS_LOG_FUNCTION_NOARGS (); + if (m_pendingData && m_pendingData->Size() != 0) + { // App close with pending data must wait until all data transmitted + m_closeOnEmpty = true; + NS_LOG_LOGIC("Socket " << this << + " deferring close, state " << m_state); + return 0; + } + + Actions_t action = ProcessEvent (APP_CLOSE); + ProcessAction (action); m_shutdownSend = true; return 0; } @@ -308,18 +320,15 @@ int TcpSocketImpl::Close (void) { - NS_LOG_FUNCTION_NOARGS (); - if (m_pendingData && m_pendingData->Size() != 0) - { // App close with pending data must wait until all data transmitted - m_closeOnEmpty = true; - NS_LOG_LOGIC("Socket " << this << - " deferring close, state " << m_state); - return 0; - } - - Actions_t action = ProcessEvent (APP_CLOSE); - ProcessAction (action); - ShutdownSend (); + if (GetRxAvailable () > 0) + { + ProcessAction (RST_TX); + } + else + { + ShutdownSend(); + } + m_closeCalled = true; return 0; } @@ -1125,6 +1134,11 @@ " seq " << tcpHeader.GetSequenceNumber() << " ack " << tcpHeader.GetAckNumber() << " p.size is " << p->GetSize()); + if(m_closeCalled) //send RST accordingly + { + ProcessAction(RST_TX); + return; + } States_t origState = m_state; if (RxBufferFreeSpace() < p->GetSize()) { //if not enough room, fragment diff -r 80601ddf444a src/internet-stack/tcp-socket-impl.h --- a/src/internet-stack/tcp-socket-impl.h Mon Mar 23 00:06:28 2009 -0400 +++ b/src/internet-stack/tcp-socket-impl.h Mon Mar 30 01:49:51 2009 -0400 @@ -191,6 +191,7 @@ bool m_closeRequestNotified; bool m_closeOnEmpty; bool m_pendingClose; + bool m_closeCalled; //sequence info, sender side