summaryrefslogtreecommitdiff
path: root/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-10 18:42:49 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-10 18:43:44 +0200
commitf4ab85cb44664a4c46c52d5a34eee300947e6069 (patch)
tree642112abdc63e9ba0765fd702c492f3241cea34f /sd/source/ui/remotecontrol/BufferedStreamSocket.cxx
parentf6a24ace5ad12e79f0cc90709a290a30e3758781 (diff)
Pairing implemented server side.
Change-Id: I542e563df68d38691f7c95cebf66aeb32071bd66
Diffstat (limited to 'sd/source/ui/remotecontrol/BufferedStreamSocket.cxx')
-rw-r--r--sd/source/ui/remotecontrol/BufferedStreamSocket.cxx61
1 files changed, 61 insertions, 0 deletions
diff --git a/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx b/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx
new file mode 100644
index 000000000000..8232bd085a06
--- /dev/null
+++ b/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <BufferedStreamSocket.hxx>
+
+#include <algorithm>
+
+using namespace sd;
+using namespace std;
+using namespace osl;
+
+BufferedStreamSocket::BufferedStreamSocket( const osl::StreamSocket &aSocket ):
+ StreamSocket( aSocket ),
+ aRet( 0 ),
+ aRead( 0 ),
+ aBuffer()
+{
+}
+
+sal_Int32 BufferedStreamSocket::readLine( OString& aLine )
+{
+ while ( true )
+ {
+ aBuffer.resize( aRead + 100 );
+ aRet = recv( &aBuffer[aRead], 100 );
+ if ( aRet == 0 )
+ {
+ return aRet;
+ }
+ // Prevent buffer from growing massively large.
+ if ( aRead > MAX_LINE_LENGTH )
+ {
+ aBuffer.erase( aBuffer.begin(), aBuffer.end() );
+ return 0;
+ }
+ aRead += aRet;
+ vector<char>::iterator aIt;
+ while ( (aIt = find( aBuffer.begin(), aBuffer.end(), '\n' ))
+ != aBuffer.end() )
+ {
+ sal_uInt64 aLocation = aIt - aBuffer.begin();
+
+ aLine = OString( &(*aBuffer.begin()), aLocation );
+
+ aBuffer.erase( aBuffer.begin(), aIt + 1 ); // Also delete the empty line
+ aRead -= (aLocation + 1);
+
+ return aLine.getLength();
+ }
+ }
+
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */