[Libreoffice-commits] .: sd/source
Andrzej J.R. Hunt
ajrhunt at kemper.freedesktop.org
Mon Aug 6 07:16:02 PDT 2012
sd/source/ui/remotecontrol/DiscoveryService.cxx | 36 ++++++++----------------
sd/source/ui/remotecontrol/DiscoveryService.hxx | 1
2 files changed, 14 insertions(+), 23 deletions(-)
New commits:
commit 3640fdd74406a0528ebc97f36fad47915da3c6d0
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Aug 6 16:14:01 2012 +0200
Tidied up DiscoveryService::execute().
Change-Id: Ic9e101bf00780dec0f054fccc640cac0e3dacdb9
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 50f7d77..6c85e2f 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.cxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx
@@ -12,6 +12,7 @@
#include <comphelper/processfactory.hxx>
#include <rtl/strbuf.hxx>
+#include <string.h>
#include "DiscoveryService.hxx"
@@ -73,37 +74,26 @@ void DiscoveryService::replyTo( sockaddr_in& rAddr )
void DiscoveryService::execute()
{
fprintf( stderr, "Discovery service is listening\n" );;
- sal_uInt64 aRet(0);
- sal_uInt64 aRead(0);
- vector<char> aBuffer;
+
+ char aBuffer[BUFFER_SIZE];
while ( true )
{
- aBuffer.resize( aRead + 100 );
-
+ memset( aBuffer, 0, sizeof(char) * BUFFER_SIZE );
sockaddr_in aAddr;
socklen_t aLen = sizeof( aAddr );
fprintf( stderr, "DiscoveryService waiting for packet\n" );
-// aRet = mSocket.recvFrom( &aBuffer[aRead], 100 );
- recvfrom( mSocket, &aBuffer[aRead], 100, 0, (sockaddr*) &aAddr, &aLen );
+ recvfrom( mSocket, &aBuffer, BUFFER_SIZE, 0, (sockaddr*) &aAddr, &aLen );
fprintf( stderr, "DiscoveryService received a packet.\n" );
-// if ( aRet == 0 )
-// {
-// fprintf( stderr, "Socket returned 0\n" );
-// // break; // I.e. transmission finished.
-// }
- aRead += aRet;
- vector<char>::iterator aIt;
- while ( (aIt = find( aBuffer.begin(), aBuffer.end(), '\n' ))
- != aBuffer.end() )
- {
- sal_uInt64 aLocation = aIt - aBuffer.begin();
- OString aString( &(*aBuffer.begin()), aLocation );
- if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 ) {
- replyTo( aAddr );
+ for (int i = 0; i < BUFFER_SIZE; i++ ) {
+ if ( aBuffer[i] == '\n' )
+ {
+ OString aString( aBuffer, i );
+ if ( aString.compareTo( "LOREMOTE_SEARCH" ) == 0 ) {
+ replyTo( aAddr );
+ }
+ break;
}
- aBuffer.erase( aBuffer.begin(), aIt + 1 ); // Also delete the newline
- aRead -= (aLocation + 1);
}
}
}
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx
index 94a2765..9ca4110 100644
--- a/sd/source/ui/remotecontrol/DiscoveryService.hxx
+++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx
@@ -24,6 +24,7 @@ namespace css = ::com::sun::star;
* The port for use for the main communication between LibO and remote control app.
*/
#define PORT_DISCOVERY 1598
+#define BUFFER_SIZE 200
#define CHARSET RTL_TEXTENCODING_UTF8
More information about the Libreoffice-commits
mailing list