1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <BufferedStreamSocket.hxx>
15 // LO vs WinAPI conflict
21 #include <sys/socket.h>
28 BufferedStreamSocket::BufferedStreamSocket( const osl::StreamSocket
&aSocket
):
29 StreamSocket( aSocket
),
38 BufferedStreamSocket::BufferedStreamSocket( int aSocket
):
48 void BufferedStreamSocket::getPeerAddr(osl::SocketAddr
& rAddr
)
50 assert ( !usingCSocket
);
51 StreamSocket::getPeerAddr( rAddr
);
54 sal_Int32
BufferedStreamSocket::write( const void* pBuffer
, sal_uInt32 n
)
57 return StreamSocket::write( pBuffer
, n
);
62 static_cast<char const *>(pBuffer
),
69 void BufferedStreamSocket::close()
71 if( usingCSocket
&& mSocket
!= -1 )
74 ::closesocket( mSocket
);
81 ::osl::StreamSocket::close();
84 sal_Int32
BufferedStreamSocket::readLine( OString
& aLine
)
88 // Process buffer first incase data already present.
89 vector
<char>::iterator aIt
;
90 if ( (aIt
= find( aBuffer
.begin(), aBuffer
.end(), '\n' ))
93 sal_uInt64 aLocation
= aIt
- aBuffer
.begin();
95 aLine
= OString( &(*aBuffer
.begin()), aLocation
);
97 aBuffer
.erase( aBuffer
.begin(), aIt
+ 1 ); // Also delete the empty line
98 aRead
-= (aLocation
+ 1);
100 SAL_INFO( "sdremote.bluetooth", "recv line '" << aLine
<< "'" );
102 return aLine
.getLength() + 1;
105 // Then try and receive if nothing present
106 aBuffer
.resize( aRead
+ 100 );
108 aRet
= StreamSocket::recv( &aBuffer
[aRead
], 100 );
110 aRet
= ::recv( mSocket
, &aBuffer
[aRead
], 100, 0 );
112 SAL_INFO( "sdremote.bluetooth", "recv " << aRet
<< " aBuffer len " << aBuffer
.size() );
117 // Prevent buffer from growing massively large.
118 if ( aRead
> MAX_LINE_LENGTH
)
120 aBuffer
.erase( aBuffer
.begin(), aBuffer
.end() );
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */