xref: /trunk/main/sal/inc/osl/socket_decl.hxx (revision 565d668c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _OSL_SOCKET_DECL_HXX_
25 #define _OSL_SOCKET_DECL_HXX_
26 
27 #include <osl/socket.h>
28 #include <rtl/ustring.hxx>
29 #include <rtl/byteseq.hxx>
30 
31 /** @HTML
32  */
33 namespace osl
34 {
35 	enum __osl_socket_NoCopy { SAL_NO_COPY };
36 
37     /** The class should be understood as a reference to a socket address handle ( struct sockaddr ).
38 
39 		The handle is mutable.
40 	 */
41 	class SocketAddr
42 	{
43 	protected:
44 		oslSocketAddr m_handle;
45 	public:
46 
47 		/** Creates socket address of unknown type.
48 		 */
49 		inline SocketAddr();
50 
51 		/** Copy constructor.
52 		 */
53 		inline SocketAddr(const SocketAddr& Addr);
54 
55 		/** The SocketAddr takes over the responsibility of the handle ( which means,
56 			that the handle gets destructed by the destructor of this reference)
57 
58 			@param nocopy use SAL_NO_COPY
59 		 */
60 		inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy );
61 
62 		/** Copyconstructs the oslSocketAddr handle.
63 		 */
64 		inline SocketAddr(oslSocketAddr Addr);
65 
66 		/** tcpip-specif constructor.
67 			@param strAddrOrHostName strAddrOrHostName hostname or dotted ip-number of the network
68 			                         interface, the socket shall be created on.
69 			@param nPort             tcp-ip port number
70 		 */
71 		inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort );
72 
73 		/** destroys underlying oslSocketAddress
74 		 */
75 		inline ~SocketAddr();
76 
77 		/** checks, if the SocketAddr was created successful.
78 			@return <code>sal_True</code> if there is a valid underlying handle,
79 			        otherwise sal_False.
80 		 */
81 		inline sal_Bool is() const;
82 
83 		/** Converts the address to a (human readable) domain-name.
84 
85 			@param pResult 0, if you are not interested in errors,
86 			               otherwise *pResult contains an error code on failure
87 						   or osl_Socket_Ok on success
88 			@return the hostname of this SocketAddr or an empty string on failure.
89 			@see osl_getHostnameOfSocketAddr()
90 		*/
91 		inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const;
92 
93 		/** Sets the ipaddress or hostname of the SocketAddress
94 		 */
95 		inline sal_Bool SAL_CALL setHostname( const ::rtl::OUString &sDottedIpOrHostname );
96 
97 		/** Returns the port number of the address.
98 			@return the port in host-byte order or or OSL_INVALID_PORT on errors.
99 		*/
100 		inline sal_Int32 SAL_CALL getPort() const;
101 
102 		/** Sets the port number of the address.
103 		   @return true if successfule.
104 		 */
105 		inline sal_Bool SAL_CALL setPort( sal_Int32 nPort );
106 
107 		/** Sets the address of the underlying socket address struct in network byte order.
108 			@return true on success, false signales falure.
109 		 */
110 		inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address );
111 
112 		/** Returns the address of the underlying socket in network byte order
113 		  */
114 		inline ::rtl::ByteSequence  SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const;
115 
116 		/** assign the handle to this reference. The previous handle is released.
117 		*/
118 		inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr);
119 
120 		/**
121 		 */
122 		inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr);
123 
124 		/** Assigns the socket addr without copyconstructing it.
125 			@param nocopy use SAL_NO_COPY
126 		  */
127 		inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy );
128 
129 		/** Returns true if the underlying handle is identical to the Addr handle.
130 		 */
131 		inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const;
132 
133 		/** Returns true if the underlying handle is identical to the Addr handle.
134 		 */
135 		inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const;
136 
137 		/** Returns the underlying SocketAddr handle without copyconstructing it.
138 		 */
139 		inline oslSocketAddr SAL_CALL getHandle() const;
140 
141 		/** Get the hostname for the local interface.
142 			@param after the call *pResult contains osl_Socket_Ok on success or
143 			       an error on failure.
144 			@return the hostname
145 		*/
146 		static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0);
147 
148 		/** Tries to find an address for a host.
149 			@see osl_resolveHostname()
150 			@return A new created socket-address or 0 if the name could not be found.
151 		*/
152 		static inline void SAL_CALL resolveHostname(
153 			const ::rtl::OUString & strHostName , SocketAddr & Addr );
154 
155 		/**
156 		   Tries to find the port associated with the given service/protocol-
157 		   pair (e.g. "ftp"/"tcp").
158 		   @return the port number in host-byte order or <code>OSL_INVALID_PORT</code>
159 		   if no service/protocol pair could be found.
160 		*/
161 		static inline sal_Int32 SAL_CALL getServicePort(
162 			const ::rtl::OUString& strServiceName,
163 			const ::rtl::OUString & strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) );
164 	};
165 
166 
167 	class Socket
168 	{
169 	protected:
170 		oslSocket m_handle;
171 	protected:
172 		/** Creates a socket. Note it's protected.
173 			@param Type
174 			@param Family
175 			@param Protocol
176 		*/
177 		inline Socket(oslSocketType Type,
178 					  oslAddrFamily Family = osl_Socket_FamilyInet,
179 					  oslProtocol   Protocol = osl_Socket_ProtocolIp);
180 	public:
181 		inline Socket( );
182 
183 		inline Socket( const Socket & socket );
184 
185 		inline Socket( oslSocket socketHandle );
186 
187 		/** The instance takes over the handle's ownership without acquiring the
188 			handle, but releases it within the dtor.
189 			@param noacquire use SAL_NO_ACQUIRE
190 		 */
191 		inline Socket( oslSocket socketHandle, __sal_NoAcquire noacquire );
192 
193 		/** Destructor. Releases the underlying handle
194 		 */
195 		inline ~Socket();
196 
197 		/** Assignment operator. If socket was already created, the old one will
198 			be discarded.
199 		*/
200 		inline Socket& SAL_CALL operator= ( oslSocket socketHandle);
201 
202 		/** Assignment operator. If socket was already created, the old one will
203 			be discarded.
204 		*/
205 		inline Socket& SAL_CALL operator= (const Socket& sock);
206 
207 		/**
208 		   @return <code>sal_True</code>, when the underlying handle of both
209 		                 Socket instances are identical, <code>sal_False</code> otherwise.
210 		 */
211 		inline sal_Bool SAL_CALL operator==( const Socket& rSocket ) const ;
212 
213 		/**
214 		   @return <code>sal_True</code>, when the underlying handle of both
215 		                 Socket instances are identical, <code>sal_False</code> otherwise.
216 		 */
217 		inline sal_Bool SAL_CALL operator==( const oslSocket socketHandle ) const;
218 
219 		/** Closes a definite or both directions of the bidirectional stream.
220 
221 		   @param Direction
222 		   @see osl_shutdownSocket()
223 		 */
224 		inline void SAL_CALL shutdown( oslSocketDirection Direction = osl_Socket_DirReadWrite );
225 
226 		/** Closes a socket.
227 			Note that closing a socket is identical to shutdown( osl_Socket_DirReadWrite ),
228 			as the operating system distinguish both cases, both functions or offered in this API.
229 			@see osl_closeSocket()
230 		 */
231 		inline void SAL_CALL close();
232 
233 		/** Retrieves the address of the local interface of this socket.
234 			@param Addr [out] receives the address.
235 			@see osl_getLocalAddrOfSocket()
236 		*/
237 		inline void SAL_CALL getLocalAddr( SocketAddr &Addr ) const;
238 
239 		/** Get the local port of the socket. Usually used after bind().
240 			@return the port number or OSL_INVALID_PORT on errors.
241 		*/
242 		inline sal_Int32	SAL_CALL getLocalPort() const;
243 
244 		/** Get the hostname for the local interface.
245 			@return the hostname or an empty string ("").
246 		*/
247 		inline ::rtl::OUString SAL_CALL getLocalHost() const;
248 
249 		/** Retrieves the address of the remote host of this socket.
250 			@param Addr [out] receives the address.
251 		*/
252 		inline void SAL_CALL getPeerAddr( SocketAddr & Addr) const;
253 
254 		/** Get the remote port of the socket.
255 			@return the port number or OSL_INVALID_PORT on errors.
256 		*/
257 		inline sal_Int32	SAL_CALL getPeerPort() const;
258 
259 		/** Get the hostname for the remote interface.
260 			@return the hostname or an empty string ("").
261 		*/
262 		inline ::rtl::OUString SAL_CALL getPeerHost() const;
263 
264 		/** Binds the socket to the specified (local) interface.
265 			@param LocalInterface Address of the Interface
266 			@return True if bind was successful.
267 		*/
268 		inline sal_Bool SAL_CALL bind(const SocketAddr& LocalInterface);
269 
270 		/** Checks if read operations will block.
271 
272 			You can specify a timeout-value in seconds/nanoseconds that denotes
273 			how the operation will block if the Socket is not ready.
274 			@return <code>sal_True</code> if read operations (recv, recvFrom, accept) on the Socket
275 			will NOT block; <code>sal_False</code> if it would block or if an error occured.
276 
277 			@param pTimeout if 0, the operation will block without a timeout. Otherwise
278 			the specified amout of time.
279 		*/
280 		inline sal_Bool	SAL_CALL isRecvReady(const TimeValue *pTimeout = 0) const;
281 
282 		/** Checks if send operations will block.
283 
284 			You can specify a timeout-value in seconds/nanoseconds that denotes
285 			how the operation will block if the Socket is not ready.
286 			@return <code>sal_True</code> if send operations (send, sendTo) on the Socket
287 			will NOT block; <code>sal_False</code> if it would block or if an error occured.
288 
289 			@param pTimeout if 0, the operation will block without a timeout. Otherwise
290 			the specified amout of time.
291 		*/
292 		inline sal_Bool	SAL_CALL isSendReady(const TimeValue *pTimeout = 0) const;
293 
294 
295 		/** Checks if a request for out-of-band data will block.
296 
297 			You can specify a timeout-value in seconds/nanoseconds that denotes
298 			how the operation will block if the Socket has no pending OOB data.
299 
300 			@return <code>sal_True</code> if OOB-request operations (recv with appropriate flags)
301 			on the Socket will NOT block; <code>sal_False</code> if it would block or if
302 			an error occured.
303 
304 			@param pTimeout if 0, the operation will block without a timeout. Otherwise
305 			the specified amout of time.
306 		*/
307 		inline sal_Bool	SAL_CALL isExceptionPending(const TimeValue *pTimeout = 0) const;
308 
309 
310 		/** Queries the socket for its type.
311 	        @return one of:
312 			<ul>
313 			<li> <code>osl_Socket_TypeStream</code>
314 			<li> <code>osl_Socket_TypeDgram</code>
315 			<li> <code>osl_Socket_TypeRaw</code>
316 			<li> <code>osl_Socket_TypeRdm</code>
317 			<li> <code>osl_Socket_TypeSeqPacket</code>
318 			<li> <code>osl_invalid_SocketType</code>, if an error occured
319 			</ul>
320 		*/
321 		inline oslSocketType	SAL_CALL getType() const;
322 
323 		/** Retrieves option-attributes associated with the socket.
324 			@param Option The attribute to query.
325 			Valid values (depending on the Level) are:
326 			<ul>
327 			<li> <code>osl_Socket_Option_Debug</code><br>
328 			     (sal_Bool) Socket debug flag 1 = enabled, 0 = disabled.
329 
330 			<li> <code>osl_Socket_OptionAcceptConn</code><br>
331 			<li> <code>osl_Socket_OptionReuseAddr</code><br>
332 			  (sal_Bool) Allows the socket to be bound to an address that is
333 			  already in use.
334 			  1 = multiple bound allowed, 0 = no multiple bounds allowed
335 
336 			<li><code>osl_Socket_OptionKeepAlive</code><br>
337 			   (sal_Bool) Keepalive packets are sent by the underlying socket.
338 			   1 = enabled, 0 = disabled
339 
340 			<li><code>osl_Socket_OptionDontRoute</code><br>
341 			   (sal_Bool) Do not route: send directly to interface.
342            	   1 = do not route , 0 = routing possible
343 
344 			<li><code>osl_Socket_OptionBroadcast</code><br>
345 			   (sal_Bool) Transmission of broadcast messages are allowed on the socket.
346 			   1 = transmission allowed, 0 = transmission disallowed
347 
348 			<li><code>osl_Socket_OptionUseLoopback</code><br>
349 
350 			<li><code>osl_Socket_OptionLinger</code><br>
351 			   (linger) Linger on close if unsent data is present.
352 			   linger has two members: l_onoff, l_linger
353 			   l_onoff = 0 is off, l_onoff > 0 and l_linger= timeout in seconds.
354 
355 			<li><code>osl_Socket_OptionOOBinLine</code><br>
356 
357 
358 			<li><code>osl_Socket_OptionSndBuf</code><br>
359 			  (sal_Int32) Size of the send buffer in bytes. Data is sent after
360 			  SndTimeo or when the buffer is full. This allows faster writing
361 			  to the socket.
362 
363 			<li><code>osl_Socket_OptionRcvBuf</code><br>
364 			  (sal_Int32) Size of the receive buffer in bytes. Data is sent after
365 			  SndTimeo or when the buffer is full. This allows faster writing
366 			  to the socket and larger packet sizes.
367 
368 			<li><code>osl_Socket_OptionSndLowat</code><br>
369 
370 			<li><code>osl_Socket_OptionRcvLowat</code><br>
371 
372 			<li><code>osl_Socket_OptionSndTimeo</code><br>
373 			  (sal_Int32) Data is sent after this timeout. This allows gathering
374 			  of data to send larger packages but increases latency times.
375 
376 			<li><code>osl_Socket_OptionRcvTimeo</code><br>
377 
378 			<li><code>osl_Socket_OptionError</code><br>
379 			<li><code>osl_Socket_OptionType</code><br>
380 
381 			<li><code>osl_Socket_OptionTcpNoDelay</code><br>
382 			  Disables the Nagle algorithm for send coalescing. (Do not
383 			  collect data until a packet is full, instead send immediatly.
384 			  This increases network traffic but might improve latency-times.)
385 			  1 = disables the algorithm, 0 = keeps it enabled.
386 			</ul>
387 
388 			  If not above mentioned otherwise, the options are only valid for
389 			  level <code>osl_Socket_LevelSocket</code>.
390 			@param pBuffer The Buffer will be filled with the attribute.
391 
392 			@param BufferSize The size of pBuffer.
393 
394 			@param Level The option level.
395 
396 			Valid values are:
397 			<ul>
398 			<li><code>osl_Socket_LevelSocket</code> : Socket Level
399 			<li><code>osl_Socket_LevelTcp</code>    : Level of Transmission Control Protocol
400 			</ul>
401 			@return The size of the attribute copied into pBuffer or -1 if an error
402 			occured.
403 		*/
404 		inline sal_Int32 SAL_CALL getOption(
405 			oslSocketOption Option,
406 			void* pBuffer,
407 			sal_uInt32 BufferLen,
408 			oslSocketOptionLevel Level= osl_Socket_LevelSocket) const;
409 
410 		/** Sets the sockets attributes.
411 
412 			@param Option denotes the option to modify.
413 			Valid values (depending on the Level) are:
414 			<ul>
415 			<li> osl_Socket_Option_Debug
416 			<li> osl_Socket_OptionAcceptConn
417 			<li> osl_Socket_OptionReuseAddr
418 			<li> osl_Socket_OptionKeepAlive
419 			<li> osl_Socket_OptionDontRoute
420 			<li> osl_Socket_OptionBroadcast
421 			<li> osl_Socket_OptionUseLoopback
422 			<li> osl_Socket_OptionLinger
423 			<li> osl_Socket_OptionOOBinLine
424 			<li> osl_Socket_OptionSndBuf
425 			<li> osl_Socket_OptionRcvBuf
426 			<li> osl_Socket_OptionSndLowat
427 			<li> osl_Socket_OptionRcvLowat
428 			<li> osl_Socket_OptionSndTimeo
429 			<li> osl_Socket_OptionRcvTimeo
430 			<li> osl_Socket_OptionError
431 			<li> osl_Socket_OptionType
432 			<li> osl_Socket_OptionTcpNoDelay
433 			</ul>
434 
435 			If not above mentioned otherwise, the options are only valid for
436 			level osl_Socket_LevelSocket.
437 
438 			@param pBuffer Pointer to a Buffer which contains the attribute-value.
439 
440 			@param BufferSize contains the length of the Buffer.
441 
442 			@param Level selects the level for which an option should be changed.
443 			Valid values are:
444 			<ul>
445 			<li> osl_Socket_evel_Socket : Socket Level
446 			<li> osl_Socket_Level_Tcp   : Level of Transmission Control Protocol
447 			</ul>
448 
449 			@return True if the option could be changed.
450 		*/
451 		inline sal_Bool SAL_CALL setOption( oslSocketOption Option,
452 											void* pBuffer,
453 											sal_uInt32 BufferLen,
454 											oslSocketOptionLevel Level= osl_Socket_LevelSocket ) const;
455 
456 		/** Convenience function for setting sal_Bool and sal_Int32 option values.
457 			@see setOption()
458 		 */
459 		inline sal_Bool setOption( oslSocketOption option, sal_Int32 nValue  );
460 
461 		/** Convenience function for retrieving sal_Bool and sal_Int32 option values.
462 			@see setOption()
463 		 */
464 		inline sal_Int32 getOption( oslSocketOption option ) const;
465 
466 		/** Enables/disables non-blocking mode of the socket.
467 			@param bNonBlockingMode If <code>sal_True</code>, blocking mode will be switched off
468 				   If <code>sal_False</code>, the socket will become a blocking
469 				   socket (which is the default behaviour of a socket).
470 			@return <code>sal_True</code> if mode could be set.
471 		*/
472 		inline sal_Bool SAL_CALL enableNonBlockingMode( sal_Bool bNonBlockingMode);
473 
474 		/** Query blocking mode of the socket.
475 			@return <code>sal_True</code> if non-blocking mode is set.
476 		*/
477 		inline sal_Bool SAL_CALL isNonBlockingMode() const;
478 
479 
480 		/** clears the error status
481 		*/
482 		inline void	SAL_CALL clearError() const;
483 
484         /** returns a constant decribing the last error for the socket system.
485 
486 			@return osl_Socket_E_NONE if no error occured, invalid_SocketError if
487 			an unknown (unmapped) error occured, otherwise an enum describing the
488 			error.
489 			@see osl_getLastSocketError()
490 		*/
491 		inline oslSocketError getError() const;
492 
493 		/** Builds a string with the last error-message for the socket.
494 		 */
495 		inline ::rtl::OUString getErrorAsString( ) const;
496 
497 		/** Returns the underlying handle unacquired  (The caller must acquire it to keep it).
498 		 */
499 		inline oslSocket getHandle() const;
500 	};
501 
502 
503 	class StreamSocket : public Socket
504 	{
505 	public:
506 		/** Creates a socket.
507 			@param Type For some protocols it might be desirable to
508 			use a different type than <code>osl_Socket_TypeStream</code>
509 			(like <code>osl_Socket_TypeSeqPacket</code>).
510 			Therefore this parameter is not hidden.
511 		*/
512   		inline StreamSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
513 							oslProtocol	Protocol = osl_Socket_ProtocolIp,
514 							oslSocketType	Type = osl_Socket_TypeStream);
515 
516 		inline StreamSocket( const StreamSocket & );
517 
518 		inline StreamSocket( oslSocket Socket , __sal_NoAcquire noacquire );
519 
520 		inline StreamSocket( oslSocket Socket );
521 
522 		/** Retrieves n bytes from the stream and copies them into pBuffer.
523 			The method avoids incomplete reads due to packet boundaries and is thus
524 			blocking.
525 			@param pBuffer receives the read data. pBuffer must be large enough
526 			to hold n bytes.
527 			@param n the number of bytes to read.
528 			@return	the number of read bytes. The number will only be smaller than
529 			n if an exceptional condition (e.g. connection closed) occurs.
530 		*/
531 		inline sal_Int32 SAL_CALL read(void* pBuffer, sal_uInt32 n);
532 
533 		/** Writes n bytes from pBuffer to the stream. The method avoids
534 			incomplete writes due to packet boundaries and is thus blocking.
535 			@param pBuffer contains the data to be written.
536 			@param n the number of bytes to write.
537 			@return the number of written bytes. The number will only be smaller than
538 			n if an exceptional condition (e.g. connection closed) occurs.
539 		*/
540 		inline sal_Int32 SAL_CALL write(const void* pBuffer, sal_uInt32 n);
541 
542 
543 		/** Tries to receive BytesToRead data from the connected socket,
544 
545 			@param pBuffer [out] Points to a buffer that will be filled with the received
546 			data. pBuffer must have at least have a size of BytesToRead.
547 			@param BytesToRead [in] The number of bytes to read.
548 			@param Flag [in] Modifier for the call. Valid values are:
549 
550 			<ul>
551 			<li><code>osl_Socket_MsgNormal</code>
552 			<li><code>osl_Socket_MsgOOB</code>
553 			<li><code>osl_Socket_MsgPeek</code>
554 			<li><code>osl_Socket_MsgDontRoute</code>
555 			<li><code>osl_Socket_MsgMaxIOVLen</code>
556 			</ul>
557 			@return the number of received bytes, which may be less than BytesToRead.
558 		*/
559 		inline sal_Int32 SAL_CALL recv(void* pBuffer,
560 									   sal_uInt32 BytesToRead,
561 									   oslSocketMsgFlag flags= osl_Socket_MsgNormal);
562 
563 		/** Tries to send BytesToSend data to the connected socket.
564 
565 			@param pBuffer [in] Points to a buffer that contains the send-data.
566 			@param BytesToSend [in] The number of bytes to send. pBuffer must have at least
567 			this size.
568 			@param Flag [in] Modifier for the call. Valid values are:
569 			<ul>
570 			<li><code>osl_Socket_MsgNormal</code>
571 			<li><code>osl_Socket_MsgOOB</code>
572 			<li><code>osl_Socket_MsgPeek</code>
573 			<li><code>osl_Socket_MsgDontRoute</code>
574 			<li><code>osl_Socket_MsgMaxIOVLen</code>
575 			</ul>
576 
577 			@return the number of transfered bytes. It may be less than BytesToSend.
578 		*/
579 		sal_Int32 SAL_CALL send(const void* pBuffer,
580 								sal_uInt32 BytesToSend,
581 								oslSocketMsgFlag= osl_Socket_MsgNormal);
582 	};
583 
584 	class ConnectorSocket : public StreamSocket
585 	{
586 	public:
587 		/** Creates a socket that can connect to a (remote) host.
588 			@param Type For some protocols it might be desirable to
589 			use a different type than sock_stream <code>osl_Socket_TypeSeqPacket</code>
590 			(like <code>osl_Socket_TypeSeqPacket</code>).
591 			Therefore we do not hide this parameter here.
592 		*/
593   		ConnectorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
594 						oslProtocol	Protocol = osl_Socket_ProtocolIp,
595 						oslSocketType	Type = osl_Socket_TypeStream);
596 
597 
598 		/** Connects the socket to a (remote) host.
599 			@param TargetHost The address of the target.
600 			@param pTimeOut The timeout for blocking. If 0, a default system dependent timeout
601 			                us used.
602 			@return <code> osl_Socket_Ok</code> if connected successfully,
603 			<code>osl_Socket_TimedOut</code> on timeout,
604 			<code>osl_Socket_Interrupted</code> if unblocked forcefully (by osl::Socket::close()),
605 			<code>osl_Socket_Error</code> if connect failed.
606 		*/
607 		oslSocketResult SAL_CALL connect(const SocketAddr& TargetHost, const TimeValue* pTimeout = 0);
608 	};
609 
610 	/** Allows to accept socket connections.
611 	 */
612 	class AcceptorSocket : public Socket
613 	{
614 	public:
615 		inline AcceptorSocket(oslAddrFamily Family = osl_Socket_FamilyInet,
616 							  oslProtocol	Protocol = osl_Socket_ProtocolIp,
617 							  oslSocketType	Type = osl_Socket_TypeStream);
618 
619 		/** Prepare a socket for the accept-call. The socket must have been
620 			bound before to the local address.
621 			@param MaxPendingConnections The maximum number of pending
622 			connections (waiting to be accepted) on this socket. If you use
623 			-1, a system default value is used.
624 			@return <code>sal_True</code> if call was successful.
625 		*/
626 		inline sal_Bool SAL_CALL listen(sal_Int32 MaxPendingConnections= -1);
627 
628 		/** Accepts incoming connections on the socket. You must
629 			precede this call with osl::Socket::bind() and listen().
630 			@param Connection receives the incoming connection.
631 			@return <code>osl_Socket_Ok</code>, if a connection has been accepted,
632 			<code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
633 			<code>osl_Socket_Error</code> on errors.
634 		*/
635 		inline oslSocketResult SAL_CALL acceptConnection( StreamSocket& Connection);
636 
637 		/** Accepts incoming connections on the socket. You must
638 			precede this call with osl::Socket::bind() and listen().
639 			@param PeerAddr receives the address of the connecting entity
640 			(your communication	partner).
641 			@param Connection receives the incoming connection.
642 			@return <code>osl_Socket_Ok</code>, if a connection has been accepted,
643 			<code>osl_Socket_TimedOut</code>, if m_RecvTimeout milliseconds passed without connect,
644 			<code>osl_Socket_Error</code> on errors.
645 		*/
646 		inline oslSocketResult SAL_CALL acceptConnection( StreamSocket&	Connection, SocketAddr & PeerAddr);
647 	};
648 
649 
650 
651     /** A connectionless socket to send and receive datagrams.
652 	 */
653 	class DatagramSocket : public Socket
654 	{
655 	public:
656 
657 		/** Creates a datagram socket.
658 			@param Type is sock_dgram by default.
659 		*/
660 		inline DatagramSocket(oslAddrFamily Family= osl_Socket_FamilyInet,
661 							  oslProtocol	Protocol= osl_Socket_ProtocolIp,
662 							  oslSocketType	Type= osl_Socket_TypeDgram);
663 
664 		/** Tries to receives BufferSize data from the socket, if no error occurs.
665 
666 			@param pSenderAddr [out] You must provide pointer to a SocketAddr.
667 			It will be	filled with the address of the datagrams sender.
668 			If pSenderAddr is 0, it is ignored.
669 			@param pBuffer [out] Points to a buffer that will be filled with the received
670 			datagram.
671 			@param BufferSize [in] The size of pBuffer.
672 			@param Flag [in] Modifier for the call. Valid values are:
673 			<ul>
674 			<li><code>osl_Socket_MsgNormal</code>
675 			<li><code>osl_Socket_MsgOOB</code>
676 			<li><code>osl_Socket_MsgPeek</code>
677 			<li><code>osl_Socket_MsgDontRoute</code>
678 			<li><code>osl_Socket_MsgMaxIOVLen</code>
679 			</ul>
680 
681 			@return the number of received bytes.
682 		*/
683 		inline sal_Int32 SAL_CALL recvFrom(void*  pBuffer,
684 										   sal_uInt32 BufferSize,
685 										   SocketAddr* pSenderAddr= 0,
686 										   oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
687 
688 		/** Tries to send one datagram with BytesToSend size to the given ReceiverAddr.
689 			Since there is only send one packet, the function doesn't care about
690 			packet boundaries.
691 
692 			@param ReceiverAddr [in] A SocketAddr that contains
693 			the destination address for this send.
694 
695 			@param pBuffer [in] Points to a buffer that contains the send-data.
696 			@param BufferSize [in] The number of bytes to send. pBuffer must have at least
697 			this size.
698 			@param Flag [in] Modifier for the call. Valid values are:
699 
700 			<ul>
701 			<li><code>osl_Socket_MsgNormal</code>
702 			<li><code>osl_Socket_MsgOOB</code>
703 			<li><code>osl_Socket_MsgPeek</code>
704 			<li><code>osl_Socket_MsgDontRoute</code>
705 			<li><code>osl_Socket_MsgMaxIOVLen</code>
706 			</ul>
707 
708 			@return the number of transfered bytes.
709 		*/
710 		inline sal_Int32	SAL_CALL sendTo( const SocketAddr& ReceiverAddr,
711 											 const void* pBuffer,
712 											 sal_uInt32 BufferSize,
713 											 oslSocketMsgFlag Flag= osl_Socket_MsgNormal);
714 	};
715 
716 }
717 
718 #endif
719