summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-06 16:14:01 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-06 16:14:40 +0200
commit3640fdd74406a0528ebc97f36fad47915da3c6d0 (patch)
tree362e4e90b8010f91793eb28c3939372e7e67d7dc
parent0e80e5fe412a19ca04b577d0cf93625b745f0dbc (diff)
Tidied up DiscoveryService::execute().
Change-Id: Ic9e101bf00780dec0f054fccc640cac0e3dacdb9
-rw-r--r--sd/source/ui/remotecontrol/DiscoveryService.cxx36
-rw-r--r--sd/source/ui/remotecontrol/DiscoveryService.hxx1
2 files changed, 14 insertions, 23 deletions
diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx
index 50f7d7703b0b..6c85e2fc9345 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 94a276546f42..9ca4110daf9d 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