Commit 26649fd2 authored by Jonas Stienen's avatar Jonas Stienen

Client-initialized close is accepted by server and client waits for...

Client-initialized close is accepted by server and client waits for acknowledge before closing connection
parent e32b6da6
......@@ -61,7 +61,7 @@ public:
};
CITANetAudioStreamingServer();
virtual ~CITANetAudioStreamingServer() {};
~CITANetAudioStreamingServer();
bool Start( const std::string& sAddress, int iPort );
bool IsClientConnected() const;
......
......@@ -121,11 +121,9 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
// TODO Timer entfernen
if (nIncomingBytes == -1)
return false;
else
int a = 5;
if (timeout != 0)
nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
//if (timeout != 0)
//nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
#if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] " << nIncomingBytes << " bytes incoming" << std::endl;
#endif
......
......@@ -124,8 +124,17 @@ bool CITANetAudioStreamingClient::LoopBody()
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteMessage();
while( true )
{
m_pMessage->ResetMessage();
m_pMessage->ReadMessage( 0 );
int iMsgType = m_pMessage->GetMessageType();
if( iMsgType == CITANetAudioProtocol::NP_SERVER_CLOSE )
break;
}
m_bStopped = true;
m_pMessage->SetConnection( NULL );
while( GetIsConnected() )
......
......@@ -63,6 +63,12 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer( )
m_iClientRingBufferFreeSamples = 0;
}
CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
{
delete m_pNetAudioServer;
delete m_pServerLogger;
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
{
if ( !m_pInputStream )
......@@ -196,11 +202,15 @@ bool CITANetAudioStreamingServer::LoopBody( )
{
case CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES:
{
m_iClientRingBufferFreeSamples = m_pMessage->ReadInt( );
m_iClientRingBufferFreeSamples = m_pMessage->ReadInt( );
break;
}
case CITANetAudioProtocol::NP_CLIENT_CLOSE:
{
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_CLOSE );
m_pMessage->WriteMessage();
StopGently( false );
m_pConnection = NULL;
Stop( );
......@@ -273,8 +283,6 @@ std::string CITANetAudioStreamingServer::GetNetworkAddress( ) const
return m_pNetAudioServer->GetServerAddress( );
}
int CITANetAudioStreamingServer::GetNetworkPort( ) const
{
return m_pNetAudioServer->GetNetworkPort( );
......@@ -282,6 +290,5 @@ int CITANetAudioStreamingServer::GetNetworkPort( ) const
void CITANetAudioStreamingServer::Stop( )
{
delete m_pServerLogger;
m_pNetAudioServer->Stop( );
}
......@@ -100,7 +100,7 @@ int main( int, char** )
vstr::out() << "[ NetAudioTestClient ] Connected." << endl;
// Playback
float fSeconds = 5.0f;
float fSeconds = 10.0f;
vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking
vstr::out() << "[ NetAudioTestClient ] Done." << endl;
......@@ -115,5 +115,7 @@ int main( int, char** )
ITAPA.Close( );
ITAPA.Finalize( );
delete pServer;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment