22#include <com/sun/star/io/IOException.hpp>
38 std::unique_lock guard(pCon->
_mutex);
46 for(
auto& listener : listeners)
51 static void callStarted(
const Reference<XStreamListener>& xStreamListener)
53 xStreamListener->started();
61 explicit callError(
const Any &
any);
63 void operator () (
const Reference<XStreamListener>& xStreamListener);
68 callError::callError(
const Any & aAny)
73 void callError::operator () (
const Reference<XStreamListener>& xStreamListener)
75 xStreamListener->error(
any);
78 static void callClosed(
const Reference<XStreamListener>& xStreamListener)
80 xStreamListener->closed();
84 SocketConnection::SocketConnection( OUString sConnectionDescription ) :
94 sal::static_int_cast< sal_Int64 >(
95 reinterpret_cast< sal_IntPtr
>(&
m_socket)) );
98 SocketConnection::~SocketConnection()
102 void SocketConnection::completeConnectionString()
109 ",peerPort=" + OUString::number( nPort ) +
110 ",peerHost=" +
m_socket.getPeerHost() +
111 ",localPort=" + OUString::number( nPort ) +
112 ",localHost=" +
m_socket.getLocalHost( );
115 sal_Int32 SocketConnection::read( Sequence < sal_Int8 > & aReadBytes , sal_Int32 nBytesToRead )
121 if( aReadBytes.getLength() != nBytesToRead )
123 aReadBytes.realloc( nBytesToRead );
125 sal_Int32
i =
m_socket.read( aReadBytes.getArray() , aReadBytes.getLength() );
127 if(i != nBytesToRead &&
m_socket.getError() != osl_Socket_E_None)
129 OUString message =
"ctr_socket.cxx:SocketConnection::read: error - " +
132 IOException ioException(message,
static_cast<XConnection *
>(
this));
146 IOException ioException(
"ctr_socket.cxx:SocketConnection::read: error - connection already closed",
static_cast<XConnection *
>(
this));
157 void SocketConnection::write(
const Sequence < sal_Int8 > &seq )
161 if(
m_socket.write( seq.getConstArray() , seq.getLength() ) != seq.getLength() )
163 OUString message =
"ctr_socket.cxx:SocketConnection::write: error - " +
166 IOException ioException(message,
static_cast<XConnection *
>(
this));
178 IOException ioException(
"ctr_socket.cxx:SocketConnection::write: error - connection already closed",
static_cast<XConnection *
>(
this));
189 void SocketConnection::flush( )
194 void SocketConnection::close()
197 if( 1 == osl_atomic_increment( (&
m_nStatus) ) )
204 OUString SocketConnection::getDescription()
211 void SAL_CALL SocketConnection::addStreamListener(
const Reference<XStreamListener> & aListener)
213 std::unique_lock guard(
_mutex);
218 void SAL_CALL SocketConnection::removeStreamListener(
const Reference<XStreamListener> & aListener)
220 std::unique_lock guard(
_mutex);
oslInterlockedCount m_nStatus
::osl::StreamSocket m_socket
XStreamListener_hash_set _listeners
XStreamListener_hash_set _listeners
static void callClosed(const Reference< XStreamListener > &xStreamListener)
static void notifyListeners(SocketConnection *pCon, bool *notified, T t)
static void callStarted(const Reference< XStreamListener > &xStreamListener)
std::unordered_set< css::uno::Reference< css::io::XStreamListener > > XStreamListener_hash_set