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

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: ...@@ -61,7 +61,7 @@ public:
}; };
CITANetAudioStreamingServer(); CITANetAudioStreamingServer();
virtual ~CITANetAudioStreamingServer() {}; ~CITANetAudioStreamingServer();
bool Start( const std::string& sAddress, int iPort ); bool Start( const std::string& sAddress, int iPort );
bool IsClientConnected() const; bool IsClientConnected() const;
......
...@@ -121,11 +121,9 @@ bool CITANetAudioMessage::ReadMessage( int timeout) ...@@ -121,11 +121,9 @@ bool CITANetAudioMessage::ReadMessage( int timeout)
// TODO Timer entfernen // TODO Timer entfernen
if (nIncomingBytes == -1) if (nIncomingBytes == -1)
return false; return false;
else
int a = 5;
if (timeout != 0) //if (timeout != 0)
nIncomingBytes = m_pConnection->WaitForIncomingData( 0 ); //nIncomingBytes = m_pConnection->WaitForIncomingData( 0 );
#if NET_AUDIO_SHOW_TRAFFIC #if NET_AUDIO_SHOW_TRAFFIC
vstr::out() << "CITANetAudioMessage [ Reading ] " << nIncomingBytes << " bytes incoming" << std::endl; vstr::out() << "CITANetAudioMessage [ Reading ] " << nIncomingBytes << " bytes incoming" << std::endl;
#endif #endif
......
...@@ -124,8 +124,17 @@ bool CITANetAudioStreamingClient::LoopBody() ...@@ -124,8 +124,17 @@ bool CITANetAudioStreamingClient::LoopBody()
m_pMessage->ResetMessage(); m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE ); m_pMessage->SetMessageType( CITANetAudioProtocol::NP_CLIENT_CLOSE );
m_pMessage->WriteMessage(); 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_bStopped = true;
m_pMessage->SetConnection( NULL ); m_pMessage->SetConnection( NULL );
while( GetIsConnected() ) while( GetIsConnected() )
......
...@@ -63,6 +63,12 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer( ) ...@@ -63,6 +63,12 @@ CITANetAudioStreamingServer::CITANetAudioStreamingServer( )
m_iClientRingBufferFreeSamples = 0; m_iClientRingBufferFreeSamples = 0;
} }
CITANetAudioStreamingServer::~CITANetAudioStreamingServer()
{
delete m_pNetAudioServer;
delete m_pServerLogger;
}
bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort ) bool CITANetAudioStreamingServer::Start( const std::string& sAddress, int iPort )
{ {
if ( !m_pInputStream ) if ( !m_pInputStream )
...@@ -196,11 +202,15 @@ bool CITANetAudioStreamingServer::LoopBody( ) ...@@ -196,11 +202,15 @@ bool CITANetAudioStreamingServer::LoopBody( )
{ {
case CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES: case CITANetAudioProtocol::NP_CLIENT_SENDING_RINGBUFFER_FREE_SAMPLES:
{ {
m_iClientRingBufferFreeSamples = m_pMessage->ReadInt( ); m_iClientRingBufferFreeSamples = m_pMessage->ReadInt( );
break; break;
} }
case CITANetAudioProtocol::NP_CLIENT_CLOSE: case CITANetAudioProtocol::NP_CLIENT_CLOSE:
{ {
m_pMessage->ResetMessage();
m_pMessage->SetMessageType( CITANetAudioProtocol::NP_SERVER_CLOSE );
m_pMessage->WriteMessage();
StopGently( false ); StopGently( false );
m_pConnection = NULL; m_pConnection = NULL;
Stop( ); Stop( );
...@@ -273,8 +283,6 @@ std::string CITANetAudioStreamingServer::GetNetworkAddress( ) const ...@@ -273,8 +283,6 @@ std::string CITANetAudioStreamingServer::GetNetworkAddress( ) const
return m_pNetAudioServer->GetServerAddress( ); return m_pNetAudioServer->GetServerAddress( );
} }
int CITANetAudioStreamingServer::GetNetworkPort( ) const int CITANetAudioStreamingServer::GetNetworkPort( ) const
{ {
return m_pNetAudioServer->GetNetworkPort( ); return m_pNetAudioServer->GetNetworkPort( );
...@@ -282,6 +290,5 @@ int CITANetAudioStreamingServer::GetNetworkPort( ) const ...@@ -282,6 +290,5 @@ int CITANetAudioStreamingServer::GetNetworkPort( ) const
void CITANetAudioStreamingServer::Stop( ) void CITANetAudioStreamingServer::Stop( )
{ {
delete m_pServerLogger;
m_pNetAudioServer->Stop( ); m_pNetAudioServer->Stop( );
} }
...@@ -100,7 +100,7 @@ int main( int, char** ) ...@@ -100,7 +100,7 @@ int main( int, char** )
vstr::out() << "[ NetAudioTestClient ] Connected." << endl; vstr::out() << "[ NetAudioTestClient ] Connected." << endl;
// Playback // Playback
float fSeconds = 5.0f; float fSeconds = 10.0f;
vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl; vstr::out() << "[ NetAudioTestClient ] Playback started, waiting " << fSeconds << " seconds" << endl;
ITAPA.Sleep( fSeconds ); // blocking ITAPA.Sleep( fSeconds ); // blocking
vstr::out() << "[ NetAudioTestClient ] Done." << endl; vstr::out() << "[ NetAudioTestClient ] Done." << endl;
...@@ -115,5 +115,7 @@ int main( int, char** ) ...@@ -115,5 +115,7 @@ int main( int, char** )
ITAPA.Close( ); ITAPA.Close( );
ITAPA.Finalize( ); ITAPA.Finalize( );
delete pServer;
return 0; 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