1 martin 1.26 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.27 //
|
3 martin 1.26 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.27 //
|
10 martin 1.26 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.27 //
|
17 martin 1.26 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.27 //
|
20 martin 1.26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.27 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.27 //
|
28 martin 1.26 //////////////////////////////////////////////////////////////////////////
|
29 mike 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #ifndef Pegasus_Socket_h
33 #define Pegasus_Socket_h
34
|
35 mike 1.17 #include <cctype>
|
36 mike 1.18 #include <Pegasus/Common/Network.h>
|
37 mike 1.2 #include <Pegasus/Common/Config.h>
|
38 mike 1.17 #include <Pegasus/Common/Linkage.h>
39
|
40 mday 1.6 #ifdef PEGASUS_OS_ZOS
41 # include <string.h> // added by rk for memcpy
42 #endif
|
43 mike 1.2
44 PEGASUS_NAMESPACE_BEGIN
45
|
46 mike 1.16 class Socket
|
47 mike 1.2 {
|
48 mike 1.17 public:
|
49 mike 1.2
|
50 kumpf 1.24 /**
51 Connects the specified socket to the specified address. If the socket
52 is non-blocking, the connect attempt will time out after the specified
53 interval.
54
55 @param socket The socket to connect.
56 @param address The address to which to connect the socket
57 @param addressLength The length of the sockaddr buffer in which the
58 address is specified.
59 @param timeoutMilliseconds The number of milliseconds after which the
60 connect attempt should time out, if the socket is non-blocking.
61 @return True if the connect attempt is successful, false otherwise.
62 */
63 static Boolean timedConnect(
64 SocketHandle socket,
65 sockaddr* address,
66 int addressLength,
67 Uint32 timeoutMilliseconds);
68
|
69 mike 1.17 static Sint32 read(SocketHandle socket, void* ptr, Uint32 size);
|
70 david.dillard 1.12
|
71 mike 1.17 static Sint32 write(SocketHandle socket, const void* ptr, Uint32 size);
|
72 mike 1.2
|
73 marek 1.19 static Sint32 timedWrite(SocketHandle socket,
74 const void* ptr,
75 Uint32 size,
76 Uint32 socketWriteTimeout);
77
|
78 kumpf 1.25 /**
79 Closes a specified socket. If successful, the socket handle is set to
80 PEGASUS_INVALID_SOCKET.
81 @param socket The SocketHandle to close.
82 */
83 static void close(SocketHandle& socket);
|
84 mike 1.2
|
85 mike 1.17 static void disableBlocking(SocketHandle socket);
|
86 mike 1.2
|
87 mike 1.17 static void initializeInterface();
|
88 david.dillard 1.12
|
89 mike 1.17 static void uninitializeInterface();
|
90 mike 1.2
|
91 thilo.boehm 1.21 static SocketHandle createSocket(int domain, int type, int protocol);
92
|
93 mike 1.17 private:
94 Socket();
|
95 mday 1.6 };
|
96 mike 1.2
|
97 kumpf 1.25 // Use with AutoPtr to automatically close a socket on error
98 struct CloseSocketHandle
99 {
100 void operator()(SocketHandle* ptr)
101 {
102 if (ptr)
103 {
104 Socket::close(*ptr);
105 }
106 }
107 };
108
|
109 mike 1.2 PEGASUS_NAMESPACE_END
110
111 #endif /* Pegasus_Socket_h */
|