diff options
Diffstat (limited to 'sd/source/ui/remotecontrol/BufferedStreamSocket.cxx')
-rw-r--r-- | sd/source/ui/remotecontrol/BufferedStreamSocket.cxx | 61 |
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: */ |