LibreOffice
LibreOffice 4.1 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
socket_decl.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 #ifndef _OSL_SOCKET_DECL_HXX_
21 #define _OSL_SOCKET_DECL_HXX_
22 
23 #include <osl/socket.h>
24 #include <rtl/ustring.hxx>
25 #include <rtl/byteseq.hxx>
26 
27 namespace osl
28 {
30 
35  class SocketAddr
36  {
37  protected:
39  public:
40 
43  inline SocketAddr();
44 
47  inline SocketAddr(const SocketAddr& Addr);
48 
53  inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy );
54 
57  inline SocketAddr(oslSocketAddr Addr);
58 
64  inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort );
65 
68  inline ~SocketAddr();
69 
74  inline sal_Bool is() const;
75 
84  inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const;
85 
88  inline sal_Bool SAL_CALL setHostname( const ::rtl::OUString &sDottedIpOrHostname );
89 
93  inline sal_Int32 SAL_CALL getPort() const;
94 
98  inline sal_Bool SAL_CALL setPort( sal_Int32 nPort );
99 
103  inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address );
104 
107  inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const;
108 
111  inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
112 
115  inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
116 
121  inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
122 
125  inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const;
126 
129  inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
130 
133  inline oslSocketAddr SAL_CALL getHandle() const;
134 
140  static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0);
141 
146  static inline void SAL_CALL resolveHostname(
147  const ::rtl::OUString & strHostName , SocketAddr & Addr );
148 
155  static inline sal_Int32 SAL_CALL getServicePort(
156  const ::rtl::OUString& strServiceName,
157  const ::rtl::OUString & strProtocolName= ::rtl::OUString("tcp") );
158  };
159 
160 
161  class Socket
162  {
163  protected:
165  protected:
171  inline Socket(oslSocketType Type,
174  public:
175  inline Socket( );
176 
177  inline Socket( const Socket & socket );
178 
179  inline Socket( oslSocket socketHandle );
180 
186  inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
187 
190  inline ~Socket();
191 
195  inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
196 
200  inline Socket& SAL_CALL operator= (const Socket& sock);
201 
206  inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ;
207 
212  inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const;
213 
219  inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
220 
226  inline void SAL_CALL close();
227 
232  inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
233 
237  inline sal_Int32 SAL_CALL getLocalPort() const;
238 
242  inline ::rtl::OUString SAL_CALL getLocalHost() const;
243 
247  inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
248 
252  inline sal_Int32 SAL_CALL getPeerPort() const;
253 
257  inline ::rtl::OUString SAL_CALL getPeerHost() const;
258 
263  inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface);
264 
275  inline sal_Bool SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const;
276 
287  inline sal_Bool SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const;
288 
289 
302  inline sal_Bool SAL_CALL isExceptionPending(const TimeValue *pTimeout = 0) const;
303 
304 
316  inline oslSocketType SAL_CALL getType() const;
317 
399  inline sal_Int32 SAL_CALL getOption(
400  oslSocketOption Option,
401  void* pBuffer,
402  sal_uInt32 BufferLen,
404 
446  inline sal_Bool SAL_CALL setOption( oslSocketOption Option,
447  void* pBuffer,
448  sal_uInt32 BufferLen,
450 
454  inline sal_Bool setOption( oslSocketOption option, sal_Int32 nValue );
455 
459  inline sal_Int32 getOption( oslSocketOption option ) const;
460 
467  inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode);
468 
472  inline sal_Bool SAL_CALL isNonBlockingMode() const;
473 
474 
477  inline void SAL_CALL clearError() const;
478 
486  inline oslSocketError getError() const;
487 
490  inline ::rtl::OUString getErrorAsString( ) const;
491 
494  inline oslSocket getHandle() const;
495  };
496 
497 
498  class StreamSocket : public Socket
499  {
500  public:
512 
513  inline StreamSocket( const StreamSocket & );
514 
515  inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
516 
517  inline StreamSocket( oslSocket Socket );
518 
528  inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
529 
537  inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
538 
539 
556  inline sal_Int32 SAL_CALL recv(void* pBuffer,
557  sal_uInt32 BytesToRead,
559 
576  sal_Int32 SAL_CALL send(const void* pBuffer,
577  sal_uInt32 BytesToSend,
579  };
580 
582  {
583  public:
595 
596 
606  oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0);
607  };
608 
611  class AcceptorSocket : public Socket
612  {
613  public:
617 
625  inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
626 
634  inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
635 
645  inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection, SocketAddr & PeerAddr);
646  };
647 
648 
649 
652  class DatagramSocket : public Socket
653  {
654  public:
655 
664 
684  inline sal_Int32 SAL_CALL recvFrom(void* pBuffer,
685  sal_uInt32 BufferSize,
686  SocketAddr* pSenderAddr= 0,
688 
711  inline sal_Int32 SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
712  const void* pBuffer,
713  sal_uInt32 BufferSize,
715  };
716 
717 }
718 
719 #endif
720 
721 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */