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