LibreOffice: osl/socket.hxx Source File

LibreOffice LibreOffice 7.3 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
29namespace osl
30{
31
32 inline SocketAddr::SocketAddr()
33 : m_handle( osl_createEmptySocketAddr( osl_Socket_FamilyInet ) )
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
48 inline SocketAddr::SocketAddr(oslSocketAddr Addr)
49 : m_handle( osl_copySocketAddr( Addr ) )
50 {
51 }
52
53
54 inline SocketAddr::SocketAddr(oslSocketAddr Addr, __osl_socket_NoCopy )
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 {
70 osl_setInetPortOfSocketAddr(m_handle, nPort);
71 }
72 else
73 {
74 osl_destroySocketAddr( m_handle );
75 m_handle = NULL;
76 }
77 }
78 }
79
80
81 inline SocketAddr::~SocketAddr()
82 {
83 if( m_handle )
84 osl_destroySocketAddr( 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 {
100 return osl_getInetPortOfSocketAddr(m_handle);
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
132 inline SocketAddr & SAL_CALL SocketAddr::operator= (oslSocketAddr Addr)
133 {
134 oslSocketAddr pNewAddr = osl_copySocketAddr( Addr );
135 if( m_handle )
136 osl_destroySocketAddr( 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
159 inline SocketAddr & SAL_CALL SocketAddr::assign( oslSocketAddr Addr, __osl_socket_NoCopy )
160 {
161 if( m_handle )
162 osl_destroySocketAddr( 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
173 inline oslSocketAddr SocketAddr::getHandle() const
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
207 inline Socket::Socket(oslSocketType Type,
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 {
222 osl_acquireSocket( m_handle );
223 }
224
225
226 inline Socket::Socket( const Socket & socket )
227 : m_handle( socket.getHandle() )
228 {
229 osl_acquireSocket( m_handle );
230 }
231
232
233 inline Socket::~Socket()
234 {
235 osl_releaseSocket( m_handle );
236 }
237
238
239 inline Socket& Socket::operator= ( oslSocket socketHandle)
240 {
241 osl_acquireSocket( socketHandle );
242 osl_releaseSocket( m_handle );
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 {
275 osl_closeSocket( m_handle );
276 }
277
278
279 inline void Socket::getLocalAddr( SocketAddr & addr) const
280 {
281 addr.assign( osl_getLocalAddrOfSocket( m_handle ) , SAL_NO_COPY );
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 {
303 addr.assign( osl_getPeerAddrOfSocket( m_handle ), SAL_NO_COPY );
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
347 inline oslSocketType Socket::getType() const
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 {
394 return osl_isNonBlockingMode( m_handle );
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
405 inline oslSocketError Socket::getError() const
406 {
407 return osl_getLastSocketError( m_handle );
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
419 inline oslSocket Socket::getHandle() const
420 {
421 return m_handle;
422 }
423
424
425 inline StreamSocket::StreamSocket(oslAddrFamily Family,
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
470 inline ConnectorSocket::ConnectorSocket(oslAddrFamily Family,
471 oslProtocol Protocol,
472 oslSocketType Type)
473 : StreamSocket( Family, Protocol ,Type )
474 {}
475
476
477 inline oslSocketResult ConnectorSocket::connect( const SocketAddr& TargetHost,
478 const TimeValue* pTimeout )
479 {
480 return osl_connectSocketTo( m_handle , TargetHost.getHandle(), pTimeout );
481 }
482
483
484 inline AcceptorSocket::AcceptorSocket(oslAddrFamily Family ,
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
497 inline oslSocketResult AcceptorSocket::acceptConnection( StreamSocket& Connection)
498 {
499 oslSocket o = osl_acceptConnectionOnSocket( m_handle, NULL );
500 oslSocketResult status = osl_Socket_Ok;
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
514 inline oslSocketResult AcceptorSocket::acceptConnection(
515 StreamSocket& Connection, SocketAddr & PeerAddr)
516 {
517 // TODO change in/OUT parameter
518 oslSocket o = osl_acceptConnectionOnSocket(
519 m_handle, reinterpret_cast<oslSocketAddr *>(&PeerAddr));
520 oslSocketResult status = osl_Socket_Ok;
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
534 inline DatagramSocket::DatagramSocket(oslAddrFamily Family,
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: */
__sal_NoAcquire
__sal_NoAcquire
Definition: types.h:353
SAL_NO_ACQUIRE
@ SAL_NO_ACQUIRE
definition of a no acquire enum for ctors
Definition: types.h:356
oslSocketOption
oslSocketOption
Represents socket-options.
Definition: socket.h:89
osl_Socket_OptionError
@ osl_Socket_OptionError
Definition: socket.h:114
osl_setInetPortOfSocketAddr
SAL_DLLPUBLIC sal_Bool osl_setInetPortOfSocketAddr(oslSocketAddr Addr, sal_Int32 Port)
Sets the Port of Addr.
osl_getSocketOption
SAL_DLLPUBLIC sal_Int32 osl_getSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Retrieves attributes associated with the socket.
osl_getInetPortOfSocketAddr
SAL_DLLPUBLIC sal_Int32 osl_getInetPortOfSocketAddr(oslSocketAddr Addr)
Retrieves the internet port-number of Addr.
osl_getAddrOfSocketAddr
SAL_DLLPUBLIC oslSocketResult osl_getAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence **ppByteSeq)
Returns the addr field in the struct sockaddr.
osl_listenOnSocket
SAL_DLLPUBLIC sal_Bool osl_listenOnSocket(oslSocket Socket, sal_Int32 MaxPendingConnections)
Prepares the socket to act as an acceptor of incoming connections.
oslSocketResult
oslSocketResult
Common return codes of socket related functions.
Definition: socket.h:197
osl_Socket_Ok
@ osl_Socket_Ok
Definition: socket.h:198
osl_Socket_Error
@ osl_Socket_Error
Definition: socket.h:199
oslSocketAddr
struct oslSocketAddrImpl * oslSocketAddr
Opaque datatype SocketAddr.
Definition: socket.h:44
osl_bindAddrToSocket
SAL_DLLPUBLIC sal_Bool osl_bindAddrToSocket(oslSocket Socket, oslSocketAddr Addr)
Binds the given address to the socket.
osl_acceptConnectionOnSocket
SAL_DLLPUBLIC oslSocket osl_acceptConnectionOnSocket(oslSocket Socket, oslSocketAddr *pAddr)
Waits for an ingoing connection on the socket.
osl_closeSocket
SAL_DLLPUBLIC void osl_closeSocket(oslSocket Socket)
Closes the socket terminating any ongoing dataflow.
osl_acquireSocket
SAL_DLLPUBLIC void osl_acquireSocket(oslSocket Socket)
increases the refcount of the socket handle by one
osl_isSendReady
SAL_DLLPUBLIC sal_Bool osl_isSendReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if send operations will block.
osl_setAddrOfSocketAddr
SAL_DLLPUBLIC oslSocketResult osl_setAddrOfSocketAddr(oslSocketAddr Addr, sal_Sequence *pByteSeq)
Sets the addr field in the struct sockaddr with pByteSeq.
osl_releaseSocket
SAL_DLLPUBLIC void osl_releaseSocket(oslSocket Socket)
decreases the refcount of the socket handle by one.
oslSocketType
oslSocketType
Represents the type of a socket.
Definition: socket.h:71
osl_getLastSocketError
SAL_DLLPUBLIC oslSocketError osl_getLastSocketError(oslSocket Socket)
Returns a constant describing the last error for the socket system.
osl_isNonBlockingMode
SAL_DLLPUBLIC sal_Bool osl_isNonBlockingMode(oslSocket Socket)
Query state of non-blocking-mode of the socket.
osl_destroySocketAddr
SAL_DLLPUBLIC void osl_destroySocketAddr(oslSocketAddr Addr)
Frees all resources allocated by Addr.
osl_getLocalAddrOfSocket
SAL_DLLPUBLIC oslSocketAddr osl_getLocalAddrOfSocket(oslSocket Socket)
Retrieves the Address of the local end of the socket.
osl_isReceiveReady
SAL_DLLPUBLIC sal_Bool osl_isReceiveReady(oslSocket Socket, const TimeValue *pTimeout)
Checks if read operations will block.
osl_getSocketType
SAL_DLLPUBLIC oslSocketType osl_getSocketType(oslSocket Socket)
Queries the socket for its type.
osl_setSocketOption
SAL_DLLPUBLIC sal_Bool osl_setSocketOption(oslSocket Socket, oslSocketOptionLevel Level, oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen)
Sets the sockets attributes.
oslSocket
struct oslSocketImpl * oslSocket
Definition: socket.h:216
osl_receiveSocket
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.
osl_createSocket
SAL_DLLPUBLIC oslSocket osl_createSocket(oslAddrFamily Family, oslSocketType Type, oslProtocol Protocol)
Create a socket of the specified Family and Type.
osl_writeSocket
SAL_DLLPUBLIC sal_Int32 osl_writeSocket(oslSocket Socket, const void *pBuffer, sal_Int32 nSize)
Writes n bytes from pBuffer to the stream.
oslSocketOptionLevel
oslSocketOptionLevel
Represents the different socket-option levels.
Definition: socket.h:125
osl_createInetSocketAddr
SAL_DLLPUBLIC oslSocketAddr osl_createInetSocketAddr(rtl_uString *strDottedAddr, sal_Int32 Port)
Create an internet-address, consisting of host address and port.
osl_createEmptySocketAddr
SAL_DLLPUBLIC oslSocketAddr osl_createEmptySocketAddr(oslAddrFamily Family)
Creates a socket-address for the given family.
osl_getPeerAddrOfSocket
SAL_DLLPUBLIC oslSocketAddr osl_getPeerAddrOfSocket(oslSocket Socket)
Retrieves the Address of the remote end of the socket.
oslSocketDirection
oslSocketDirection
Used by shutdown to denote which end of the socket to "close".
Definition: socket.h:148
osl_readSocket
SAL_DLLPUBLIC sal_Int32 osl_readSocket(oslSocket Socket, void *pBuffer, sal_Int32 nSize)
Retrieves n bytes from the stream and copies them into pBuffer.
osl_sendToSocket
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...
osl_sendSocket
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.
osl_enableNonBlockingMode
SAL_DLLPUBLIC sal_Bool osl_enableNonBlockingMode(oslSocket Socket, sal_Bool On)
Enables/disables non-blocking-mode of the socket.
oslProtocol
oslProtocol
represent a specific protocol within an address-family
Definition: socket.h:59
oslSocketError
oslSocketError
Describes the various error socket error conditions, which may occur.
Definition: socket.h:158
osl_receiveFromSocket
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,...
oslAddrFamily
oslAddrFamily
Represents the address-family of a socket.
Definition: socket.h:49
osl_Socket_FamilyInet
@ osl_Socket_FamilyInet
Definition: socket.h:50
osl_connectSocketTo
SAL_DLLPUBLIC oslSocketResult osl_connectSocketTo(oslSocket Socket, oslSocketAddr Addr, const TimeValue *pTimeout)
Connects the socket to the given address.
osl_getLocalHostname
SAL_DLLPUBLIC oslSocketResult osl_getLocalHostname(rtl_uString **strLocalHostname)
Retrieve this machines hostname (NOT the FQDN)
osl_getServicePort
SAL_DLLPUBLIC sal_Int32 osl_getServicePort(rtl_uString *strServicename, rtl_uString *strProtocol)
Looks up the port-number designated to the specified service/protocol-pair.
osl_resolveHostname
SAL_DLLPUBLIC oslSocketAddr osl_resolveHostname(rtl_uString *strHostname)
Uses the systems name-service interface to find an address for strHostname.
osl_getHostnameOfSocketAddr
SAL_DLLPUBLIC oslSocketResult osl_getHostnameOfSocketAddr(oslSocketAddr Addr, rtl_uString **strHostname)
Returns the hostname represented by Addr.
oslSocketMsgFlag
oslSocketMsgFlag
Represents flags to be used with send/recv-calls.
Definition: socket.h:135
osl_copySocketAddr
SAL_DLLPUBLIC oslSocketAddr osl_copySocketAddr(oslSocketAddr Addr)
Creates a new SocketAddress and fills it from Addr.
osl_isExceptionPending
SAL_DLLPUBLIC sal_Bool osl_isExceptionPending(oslSocket Socket, const TimeValue *pTimeout)
Checks if a request for out-of-band data will block.
osl_getLastSocketErrorDescription
SAL_DLLPUBLIC void osl_getLastSocketErrorDescription(oslSocket Socket, rtl_uString **strError)
returns a string which describes the last socket error.
osl_isEqualSocketAddr
SAL_DLLPUBLIC sal_Bool osl_isEqualSocketAddr(oslSocketAddr Addr1, oslSocketAddr Addr2)
Compares the values of two SocketAddresses.
osl_shutdownSocket
SAL_DLLPUBLIC sal_Bool osl_shutdownSocket(oslSocket Socket, oslSocketDirection Direction)
Shuts down communication on a connected socket.
socket_decl.hxx
osl
Definition: component.hxx:34
osl::__osl_socket_NoCopy
__osl_socket_NoCopy
Definition: socket_decl.hxx:37
osl::SAL_NO_COPY
@ SAL_NO_COPY
Definition: socket_decl.hxx:37
osl::SocketAddr
The class should be understood as a reference to a socket address handle (struct sockaddr).
Definition: socket_decl.hxx:44
osl::SocketAddr::getHostname
inline ::rtl::OUString getHostname(oslSocketResult *pResult=NULL) const
Converts the address to a (human readable) domain-name.
Definition: socket.hxx:88
osl::SocketAddr::operator==
bool operator==(oslSocketAddr Addr) const
Returns true if the underlying handle is identical to the Addr handle.
Definition: socket.hxx:168
osl::SocketAddr::resolveHostname
static void resolveHostname(const ::rtl::OUString &strHostName, SocketAddr &Addr)
Tries to find an address for a host.
Definition: socket.hxx:193
osl::SocketAddr::getAddr
inline ::rtl::ByteSequence getAddr(oslSocketResult *pResult=NULL) const
Returns the address of the underlying socket in network byte order.
Definition: socket.hxx:122
osl::SocketAddr::setPort
bool setPort(sal_Int32 nPort)
Sets the port number of the address.
Definition: socket.hxx:104
osl::SocketAddr::setAddr
bool setAddr(const ::rtl::ByteSequence &address)
Sets the address of the underlying socket address struct in network byte order.
Definition: socket.hxx:116
osl::SocketAddr::operator=
SocketAddr & operator=(oslSocketAddr Addr)
assign the handle to this reference.
Definition: socket.hxx:132
osl::SocketAddr::getLocalHostname
static inline ::rtl::OUString getLocalHostname(oslSocketResult *pResult=NULL)
Get the hostname for the local interface.
Definition: socket.hxx:184
osl::SocketAddr::getHandle
oslSocketAddr getHandle() const
Returns the underlying SocketAddr handle without copyconstructing it.
Definition: socket.hxx:173
osl::SocketAddr::assign
SocketAddr & assign(oslSocketAddr Addr, __osl_socket_NoCopy nocopy)
Assigns the socket addr without copyconstructing it.
Definition: socket.hxx:159
osl::SocketAddr::setHostname
bool setHostname(const ::rtl::OUString &sDottedIpOrHostname)
Sets the IP address or hostname of the SocketAddress.
Definition: socket.hxx:109
osl::SocketAddr::getServicePort
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
osl::SocketAddr::SocketAddr
SocketAddr()
Creates socket address of unknown type.
Definition: socket.hxx:32
osl::SocketAddr::getPort
sal_Int32 getPort() const
Returns the port number of the address.
Definition: socket.hxx:98
osl::SocketAddr::is
bool is() const
Checks if the SocketAddr was created successful.
Definition: socket.hxx:179
osl::SocketAddr::m_handle
oslSocketAddr m_handle
Definition: socket_decl.hxx:46
osl::SocketAddr::~SocketAddr
~SocketAddr()
destroys underlying oslSocketAddress
Definition: socket.hxx:81
osl::Socket
Definition: socket_decl.hxx:196
osl::Socket::getPeerPort
sal_Int32 getPeerPort() const
Get the remote port of the socket.
Definition: socket.hxx:307
osl::Socket::getHandle
oslSocket getHandle() const
Returns the underlying handle unacquired (The caller must acquire it to keep it).
Definition: socket.hxx:419
osl::Socket::setOption
bool setOption(oslSocketOption Option, void *pBuffer, sal_uInt32 BufferLen, oslSocketOptionLevel Level=osl_Socket_LevelSocket) const
Sets the sockets attributes.
Definition: socket.hxx:363
osl::Socket::shutdown
void shutdown(oslSocketDirection Direction=osl_Socket_DirReadWrite)
Closes a definite or both directions of the bidirectional stream.
Definition: socket.hxx:267
osl::Socket::isNonBlockingMode
bool isNonBlockingMode() const
Query blocking mode of the socket.
Definition: socket.hxx:392
osl::Socket::getError
oslSocketError getError() const
returns a constant describing the last error for the socket system.
Definition: socket.hxx:405
osl::Socket::getErrorAsString
inline ::rtl::OUString getErrorAsString() const
Builds a string with the last error-message for the socket.
Definition: socket.hxx:411
osl::Socket::getPeerHost
inline ::rtl::OUString getPeerHost() const
Get the hostname for the remote interface.
Definition: socket.hxx:315
osl::Socket::getLocalPort
sal_Int32 getLocalPort() const
Get the local port of the socket.
Definition: socket.hxx:285
osl::Socket::getPeerAddr
void getPeerAddr(SocketAddr &Addr) const
Retrieves the address of the remote host of this socket.
Definition: socket.hxx:301
osl::Socket::bind
bool bind(const SocketAddr &LocalInterface)
Binds the socket to the specified (local) interface.
Definition: socket.hxx:323
osl::Socket::getType
oslSocketType getType() const
Queries the socket for its type.
Definition: socket.hxx:347
osl::Socket::isSendReady
bool isSendReady(const TimeValue *pTimeout=NULL) const
Checks if send operations will block.
Definition: socket.hxx:335
osl::Socket::getLocalAddr
void getLocalAddr(SocketAddr &Addr) const
Retrieves the address of the local interface of this socket.
Definition: socket.hxx:279
osl::Socket::close
void close()
Closes a socket.
Definition: socket.hxx:273
osl::Socket::isRecvReady
bool isRecvReady(const TimeValue *pTimeout=NULL) const
Checks if read operations will block.
Definition: socket.hxx:329
osl::Socket::Socket
Socket()
osl::Socket::getLocalHost
inline ::rtl::OUString getLocalHost() const
Get the hostname for the local interface.
Definition: socket.hxx:293
osl::Socket::isExceptionPending
bool isExceptionPending(const TimeValue *pTimeout=NULL) const
Checks if a request for out-of-band data will block.
Definition: socket.hxx:341
osl::Socket::m_handle
oslSocket m_handle
Definition: socket_decl.hxx:198
osl::Socket::clearError
void clearError() const
clears the error status
Definition: socket.hxx:398
osl::Socket::enableNonBlockingMode
bool enableNonBlockingMode(bool bNonBlockingMode)
Enables/disables non-blocking mode of the socket.
Definition: socket.hxx:386
osl::Socket::operator==
bool operator==(const Socket &rSocket) const
Definition: socket.hxx:255
osl::Socket::getOption
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
osl::Socket::operator=
Socket & operator=(oslSocket socketHandle)
Assignment operator.
Definition: socket.hxx:239
osl::Socket::~Socket
~Socket()
Destructor.
Definition: socket.hxx:233
osl::StreamSocket
Definition: socket_decl.hxx:531
osl::StreamSocket::StreamSocket
StreamSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Creates a socket.
Definition: socket.hxx:425
osl::StreamSocket::write
sal_Int32 write(const void *pBuffer, sal_uInt32 n)
Writes n bytes from pBuffer to the stream.
Definition: socket.hxx:448
osl::StreamSocket::read
sal_Int32 read(void *pBuffer, sal_uInt32 n)
Retrieves n bytes from the stream and copies them into pBuffer.
Definition: socket.hxx:442
osl::StreamSocket::send
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
osl::StreamSocket::recv
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
osl::ConnectorSocket::ConnectorSocket
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
osl::ConnectorSocket::connect
oslSocketResult connect(const SocketAddr &TargetHost, const TimeValue *pTimeout=NULL)
Connects the socket to a (remote) host.
Definition: socket.hxx:477
osl::AcceptorSocket::acceptConnection
oslSocketResult acceptConnection(StreamSocket &Connection)
Accepts incoming connections on the socket.
Definition: socket.hxx:497
osl::AcceptorSocket::listen
bool listen(sal_Int32 MaxPendingConnections=-1)
Prepare a socket for the accept-call.
Definition: socket.hxx:491
osl::AcceptorSocket::AcceptorSocket
AcceptorSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeStream)
Definition: socket.hxx:484
osl::DatagramSocket::DatagramSocket
DatagramSocket(oslAddrFamily Family=osl_Socket_FamilyInet, oslProtocol Protocol=osl_Socket_ProtocolIp, oslSocketType Type=osl_Socket_TypeDgram)
Creates a datagram socket.
Definition: socket.hxx:534
osl::DatagramSocket::sendTo
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
osl::DatagramSocket::recvFrom
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
TimeValue
Definition: time.h:72
rtl::ByteSequence
C++ class representing a SAL byte sequence.
Definition: byteseq.h:170
rtl::OUString
This String class provides base functionality for C++ like Unicode character array handling.
Definition: ustring.hxx:204
_sal_Sequence
This is the binary specification of a SAL sequence.
Definition: types.h:304