summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-07 08:47:28 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-07 08:49:06 +0200
commita554b8e38fd5f4d1b613344304e012c9abc3c870 (patch)
treeda276be9b969bcd1cc06e4ca3a45b5823505ede9 /sd
parenta9210660294dd40c18814f59106164d548416032 (diff)
Refactored DiscoveryService. Added basic error handling.
Change-Id: Ic5bf2d73e55f3d51eebf9421529a9150316f01a4
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/remotecontrol/DiscoveryService.cxx30
-rw-r--r--sd/source/ui/remotecontrol/DiscoveryService.hxx1
2 files changed, 13 insertions, 18 deletions
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 53cbfd5d018f..30b2131db290 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -61,16 +61,6 @@ DiscoveryService::~DiscoveryService()
{
}
-
-void DiscoveryService::replyTo( sockaddr_in& rAddr )
-{
- OStringBuffer aBuffer("LOREMOTE_ADVERTISE\n");
- aBuffer.append( OUStringToOString( osl::SocketAddr::getLocalHostname(),
- RTL_TEXTENCODING_UTF8 ) ).append( "\n\n" );
- sendto( mSocket, aBuffer.getStr(), aBuffer.getLength(), 0,
- (sockaddr*) &rAddr, sizeof(rAddr) );
-}
-
void DiscoveryService::execute()
{
fprintf( stderr, "Discovery service is listening\n" );;
@@ -85,14 +75,20 @@ void DiscoveryService::execute()
fprintf( stderr, "DiscoveryService waiting for packet\n" );
recvfrom( mSocket, aBuffer, BUFFER_SIZE, 0, (sockaddr*) &aAddr, &aLen );
fprintf( stderr, "DiscoveryService received a packet.\n" );
- for (int i = 0; i < BUFFER_SIZE; i++ ) {
- if ( aBuffer[i] == '\n' )
+
+ OString aString( aBuffer, strlen( "LOREMOTE_SEARCH" ) );
+ if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 )
+ {
+ OStringBuffer aStringBuffer("LOREMOTE_ADVERTISE\n");
+ aStringBuffer.append( OUStringToOString(
+ osl::SocketAddr::getLocalHostname(), RTL_TEXTENCODING_UTF8 ) )
+ .append( "\n\n" );
+ if ( sendto( mSocket, aStringBuffer.getStr(),
+ aStringBuffer.getLength(), 0, (sockaddr*) &aAddr,
+ sizeof(aAddr) ) <= 0 )
{
- OString aString( aBuffer, i );
- if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 ) {
- replyTo( aAddr );
- }
- break;
+ // Read error or closed socket -- we are done.
+ return;
}
}
}
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx
index 9ca4110daf9d..46c629b34927 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.hxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx
@@ -49,7 +49,6 @@ namespace sd
// osl::DatagramSocket mSocket;
int mSocket;
- void replyTo( sockaddr_in& rAddr );
};
}