[Libreoffice-commits] .: sd/source

Andrzej J.R. Hunt ajrhunt at kemper.freedesktop.org
Mon Aug 6 23:49:19 PDT 2012


 sd/source/ui/remotecontrol/DiscoveryService.cxx |   30 ++++++++++--------------
 sd/source/ui/remotecontrol/DiscoveryService.hxx |    1 
 2 files changed, 13 insertions(+), 18 deletions(-)

New commits:
commit a554b8e38fd5f4d1b613344304e012c9abc3c870
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Tue Aug 7 08:47:28 2012 +0200

    Refactored DiscoveryService. Added basic error handling.
    
    Change-Id: Ic5bf2d73e55f3d51eebf9421529a9150316f01a4

diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 53cbfd5..30b2131 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 9ca4110..46c629b 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 );
 
     };
 }


More information about the Libreoffice-commits mailing list