LibreOffice
LibreOffice 6.0 SDK C/C++ API Reference
socket.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_OSL_SOCKET_HXX
20 #define INCLUDED_OSL_SOCKET_HXX
21 
22 #include <osl/socket_decl.hxx>
23 
24 namespace osl
25 {
26 
29  {}
30 
31 
32  inline SocketAddr::SocketAddr(const SocketAddr& Addr)
34  {
35  }
36 
37 #if defined LIBO_INTERNAL_ONLY
38  SocketAddr::SocketAddr(SocketAddr && other): m_handle(other.m_handle) {
39  other.m_handle = nullptr;
40  }
41 #endif
42 
44  : m_handle( osl_copySocketAddr( Addr ) )
45  {
46  }
47 
48 
50  : m_handle( Addr )
51  {
52  }
53 
54 
55  inline SocketAddr::SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort)
56  : m_handle( osl_createInetSocketAddr( strAddrOrHostName.pData, nPort ) )
57  {
58  if(! m_handle )
59  {
60  m_handle = osl_resolveHostname(strAddrOrHostName.pData);
61 
62  // host found?
63  if(m_handle)
64  {
66  }
67  else
68  {
70  m_handle = NULL;
71  }
72  }
73  }
74 
75 
77  {
78  if( m_handle )
80  }
81 
82 
83  inline ::rtl::OUString SocketAddr::getHostname( oslSocketResult *pResult ) const
84  {
85  ::rtl::OUString hostname;
86  oslSocketResult result = osl_getHostnameOfSocketAddr( m_handle, &(hostname.pData) );
87  if( pResult )
88  *pResult = result;
89  return hostname;
90  }
91 
92 
93  inline sal_Int32 SAL_CALL SocketAddr::getPort() const
94  {
96  }
97 
98 
99  inline bool SAL_CALL SocketAddr::setPort( sal_Int32 nPort )
100  {
101  return osl_setInetPortOfSocketAddr(m_handle, nPort );
102  }
103 
104  inline bool SAL_CALL SocketAddr::setHostname( const ::rtl::OUString &sDottedIpOrHostname )
105  {
106  *this = SocketAddr( sDottedIpOrHostname , getPort() );
107  return is();
108  }
109 
110 
111  inline bool SAL_CALL SocketAddr::setAddr( const ::rtl::ByteSequence & address )
112  {
113  return osl_setAddrOfSocketAddr( m_handle, address.getHandle() )
114  == osl_Socket_Ok;
115  }
116 
117  inline ::rtl::ByteSequence SAL_CALL SocketAddr::getAddr( oslSocketResult *pResult ) const
118  {
119  ::rtl::ByteSequence sequence;
120  oslSocketResult result = osl_getAddrOfSocketAddr( m_handle, reinterpret_cast<sal_Sequence **>(&sequence) );
121  if( pResult )
122  *pResult = result;
123  return sequence;
124  }
125 
126 
128  {
129  oslSocketAddr pNewAddr = osl_copySocketAddr( Addr );
130  if( m_handle )
132  m_handle = pNewAddr;
133  return *this;
134  }
135 
136 
137  inline SocketAddr & SAL_CALL SocketAddr::operator= (const SocketAddr& Addr)
138  {
139  *this = (Addr.getHandle());
140  return *this;
141  }
142 
143 #if defined LIBO_INTERNAL_ONLY
145  if (m_handle != nullptr) {
147  }
148  m_handle = other.m_handle;
149  other.m_handle = nullptr;
150  return *this;
151  }
152 #endif
153 
155  {
156  if( m_handle )
158  m_handle = Addr;
159  return *this;
160  }
161 
162 
163  inline bool SAL_CALL SocketAddr::operator== (oslSocketAddr Addr) const
164  {
165  return osl_isEqualSocketAddr( m_handle, Addr );
166  }
167 
169  {
170  return m_handle;
171  }
172 
173 
174  inline bool SocketAddr::is() const
175  {
176  return m_handle != NULL;
177  }
178 
179  inline ::rtl::OUString SAL_CALL SocketAddr::getLocalHostname( oslSocketResult *pResult )
180  {
181  ::rtl::OUString hostname;
182  oslSocketResult result = osl_getLocalHostname( &(hostname.pData) );
183  if(pResult )
184  *pResult = result;
185  return hostname;
186  }
187 
188  inline void SAL_CALL SocketAddr::resolveHostname(
189  const ::rtl::OUString & strHostName, SocketAddr &Addr)
190  {
191  Addr = SocketAddr( osl_resolveHostname( strHostName.pData ) , SAL_NO_COPY );
192  }
193 
194  inline sal_Int32 SAL_CALL SocketAddr::getServicePort(
195  const ::rtl::OUString& strServiceName,
196  const ::rtl::OUString & strProtocolName )
197  {
198  return osl_getServicePort( strServiceName.pData, strProtocolName.pData );
199  }
200 
201 
203  oslAddrFamily Family,
204  oslProtocol Protocol)
205  : m_handle( osl_createSocket(Family, Type, Protocol) )
206  {}
207 
208 
209  inline Socket::Socket( oslSocket socketHandle, __sal_NoAcquire )
210  : m_handle( socketHandle )
211  {}
212 
213 
214  inline Socket::Socket( oslSocket socketHandle )
215  : m_handle( socketHandle )
216  {
218  }
219 
220 
221  inline Socket::Socket( const Socket & socket )
222  : m_handle( socket.getHandle() )
223  {
225  }
226 
227 
229  {
231  }
232 
233 
234  inline Socket& Socket::operator= ( oslSocket socketHandle)
235  {
236  osl_acquireSocket( socketHandle );
238  m_handle = socketHandle;
239  return *this;
240  }
241 
242 
243  inline Socket& Socket::operator= (const Socket& sock)
244  {
245  return (*this) = sock.getHandle();
246  }
247 
248 
249  inline bool Socket::operator==( const Socket& rSocket ) const
250  {
251  return m_handle == rSocket.getHandle();
252  }
253 
254 
255  inline bool Socket::operator==( const oslSocket socketHandle ) const
256  {
257  return m_handle == socketHandle;
258  }
259 
260 
261  inline void Socket::shutdown( oslSocketDirection Direction )
262  {
263  osl_shutdownSocket( m_handle , Direction );
264  }
265 
266 
267  inline void Socket::close()
268  {
270  }
271 
272 
273  inline void Socket::getLocalAddr( SocketAddr & addr) const
274  {
276  }
277 
278 
279  inline sal_Int32 Socket::getLocalPort() const
280  {
281  SocketAddr addr( NULL );
282  getLocalAddr( addr );
283  return addr.getPort();
284  }
285 
286 
287  inline ::rtl::OUString Socket::getLocalHost() const
288  {
289  SocketAddr addr( NULL );
290  getLocalAddr( addr );
291  return addr.getHostname();
292  }
293 
294 
295  inline void Socket::getPeerAddr( SocketAddr &addr ) const
296  {
298  }
299 
300 
301  inline sal_Int32 Socket::getPeerPort() const
302  {
303  SocketAddr addr( NULL );
304  getPeerAddr( addr );
305  return addr.getPort();
306  }
307 
308 
309  inline ::rtl::OUString Socket::getPeerHost() const
310  {
311  SocketAddr addr( NULL );
312  getPeerAddr( addr );
313  return addr.getHostname();
314  }
315 
316 
317  inline bool Socket::bind(const SocketAddr& LocalInterface)
318  {
319  return osl_bindAddrToSocket( m_handle , LocalInterface.getHandle() );
320  }
321 
322 
323  inline bool Socket::isRecvReady(const TimeValue *pTimeout ) const
324  {
325  return osl_isReceiveReady( m_handle , pTimeout );
326  }
327 
328 
329  inline bool Socket::isSendReady(const TimeValue *pTimeout ) const
330  {
331  return osl_isSendReady( m_handle, pTimeout );
332  }
333 
334 
335  inline bool Socket::isExceptionPending(const TimeValue *pTimeout ) const
336  {
337  return osl_isExceptionPending( m_handle, pTimeout );
338  }
339 
340 
342  {
343  return osl_getSocketType( m_handle );
344  }
345 
346 
347  inline sal_Int32 Socket::getOption(
348  oslSocketOption Option,
349  void* pBuffer,
350  sal_uInt32 BufferLen,
351  oslSocketOptionLevel Level) const
352  {
353  return osl_getSocketOption( m_handle, Level, Option, pBuffer , BufferLen );
354  }
355 
356 
357  inline bool Socket::setOption( oslSocketOption Option,
358  void* pBuffer,
359  sal_uInt32 BufferLen,
360  oslSocketOptionLevel Level ) const
361  {
362  return osl_setSocketOption( m_handle, Level, Option , pBuffer, BufferLen );
363  }
364 
365 
366  inline bool Socket::setOption( oslSocketOption option, sal_Int32 nValue )
367  {
368  return setOption( option, &nValue, sizeof( nValue ) );
369  }
370 
371 
372  inline sal_Int32 Socket::getOption( oslSocketOption option ) const
373  {
374  sal_Int32 n;
375  getOption( option, &n, sizeof( n ) );
376  return n;
377  }
378 
379 
380  inline bool Socket::enableNonBlockingMode( bool bNonBlockingMode)
381  {
382  return osl_enableNonBlockingMode( m_handle , bNonBlockingMode );
383  }
384 
385 
386  inline bool Socket::isNonBlockingMode() const
387  {
389  }
390 
391 
392  inline void SAL_CALL Socket::clearError() const
393  {
394  sal_Int32 err = 0;
395  getOption(osl_Socket_OptionError, &err, sizeof(err));
396  }
397 
398 
400  {
402  }
403 
404 
405  inline ::rtl::OUString Socket::getErrorAsString( ) const
406  {
407  ::rtl::OUString error;
408  osl_getLastSocketErrorDescription( m_handle, &(error.pData) );
409  return error;
410  }
411 
412 
414  {
415  return m_handle;
416  }
417 
418 
420  oslProtocol Protocol,
421  oslSocketType Type )
422  : Socket( Type, Family, Protocol )
423  {}
424 
425 
426  inline StreamSocket::StreamSocket( oslSocket socketHandle, __sal_NoAcquire noacquire )
427  : Socket( socketHandle, noacquire )
428  {}
429 
430 
431  inline StreamSocket::StreamSocket( oslSocket socketHandle )
432  : Socket( socketHandle )
433  {}
434 
435 
436  inline StreamSocket::StreamSocket( const StreamSocket & socket )
437  : Socket( socket )
438  {}
439 
440 
441  inline sal_Int32 StreamSocket::read(void* pBuffer, sal_uInt32 n)
442  {
443  return osl_readSocket( m_handle, pBuffer, n );
444  }
445 
446 
447  inline sal_Int32 StreamSocket::write(const void* pBuffer, sal_uInt32 n)
448  {
449  return osl_writeSocket( m_handle, pBuffer, n );
450  }
451 
452 
453  inline sal_Int32 StreamSocket::recv(void* pBuffer,
454  sal_uInt32 BytesToRead,
455  oslSocketMsgFlag Flag)
456  {
457  return osl_receiveSocket( m_handle, pBuffer,BytesToRead, Flag );
458  }
459 
460 
461  inline sal_Int32 StreamSocket::send(const void* pBuffer,
462  sal_uInt32 BytesToSend,
463  oslSocketMsgFlag Flag)
464  {
465  return osl_sendSocket( m_handle, pBuffer, BytesToSend, Flag );
466  }
467 
468 
470  oslProtocol Protocol,
471  oslSocketType Type)
472  : StreamSocket( Family, Protocol ,Type )
473  {}
474 
475 
477  const TimeValue* pTimeout )
478  {
479  return osl_connectSocketTo( m_handle , TargetHost.getHandle(), pTimeout );
480  }
481 
482 
484  oslProtocol Protocol ,
485  oslSocketType Type )
486  : Socket( Type, Family, Protocol )
487  {}
488 
489 
490  inline bool AcceptorSocket::listen(sal_Int32 MaxPendingConnections)
491  {
492  return osl_listenOnSocket( m_handle, MaxPendingConnections );
493  }
494 
495 
497  {
500  if( o )
501  {
502  Connection = StreamSocket( o , SAL_NO_ACQUIRE );
503  }
504  else
505  {
506  Connection = StreamSocket();
507  status = osl_Socket_Error;
508  }
509  return status;
510  }
511 
512 
514  StreamSocket& Connection, SocketAddr & PeerAddr)
515  {
516  // TODO change in/OUT parameter
518  m_handle, reinterpret_cast<oslSocketAddr *>(&PeerAddr));
520  if( o )
521  {
522  Connection = StreamSocket( o , SAL_NO_ACQUIRE );
523  }
524  else
525  {
526  Connection = StreamSocket();
527  status = osl_Socket_Error;
528  }
529  return status;
530  }
531 
532 
534  oslProtocol Protocol,
535  oslSocketType Type)
536  : Socket( Type, Family, Protocol )
537  {}
538 
539 
540  inline sal_Int32 DatagramSocket::recvFrom(void* pBuffer,
541  sal_uInt32 BufferSize,
542  SocketAddr* pSenderAddr,
543  oslSocketMsgFlag Flag )
544  {
545  sal_Int32 nByteRead;
546  if( pSenderAddr )
547  {
548  // TODO : correct the out-parameter pSenderAddr outparameter
549  nByteRead = osl_receiveFromSocket( m_handle, pSenderAddr->getHandle() , pBuffer,
550  BufferSize, Flag);
551  }
552  else
553  {
554  nByteRead = osl_receiveFromSocket( m_handle, NULL , pBuffer , BufferSize , Flag );
555  }
556  return nByteRead;
557  }
558 
559 
560  inline sal_Int32 DatagramSocket::sendTo( const SocketAddr& ReceiverAddr,
561  const void* pBuffer,
562  sal_uInt32 BufferSize,
563  oslSocketMsgFlag Flag )
564  {
565  return osl_sendToSocket( m_handle, ReceiverAddr.getHandle(), pBuffer, BufferSize, Flag );
566  }
567 }
568 #endif
569 
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:121
ConnectorSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Creates a socket that can connect to a (remote) host.
Definition: socket.hxx:469
SAL_DLLPUBLIC oslSocketResult osl_setAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence *pByteSeq)
Sets the addr field in the struct sockaddr with pByteSeq.
bool listen(sal_Int32 MaxPendingConnections=-1)
Prepare a socket for the accept-call.
Definition: socket.hxx:490
bool isNonBlockingMode() const
Query blocking mode of the socket.
Definition: socket.hxx:386
oslSocket getHandle() const
Returns the underlying handle unacquired (The caller must acquire it to keep it). ...
Definition: socket.hxx:413
StreamSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Creates a socket.
Definition: socket.hxx:419
static inline::rtl::OUString getLocalHostname(oslSocketResult *pResult=NULL)
Get the hostname for the local interface.
Definition: socket.hxx:179
bool operator==(oslSocketAddr Addr) const
Returns true if the underlying handle is identical to the Addr handle.
Definition: socket.hxx:163
SAL_DLLPUBLIC sal_Int32 osl_receiveFromSocket(oslSocket Socket, oslSocketAddr SenderAddr, void *pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag)
Tries to receives BufferSize data from the (usually unconnected) (datagram-)socket, if no error occurs.
SAL_DLLPUBLIC oslSocketResult osl_getHostnameOfSocketAddr(oslSocketAddr Addr, rtl_uString **strHostname)
Returns the hostname represented by Addr.
struct oslSocketImpl * oslSocket
Definition: socket.h:211
SAL_DLLPUBLIC oslSocketAddr osl_getLocalAddrOfSocket(oslSocket Socket)
Retrieves the Address of the local end of the socket.
SocketAddr & assign(oslSocketAddr Addr, __osl_socket_NoCopy nocopy)
Assigns the socket addr without copyconstructing it.
Definition: socket.hxx:154
bool setAddr(const ::rtl::ByteSequence &address)
Sets the address of the underlying socket address struct in network byte order.
Definition: socket.hxx:111
oslSocketResult acceptConnection(StreamSocket &Connection)
Accepts incoming connections on the socket.
Definition: socket.hxx:496
SAL_DLLPUBLIC sal_Int32 osl_sendSocket(oslSocket Socket, const void *pBuffer, sal_uInt32 BytesToSend, oslSocketMsgFlag Flag)
Tries to send BytesToSend data from the connected socket, if no error occurs.
SocketAddr()
Creates socket address of unknown type.
Definition: socket.hxx:27
oslSocketOption
Represents socket-options.
Definition: socket.h:85
SAL_DLLPUBLIC oslSocketResult osl_getAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence **ppByteSeq)
Returns the addr field in the struct sockaddr.
inline::rtl::OUString getHostname(oslSocketResult *pResult=NULL) const
Converts the address to a (human readable) domain-name.
Definition: socket.hxx:83
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:144
~SocketAddr()
destroys underlying oslSocketAddress
Definition: socket.hxx:76
static void resolveHostname(const ::rtl::OUString &strHostName, SocketAddr &Addr)
Tries to find an address for a host.
Definition: socket.hxx:188
sal_Int32 sendTo(const SocketAddr &ReceiverAddr, const void *pBuffer, sal_uInt32 BufferSize, oslSocketMsgFlag Flag=osl_Socket_MsgNormal)
Tries to send one datagram with BytesToSend size to the given ReceiverAddr.
Definition: socket.hxx:560
bool setHostname(const ::rtl::OUString &sDottedIpOrHostname)
Sets the IP address or hostname of the SocketAddress.
Definition: socket.hxx:104
sal_Int32 send(const void *pBuffer, sal_uInt32 BytesToSend, oslSocketMsgFlag=osl_Socket_MsgNormal)
Tries to send BytesToSend data to the connected socket.
Definition: socket.hxx:461
~Socket()
Destructor.
Definition: socket.hxx:228
SAL_DLLPUBLIC oslSocketError osl_getLastSocketError(oslSocket Socket)
Returns a constant describing the last error for the socket system.
SAL_DLLPUBLIC oslSocketAddr osl_getPeerAddrOfSocket(oslSocket Socket)
Retrieves the Address of the remote end of the socket.
oslSocketAddr getHandle() const
Returns the underlying SocketAddr handle without copyconstructing it.
Definition: socket.hxx:168
void shutdown(oslSocketDirection Direction=osl_Socket_DirReadWrite)
Closes a definite or both directions of the bidirectional stream.
Definition: socket.hxx:261
DatagramSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeDgram)
Creates a datagram socket.
Definition: socket.hxx:533
sal_Int32 recv(void *pBuffer, sal_uInt32 BytesToRead, oslSocketMsgFlag flags=osl_Socket_MsgNormal)
Tries to receive BytesToRead data from the connected socket,.
Definition: socket.hxx:453
bool setOption(oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
Sets the sockets attributes.
Definition: socket.hxx:357
sal_Int32 getPeerPort() const
Get the remote port of the socket.
Definition: socket.hxx:301
oslSocketType
Represents the type of a socket.
Definition: socket.h:67
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:154
inline::rtl::OUString getPeerHost() const
Get the hostname for the remote interface.
Definition: socket.hxx:309
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:131
void getPeerAddr(SocketAddr &Addr) const
Retrieves the address of the remote host of this socket.
Definition: socket.hxx:295
SAL_DLLPUBLIC void osl_closeSocket(oslSocket Socket)
Closes the socket terminating any ongoing dataflow.
sal_Int32 recvFrom(void *pBuffer, sal_uInt32 BufferSize, SocketAddr *pSenderAddr=NULL, oslSocketMsgFlag Flag=osl_Socket_MsgNormal)
Tries to receives BufferSize data from the socket, if no error occurs.
Definition: socket.hxx:540
SAL_DLLPUBLIC sal_Int32 osl_writeSocket(oslSocket Socket, const void *pBuffer, sal_Int32 nSize)
Writes n bytes from pBuffer to the stream.
void clearError() const
clears the error status
Definition: socket.hxx:392
SAL_DLLPUBLIC sal_Bool osl_bindAddrToSocket(oslSocket Socket, oslSocketAddr Addr)
Binds the given address to the socket.
SAL_DLLPUBLIC sal_Bool osl_listenOnSocket(oslSocket Socket, sal_Int32 MaxPendingConnections)
Prepares the socket to act as an acceptor of incoming connections.
Definition: socket.h:110
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:40
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:193
__sal_NoAcquire
Definition: types.h:376
sal_Int32 read(void *pBuffer, sal_uInt32 n)
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: socket.hxx:441
SAL_DLLPUBLIC void osl_releaseSocket(oslSocket Socket)
decreases the refcount of the socket handle by one.
inline::rtl::OUString getLocalHost() const
Get the hostname for the local interface.
Definition: socket.hxx:287
sal_Int32 getOption(oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
Retrieves option-attributes associated with the socket.
Definition: socket.hxx:347
SAL_DLLPUBLIC sal_Int32 osl_sendToSocket(oslSocket Socket, oslSocketAddr ReceiverAddr, const void *pBuffer, sal_uInt32 BytesToSend, oslSocketMsgFlag Flag)
Tries to send one datagram with BytesToSend data to the given ReceiverAddr via the (implicitly unconn...
SAL_DLLPUBLIC sal_Bool osl_isEqualSocketAddr(oslSocketAddr Addr1, oslSocketAddr Addr2)
Compares the values of two SocketAddresses.
SAL_DLLPUBLIC sal_Int32 osl_readSocket(oslSocket Socket, void *pBuffer, sal_Int32 nSize)
Retrieves n bytes from the stream and copies them into pBuffer.
SAL_DLLPUBLIC oslSocketResult osl_connectSocketTo(oslSocket Socket, oslSocketAddr Addr, const TimeValue *pTimeout)
Connects the socket to the given address.
oslSocketError getError() const
returns a constant describing the last error for the socket system.
Definition: socket.hxx:399
SAL_DLLPUBLIC sal_Bool osl_isSendReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if send operations will block.
SAL_DLLPUBLIC sal_Bool osl_enableNonBlockingMode(oslSocket Socket, sal_Bool On)
Enables/disables non-blocking-mode of the socket.
SAL_DLLPUBLIC sal_Int32 osl_getSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Retrieves attributes associated with the socket.
bool isExceptionPending(const TimeValue *pTimeout=NULL) const
Checks if a request for out-of-band data will block.
Definition: socket.hxx:335
SAL_DLLPUBLIC void osl_getLastSocketErrorDescription(oslSocket Socket, rtl_uString **strError)
returns a string which describes the last socket error.
SAL_DLLPUBLIC sal_Bool osl_isNonBlockingMode(oslSocket Socket)
Query state of non-blocking-mode of the socket.
SAL_DLLPUBLIC sal_Bool osl_shutdownSocket(oslSocket Socket, oslSocketDirection Direction)
Shuts down communication on a connected socket.
SAL_DLLPUBLIC sal_Bool osl_isReceiveReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if read operations will block.
bool bind(const SocketAddr &LocalInterface)
Binds the socket to the specified (local) interface.
Definition: socket.hxx:317
SAL_DLLPUBLIC void osl_destroySocketAddr(oslSocketAddr Addr)
Frees all resources allocated by Addr.
SAL_DLLPUBLIC sal_Bool osl_setInetPortOfSocketAddr(oslSocketAddr Addr, sal_Int32 Port)
Sets the Port of Addr.
SAL_DLLPUBLIC oslSocketAddr osl_createEmptySocketAddr(oslAddrFamily Family)
Creates a socket-address for the given family.
bool isRecvReady(const TimeValue *pTimeout=NULL) const
Checks if read operations will block.
Definition: socket.hxx:323
oslSocketResult connect(const SocketAddr &TargetHost, const TimeValue *pTimeout=NULL)
Connects the socket to a (remote) host.
Definition: socket.hxx:476
oslProtocol
represent a specific protocol within a address-family
Definition: socket.h:55
oslSocketAddr m_handle
Definition: socket_decl.hxx:42
__osl_socket_NoCopy
Definition: socket_decl.hxx:33
oslSocketType getType() const
Queries the socket for its type.
Definition: socket.hxx:341
SAL_DLLPUBLIC void osl_acquireSocket(oslSocket Socket)
increases the refcount of the socket handle by one
SAL_DLLPUBLIC oslSocketResult osl_getLocalHostname(rtl_uString **strLocalHostname)
Retrieve this machines hostname.
SAL_DLLPUBLIC sal_Int32 osl_receiveSocket(oslSocket Socket, void *pBuffer, sal_uInt32 BytesToRead, oslSocketMsgFlag Flag)
Tries to receive BytesToRead data from the connected socket, if no error occurs.
sal_Int32 getPort() const
Returns the port number of the address.
Definition: socket.hxx:93
This String class provides base functionality for C++ like Unicode character array handling...
Definition: ustring.hxx:120
definition of a no acquire enum for ctors
Definition: types.h:380
SAL_DLLPUBLIC oslSocketAddr osl_resolveHostname(rtl_uString *strHostname)
Uses the systems name-service interface to find an address for strHostname.
SAL_DLLPUBLIC sal_Bool osl_isExceptionPending(oslSocket Socket, const TimeValue *pTimeout)
Checks if a request for out-of-band data will block.
Definition: time.h:66
SAL_DLLPUBLIC oslSocketType osl_getSocketType(oslSocket Socket)
Queries the socket for its type.
bool operator==(const Socket &rSocket) const
Definition: socket.hxx:249
C++ class representing a SAL byte sequence.
Definition: byteseq.h:165
The class should be understood as a reference to a socket address handle (struct sockaddr).
Definition: socket_decl.hxx:39
bool setPort(sal_Int32 nPort)
Sets the port number of the address.
Definition: socket.hxx:99
Socket & operator=(oslSocket socketHandle)
Assignment operator.
Definition: socket.hxx:234
AcceptorSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Definition: socket.hxx:483
void getLocalAddr(SocketAddr &Addr) const
Retrieves the address of the local interface of this socket.
Definition: socket.hxx:273
inline::rtl::OUString getErrorAsString() const
Builds a string with the last error-message for the socket.
Definition: socket.hxx:405
SAL_DLLPUBLIC oslSocketAddr osl_copySocketAddr(oslSocketAddr Addr)
Creates a new SocketAddress and fills it from Addr.
SAL_DLLPUBLIC sal_Int32 osl_getServicePort(rtl_uString *strServicename, rtl_uString *strProtocol)
Looks up the port-number designated to the specified service/protocol-pair.
Definition: socket.h:194
static sal_Int32 getServicePort(const ::rtl::OUString &strServiceName, const ::rtl::OUString &strProtocolName=::rtl::OUString("tcp"))
Tries to find the port associated with the given service/protocol- pair (e.g.
Definition: socket.hxx:194
SAL_DLLPUBLIC oslSocket osl_acceptConnectionOnSocket(oslSocket Socket, oslSocketAddr *pAddr)
Waits for an ingoing connection on the socket.
oslSocket m_handle
Definition: socket_decl.hxx:194
void close()
Closes a socket.
Definition: socket.hxx:267
bool isSendReady(const TimeValue *pTimeout=NULL) const
Checks if send operations will block.
Definition: socket.hxx:329
bool enableNonBlockingMode(bool bNonBlockingMode)
Enables/disables non-blocking mode of the socket.
Definition: socket.hxx:380
Definition: socket.h:46
Definition: socket_decl.hxx:526
SAL_DLLPUBLIC oslSocketAddr osl_createInetSocketAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet-address, consisting of host address and port.
inline::rtl::ByteSequence getAddr(oslSocketResult *pResult=NULL) const
Returns the address of the underlying socket in network byte order.
Definition: socket.hxx:117
Definition: socket.h:195
Definition: conditn.hxx:36
SocketAddr & operator=(oslSocketAddr Addr)
assign the handle to this reference.
Definition: socket.hxx:127
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:45
sal_Int32 getLocalPort() const
Get the local port of the socket.
Definition: socket.hxx:279
Definition: socket_decl.hxx:191
bool is() const
Checks if the SocketAddr was created successful.
Definition: socket.hxx:174
Definition: socket_decl.hxx:33
SAL_DLLPUBLIC sal_Bool osl_setSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Sets the sockets attributes.
SAL_DLLPUBLIC oslSocket osl_createSocket(oslAddrFamily Family, oslSocketType Type, oslProtocol Protocol)
Create a socket of the specified Family and Type.
sal_Int32 write(const void *pBuffer, sal_uInt32 n)
Writes n bytes from pBuffer to the stream.
Definition: socket.hxx:447
SAL_DLLPUBLIC sal_Int32 osl_getInetPortOfSocketAddr(oslSocketAddr Addr)
Retrieves the internet port-number of Addr.