1 karl 1.18 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.17 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.14 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.17 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.18 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.2 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.4 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 //
|
19 kumpf 1.4 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.4 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
|
32 joyce.j 1.19 // Modified By: Josephine Eskaline Joyce, IBM (jojustin@in.ibm.com) for Bug#2513
|
33 mike 1.2 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 #include "Socket.h"
37
38 #ifdef PEGASUS_OS_TYPE_WINDOWS
|
39 tony 1.9 #include <windows.h>
40 # ifndef _WINSOCKAPI_
41 # include <winsock2.h>
42 # endif
|
43 mike 1.2 #else
44 # include <cctype>
|
45 chuck 1.5 #ifndef PEGASUS_OS_OS400
46 # include <unistd.h>
47 #else
48 # include <unistd.cleinc>
49 #endif
|
50 marek 1.7 # include <string.h> // added by rk for memcpy
|
51 mike 1.2 # include <cstdlib>
52 # include <errno.h>
53 # include <fcntl.h>
54 # include <netdb.h>
55 # include <netinet/in.h>
56 # include <arpa/inet.h>
57 # include <sys/socket.h>
|
58 mday 1.11 # include <errno.h>
|
59 mike 1.2 #endif
60
|
61 mday 1.11 #include <Pegasus/Common/Sharable.h>
|
62 mike 1.2 PEGASUS_NAMESPACE_BEGIN
63
64 static Uint32 _socketInterfaceRefCount = 0;
65
66 Sint32 Socket::read(Sint32 socket, void* ptr, Uint32 size)
67 {
68 #ifdef PEGASUS_OS_TYPE_WINDOWS
69 return ::recv(socket, (char*)ptr, size, 0);
70 #else
|
71 konrad.r 1.16 #if defined (__GNUC__) && !defined(PEGASUS_OS_SOLARIS) && !defined(PEGASUS_OS_DARWIN) && !defined(PEGASUS_OS_LSB)
|
72 mday 1.11 int ccode = TEMP_FAILURE_RETRY(::read(socket, (char*)ptr, size));
73 return ccode;
74 #else
|
75 mike 1.2 return ::read(socket, (char*)ptr, size);
76 #endif
|
77 mday 1.11 #endif
|
78 mike 1.2 }
79
80 Sint32 Socket::write(Sint32 socket, const void* ptr, Uint32 size)
81 {
82 #ifdef PEGASUS_OS_TYPE_WINDOWS
83 return ::send(socket, (const char*)ptr, size, 0);
84 #else
|
85 konrad.r 1.16 #if (__GNUC__) && !defined(PEGASUS_OS_SOLARIS) && !defined(PEGASUS_OS_DARWIN) && !defined(PEGASUS_OS_LSB)
|
86 mday 1.11 int ccode = TEMP_FAILURE_RETRY(::write(socket, (char*)ptr, size));
87 return ccode;
88 #else
|
89 mike 1.2 return ::write(socket, (char*)ptr, size);
90 #endif
|
91 mday 1.11 #endif
|
92 mike 1.2 }
93
94 void Socket::close(Sint32 socket)
95 {
|
96 joyce.j 1.19 if(-1 != socket)
97 {
98 #ifdef PEGASUS_OS_TYPE_WINDOWS
99 if(!closesocket(socket)) socket=-1;
100 #else
101 #if (__GNUC__) && !defined(PEGASUS_OS_SOLARIS) && !defined(PEGASUS_OS_DARWIN) && !defined(PEGASUS_OS_LSB)
102 if(!TEMP_FAILURE_RETRY(::close(socket))) socket = -1;
103 #else
104 if(!::close(socket)) socket = -1;
105 #endif
106 #endif
107 }
|
108 mike 1.2 }
109
|
110 mday 1.11 int Socket::close2(Sint32 socket)
111 {
112 #ifdef PEGASUS_OS_TYPE_WINDOWS
113 return closesocket(socket);
114 #else
|
115 konrad.r 1.16 #if (__GNUC__) && !defined(PEGASUS_OS_SOLARIS) && !defined(PEGASUS_OS_DARWIN) && !defined(PEGASUS_OS_LSB)
|
116 mday 1.11 int ccode = TEMP_FAILURE_RETRY(::close(socket));
117 return ccode;
118 #else
119 return ::close(socket);
120 #endif
121 #endif
122 }
123
124
|
125 mike 1.2 void Socket::enableBlocking(Sint32 socket)
126 {
127 #ifdef PEGASUS_OS_TYPE_WINDOWS
128 unsigned long flag = 0;
129 ioctlsocket(socket, FIONBIO, &flag);
130 #else
131 int flags = fcntl(socket, F_GETFL, 0);
132 flags &= ~O_NONBLOCK;
133 fcntl(socket, F_SETFL, flags);
134 #endif
135 }
136
|
137 mday 1.11 int Socket::enableBlocking2(Sint32 socket)
138 {
139 #ifdef PEGASUS_OS_TYPE_WINDOWS
140 unsigned long flag = 0;
141 return ioctlsocket(socket, FIONBIO, &flag);
142 #else
143 int flags = fcntl(socket, F_GETFL, 0);
144 flags &= ~O_NONBLOCK;
145 return fcntl(socket, F_SETFL, flags);
146 #endif
147 }
148
|
149 mike 1.2 void Socket::disableBlocking(Sint32 socket)
150 {
151 #ifdef PEGASUS_OS_TYPE_WINDOWS
152 unsigned long flag = 1;
153 ioctlsocket(socket, FIONBIO, &flag);
154 #else
155 int flags = fcntl(socket, F_GETFL, 0);
156 flags |= O_NONBLOCK;
157 fcntl(socket, F_SETFL, flags);
158 #endif
159 }
160
|
161 mday 1.11 int Socket::disableBlocking2(Sint32 socket)
162 {
163 #ifdef PEGASUS_OS_TYPE_WINDOWS
164 unsigned long flag = 1;
165 return ioctlsocket(socket, FIONBIO, &flag);
166 #else
167 int flags = fcntl(socket, F_GETFL, 0);
168 flags |= O_NONBLOCK;
169 return fcntl(socket, F_SETFL, flags);
170 #endif
171 }
172
|
173 mike 1.2 void Socket::initializeInterface()
174 {
175 #ifdef PEGASUS_OS_TYPE_WINDOWS
176 if (_socketInterfaceRefCount == 0)
177 {
178 WSADATA tmp;
179
180 if (WSAStartup(0x202, &tmp) == SOCKET_ERROR)
181 WSACleanup();
182 }
183
184 _socketInterfaceRefCount++;
185 #endif
186 }
187
188 void Socket::uninitializeInterface()
189 {
190 #ifdef PEGASUS_OS_TYPE_WINDOWS
191 _socketInterfaceRefCount--;
192
193 if (_socketInterfaceRefCount == 0)
194 mike 1.2 WSACleanup();
195 #endif
196 }
197
|
198 mday 1.11
|
199 mike 1.2 PEGASUS_NAMESPACE_END
|
200 mday 1.11
|