summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2008-02-07 16:49:30 +0100
committerBenoit Foucher <benoit@zeroc.com>2008-02-07 16:49:30 +0100
commitc8f810cae2c49c45bb771974321cc702401d3464 (patch)
tree39eecd100ff09f3b56fe87e7f7ee1617fd56292d /cpp/src
parentAdded expect script for casino demo (diff)
downloadice-c8f810cae2c49c45bb771974321cc702401d3464.tar.bz2
ice-c8f810cae2c49c45bb771974321cc702401d3464.tar.xz
ice-c8f810cae2c49c45bb771974321cc702401d3464.zip
Fixed bug 2662
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/Network.cpp88
-rw-r--r--cpp/src/Ice/UdpTransceiver.cpp40
2 files changed, 72 insertions, 56 deletions
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index 749b5683e27..ce9bbec5a08 100644
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -11,10 +11,18 @@
// The following is required on HP-UX in order to bring in
// the definition for the ip_mreq structure.
//
-#ifdef __hpux
-#undef _XOPEN_SOURCE_EXTENDED
-#define _XOPEN_SOURCE
-#include <netinet/in.h>
+#if defined(__hpux)
+# undef _XOPEN_SOURCE_EXTENDED
+# define _XOPEN_SOURCE
+# include <netinet/in.h>
+#endif
+
+//
+// The following is required for the Vista PSDK to bring in
+// the definitions of the IN6_IS_ADDR_* macros.
+//
+#if defined(_WIN32) && !defined(NTDDI_VERSION)
+# define NTDDI_VERSION NTDDI_WIN2KSP1
#endif
#include <IceUtil/StringUtil.h>
@@ -68,7 +76,7 @@ getLocalAddresses(ProtocolSupport protocol)
vector<unsigned char> buffer;
buffer.resize(1024);
unsigned long len = 0;
- DWORD rs = WSAIoctl(fd, SIO_ADDRESS_LIST_QUERY, 0, 0,
+ DWORD rs = WSAIoctl(fd, SIO_ADDRESS_LIST_QUERY, 0, 0,
&buffer[0], static_cast<DWORD>(buffer.size()),
&len, 0, 0);
if(rs == SOCKET_ERROR)
@@ -80,7 +88,7 @@ getLocalAddresses(ProtocolSupport protocol)
if(getSocketErrno() == WSAEFAULT)
{
buffer.resize(len);
- rs = WSAIoctl(fd, SIO_ADDRESS_LIST_QUERY, 0, 0,
+ rs = WSAIoctl(fd, SIO_ADDRESS_LIST_QUERY, 0, 0,
&buffer[0], static_cast<DWORD>(buffer.size()),
&len, 0, 0);
}
@@ -94,7 +102,7 @@ getLocalAddresses(ProtocolSupport protocol)
}
}
- //
+ //
// Add the local interface addresses.
//
SOCKET_ADDRESS_LIST* addrs = reinterpret_cast<SOCKET_ADDRESS_LIST*>(&buffer[0]);
@@ -161,7 +169,7 @@ getLocalAddresses(ProtocolSupport protocol)
}
}
}
-
+
curr = curr->ifa_next;
}
@@ -195,7 +203,7 @@ getLocalAddresses(ProtocolSupport protocol)
int bufsize = numaddrs * static_cast<int>(sizeof(struct ifreq));
ifc.ifc_len = bufsize;
ifc.ifc_buf = (char*)malloc(bufsize);
-
+
int rs = ioctl(fd, cmd, &ifc);
if(rs == SOCKET_ERROR)
{
@@ -216,7 +224,7 @@ getLocalAddresses(ProtocolSupport protocol)
{
old_ifc_len = ifc.ifc_len;
}
-
+
numaddrs += 10;
free(ifc.ifc_buf);
}
@@ -262,11 +270,11 @@ getAddressImpl(const string& host, int port, struct sockaddr_storage& addr, Prot
// We now use getaddrinfo() on Windows.
//
// #ifdef _WIN32
-
+
// //
// // Windows XP has getaddrinfo(), but we don't want to require XP to run Ice.
// //
-
+
// //
// // gethostbyname() is thread safe on Windows, with a separate hostent per thread
// //
@@ -277,7 +285,7 @@ getAddressImpl(const string& host, int port, struct sockaddr_storage& addr, Prot
// entry = gethostbyname(host.c_str());
// }
// while(entry == 0 && WSAGetLastError() == WSATRY_AGAIN && --retry >= 0);
-
+
// if(entry == 0)
// {
// DNSException ex(__FILE__, __LINE__);
@@ -293,7 +301,7 @@ getAddressImpl(const string& host, int port, struct sockaddr_storage& addr, Prot
memset(&addr, 0, sizeof(struct sockaddr_storage));
struct addrinfo* info = 0;
int retry = 5;
-
+
struct addrinfo hints = { 0 };
if(server)
@@ -301,7 +309,7 @@ getAddressImpl(const string& host, int port, struct sockaddr_storage& addr, Prot
//
// If host is empty, getaddrinfo will return the wildcard
// address instead of the loopack address.
- //
+ //
hints.ai_flags |= AI_PASSIVE;
}
@@ -327,11 +335,11 @@ getAddressImpl(const string& host, int port, struct sockaddr_storage& addr, Prot
}
else
{
- rs = getaddrinfo(host.c_str(), 0, &hints, &info);
+ rs = getaddrinfo(host.c_str(), 0, &hints, &info);
}
}
while(info == 0 && rs == EAI_AGAIN && --retry >= 0);
-
+
if(rs != 0)
{
DNSException ex(__FILE__, __LINE__);
@@ -609,7 +617,7 @@ IceInternal::closeSocketNoThrow(SOCKET fd)
errno = error;
#endif
}
-
+
void
IceInternal::shutdownSocketWrite(SOCKET fd)
{
@@ -645,7 +653,7 @@ IceInternal::shutdownSocketWrite(SOCKET fd)
throw ex;
}
}
-
+
void
IceInternal::shutdownSocketReadWrite(SOCKET fd)
{
@@ -682,7 +690,7 @@ IceInternal::shutdownSocketReadWrite(SOCKET fd)
throw ex;
}
}
-
+
void
IceInternal::setBlock(SOCKET fd, bool block)
{
@@ -746,7 +754,7 @@ IceInternal::setTcpNoDelay(SOCKET fd)
throw ex;
}
}
-
+
void
IceInternal::setKeepAlive(SOCKET fd)
{
@@ -958,7 +966,7 @@ repeatListen:
{
goto repeatListen;
}
-
+
closeSocketNoThrow(fd);
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
@@ -991,7 +999,7 @@ repeatConnect:
{
goto repeatConnect;
}
-
+
if(connectInProgress())
{
if(timeout == 0)
@@ -1010,7 +1018,7 @@ repeatConnect:
}
return true;
}
-
+
closeSocketNoThrow(fd);
if(connectionRefused())
{
@@ -1097,7 +1105,7 @@ IceInternal::doFinishConnect(SOCKET fd, int timeout)
{
goto repeatSelect;
}
-
+
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;
@@ -1121,7 +1129,7 @@ IceInternal::doFinishConnect(SOCKET fd, int timeout)
ex.error = getSocketErrno();
throw ex;
}
-
+
if(val > 0)
{
#ifdef _WIN32
@@ -1209,27 +1217,27 @@ repeatAccept:
pollFd[0].events = POLLIN;
rs = ::poll(pollFd, 1, timeout);
#endif
-
+
if(rs == SOCKET_ERROR)
{
if(interrupted())
{
goto repeatSelect;
}
-
+
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;
}
-
+
if(rs == 0)
{
throw TimeoutException(__FILE__, __LINE__);
}
-
+
goto repeatAccept;
}
-
+
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;
@@ -1262,7 +1270,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
// //
// // Windows XP has getaddrinfo(), but we don't want to require XP to run Ice.
// //
-
+
// //
// // gethostbyname() is thread safe on Windows, with a separate hostent per thread
// //
@@ -1274,7 +1282,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
// entry = gethostbyname(host.c_str());
// }
// while(entry == 0 && h_errno == TRY_AGAIN && --retry >= 0);
-
+
// if(entry == 0)
// {
// DNSException ex(__FILE__, __LINE__);
@@ -1289,7 +1297,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
// memcpy(&addr.sin_addr, *p, entry->h_length);
// result.push_back(addr);
// p++;
-// }
+// }
// #else
@@ -1318,7 +1326,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
{
hints.ai_flags = AI_NUMERICHOST;
}
-
+
int rs = 0;
do
{
@@ -1435,7 +1443,7 @@ IceInternal::compareAddress(const struct sockaddr_storage& addr1, const struct s
{
return 1;
}
-
+
int res = memcmp(&addr1in->sin6_addr, &addr2in->sin6_addr, sizeof(struct in6_addr));
if(res < 0)
{
@@ -1457,7 +1465,7 @@ IceInternal::createPipe(SOCKET fds[2])
SOCKET fd = createSocket(false, AF_INET);
setBlock(fd, true);
-
+
struct sockaddr_storage addr;
memset(&addr, 0, sizeof(addr));
@@ -1465,7 +1473,7 @@ IceInternal::createPipe(SOCKET fds[2])
addrin->sin_family = AF_INET;
addrin->sin_port = htons(0);
addrin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-
+
doBind(fd, addr);
doListen(fd, 1);
@@ -1694,10 +1702,10 @@ IceInternal::getHostsForEndpointExpand(const string& host, ProtocolSupport proto
for(vector<struct sockaddr_storage>::const_iterator p = addrs.begin(); p != addrs.end(); ++p)
{
//
- // NOTE: We don't publish link-local IPv6 addresses as these addresses can only
+ // NOTE: We don't publish link-local IPv6 addresses as these addresses can only
// be accessed in general with a scope-id.
//
- if(p->ss_family != AF_INET6 ||
+ if(p->ss_family != AF_INET6 ||
!IN6_IS_ADDR_LINKLOCAL(&reinterpret_cast<const struct sockaddr_in6*>(&(*p))->sin6_addr))
{
hosts.push_back(inetAddrToString(*p));
diff --git a/cpp/src/Ice/UdpTransceiver.cpp b/cpp/src/Ice/UdpTransceiver.cpp
index 4d2b904c185..05ff09dec7c 100644
--- a/cpp/src/Ice/UdpTransceiver.cpp
+++ b/cpp/src/Ice/UdpTransceiver.cpp
@@ -7,6 +7,14 @@
//
// **********************************************************************
+//
+// The following is required for the Vista PSDK to bring in
+// the definitions of the IN6_IS_ADDR_* macros.
+//
+#if defined(_WIN32) && !defined(NTDDI_VERSION)
+# define NTDDI_VERSION NTDDI_WIN2KSP1
+#endif
+
#include <Ice/UdpTransceiver.h>
#include <Ice/Instance.h>
#include <Ice/TraceLevels.h>
@@ -131,7 +139,7 @@ repeat:
ssize_t ret = ::send(_fd, reinterpret_cast<const char*>(&buf.b[0]), static_cast<int>(buf.b.size()), 0);
#else
ssize_t ret = ::send(_fd, reinterpret_cast<const char*>(&buf.b[0]), buf.b.size(), 0);
-#endif
+#endif
if(ret == SOCKET_ERROR)
{
@@ -153,7 +161,7 @@ repeat:
assert(_fd != INVALID_SOCKET);
#ifdef _WIN32
FD_SET(_fd, &_wFdSet);
-
+
if(timeout >= 0)
{
struct timeval tv;
@@ -170,14 +178,14 @@ repeat:
pollFd[0].fd = _fd;
pollFd[0].events = POLLOUT;
rs = ::poll(pollFd, 1, timeout);
-#endif
+#endif
if(rs == SOCKET_ERROR)
{
if(interrupted())
{
goto repeatSelect;
}
-
+
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;
@@ -187,10 +195,10 @@ repeat:
{
throw new Ice::TimeoutException(__FILE__, __LINE__);
}
-
+
goto repeat;
}
-
+
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;
@@ -201,7 +209,7 @@ repeat:
Trace out(_logger, _traceLevels->networkCat);
out << "sent " << ret << " bytes via udp\n" << toString();
}
-
+
if(_stats)
{
_stats->bytesSent(type(), static_cast<Int>(ret));
@@ -289,7 +297,7 @@ repeat:
{
goto repeat;
}
-
+
if(wouldBlock())
{
if(timeout == 0)
@@ -298,7 +306,7 @@ repeat:
}
repeatSelect:
-
+
assert(_fd != INVALID_SOCKET);
#ifdef _WIN32
FD_SET(_fd, &_rFdSet);
@@ -316,12 +324,12 @@ repeat:
{
goto repeatSelect;
}
-
+
SocketException ex(__FILE__, __LINE__);
ex.error = getSocketErrno();
throw ex;
}
-
+
if(rs == 0)
{
throw TimeoutException(__FILE__, __LINE__);
@@ -346,7 +354,7 @@ repeat:
ex.error = getSocketErrno();
throw ex;
}
-
+
if(_traceLevels->network >= 3)
{
Trace out(_logger, _traceLevels->networkCat);
@@ -454,7 +462,7 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
setMcastTtl(_fd, mcastTtl, _addr.ss_family == AF_INET);
}
}
-
+
if(_traceLevels->network >= 1)
{
Trace out(_logger, _traceLevels->networkCat);
@@ -473,7 +481,7 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
#endif
}
-IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const string& host, int port,
+IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const string& host, int port,
const string& mcastInterface, bool connect) :
_traceLevels(instance->traceLevels()),
_logger(instance->initializationData().logger),
@@ -545,7 +553,7 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
#endif
doBind(_fd, _addr);
}
-
+
if(_traceLevels->network >= 1)
{
Trace out(_logger, _traceLevels->networkCat);
@@ -567,7 +575,7 @@ IceInternal::UdpTransceiver::UdpTransceiver(const InstancePtr& instance, const s
IceInternal::UdpTransceiver::~UdpTransceiver()
{
assert(_fd == INVALID_SOCKET);
-}
+}
//
// Set UDP receive and send buffer sizes.