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