Add a socket callback that can unblock a blocked close

This commit is contained in:
Raj Bhattacharjea
2008-05-12 13:13:50 -04:00
parent 53841f6170
commit 5d5fd895f1
4 changed files with 40 additions and 4 deletions

View File

@@ -165,7 +165,7 @@ int main (int argc, char *argv[])
//
///////////////////////////////////////////////////////////////////////////
int nBytes = 2000000;
int nBytes = 2000;
uint16_t servPort = 50000;
// Create a packet sink to receive these packets

View File

@@ -282,13 +282,25 @@ TcpSocket::ShutdownSend (void)
{
NS_LOG_FUNCTION_NOARGS ();
m_shutdownSend = true;
if (m_state == CLOSED)
{
return -1;
}
if (m_pendingData && m_pendingData->Size() != 0)
{ // App shutdown with pending data must wait until all data transmitted
m_closeOnEmpty = true;
NS_LOG_LOGIC("TcpSocket "<<this<< " deferring close, state " << m_state);
return 0;
}
Actions_t action = ProcessEvent (APP_CLOSE);
ProcessAction (action);
return 0;
}
int
TcpSocket::ShutdownRecv (void)
{
NS_LOG_FUNCTION_NOARGS ();
m_shutdownRecv = false;
m_shutdownRecv = true;
return 0;
}
@@ -303,7 +315,7 @@ TcpSocket::Close (void)
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 <<
NS_LOG_LOGIC("TcpSocket " << this <<
" deferring close, state " << m_state);
return 0;
}
@@ -955,8 +967,12 @@ bool TcpSocket::SendPendingData (bool withAck)
m_endPoint->GetLocalAddress (),
m_remoteAddress);
m_rtt->SentSeq(m_nextTxSequence, sz); // notify the RTT
// Notify the application
// Notify the application data was sent
Simulator::ScheduleNow(&TcpSocket::NotifyDataSent, this, p->GetSize ());
if (m_state == FIN_WAIT_1)
{
Simulator::ScheduleNow(&TcpSocket::NotifyCloseUnblocks, this);
}
nPacketsSent++; // Count sent this loop
m_nextTxSequence += sz; // Advance next tx sequence
// Note the high water mark

View File

@@ -33,6 +33,13 @@ Socket::~Socket ()
NS_LOG_FUNCTION_NOARGS ();
}
void
Socket::SetCloseUnblocksCallback (Callback<void,Ptr<Socket> > closeUnblocks)
{
NS_LOG_FUNCTION_NOARGS ();
m_closeUnblocks = closeUnblocks;
}
void
Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
{
@@ -91,6 +98,15 @@ int Socket::Listen (uint32_t queueLimit)
return 0; //XXX the base class version does nothing
}
void
Socket::NotifyCloseUnblocks (void)
{
NS_LOG_FUNCTION_NOARGS ();
if (!m_closeUnblocks.IsNull ())
{
m_closeUnblocks (this);
}
}
int Socket::Send (const uint8_t* buf, uint32_t size)
{

View File

@@ -78,6 +78,8 @@ public:
*/
virtual Ptr<Node> GetNode (void) const = 0;
void SetCloseUnblocksCallback (Callback<void, Ptr<Socket> > closeUnblocks);
/**
* \param closeCompleted Callback invoked when the close operation is
* completed.
@@ -316,6 +318,7 @@ public:
virtual uint32_t GetRcvBuf (void) = 0;
protected:
void NotifyCloseUnblocks (void);
void NotifyCloseCompleted (void);
void NotifyConnectionSucceeded (void);
void NotifyConnectionFailed (void);
@@ -327,6 +330,7 @@ protected:
void NotifySend (uint32_t spaceAvailable);
void NotifyDataRecv (void);
Callback<void, Ptr<Socket> > m_closeUnblocks;
Callback<void,Ptr<Socket> > m_closeCompleted;
Callback<void, Ptr<Socket> > m_connectionSucceeded;
Callback<void, Ptr<Socket> > m_connectionFailed;