summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Network.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2017-09-20 11:05:13 +0200
committerJose <jose@zeroc.com>2017-09-20 11:05:13 +0200
commit7f0816001e085f482f8f9a34b7f8e06435907510 (patch)
tree46807f18b840e1c9816cd9b4aac001c8078d8bce /cpp/src/Ice/Network.cpp
parentFixed Ice/acm Java7 build failure (diff)
downloadice-7f0816001e085f482f8f9a34b7f8e06435907510.tar.bz2
ice-7f0816001e085f482f8f9a34b7f8e06435907510.tar.xz
ice-7f0816001e085f482f8f9a34b7f8e06435907510.zip
Clean C++ exception code to only throw exception types
- Update C++ code to only throw types derived from C++ exception - Update C++ code to use one-shot constructors to create the exceptions Fix bug ICE-7892
Diffstat (limited to 'cpp/src/Ice/Network.cpp')
-rwxr-xr-xcpp/src/Ice/Network.cpp234
1 files changed, 58 insertions, 176 deletions
diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp
index a4b6cc10c28..09508a02737 100755
--- a/cpp/src/Ice/Network.cpp
+++ b/cpp/src/Ice/Network.cpp
@@ -153,9 +153,7 @@ setTcpNoDelay(SOCKET fd)
if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -166,9 +164,7 @@ setKeepAlive(SOCKET fd)
if(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -189,9 +185,7 @@ setTcpLoopbackFastPath(SOCKET fd)
if(LastError != WSAEOPNOTSUPP)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -233,9 +227,7 @@ createSocketImpl(bool udp, int family)
if(fd == INVALID_SOCKET)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
if(!udp)
@@ -325,9 +317,7 @@ getLocalAddresses(ProtocolSupport protocol, bool includeLoopback)
struct ifaddrs* ifap;
if(::getifaddrs(&ifap) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
struct ifaddrs* curr = ifap;
@@ -394,9 +384,7 @@ getLocalAddresses(ProtocolSupport protocol, bool includeLoopback)
{
free(ifc.ifc_buf);
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketError());
}
else if(ifc.ifc_len == old_ifc_len)
{
@@ -832,9 +820,7 @@ IceInternal::NativeInfo::completed(SocketOperation operation)
{
if(!PostQueuedCompletionStatus(_handle, 0, _key, getAsyncInfo(operation)))
{
- Ice::SocketException ex(__FILE__, __LINE__);
- ex.error = GetLastError();
- throw ex;
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
}
}
@@ -1059,10 +1045,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport, Ice::En
}
catch(Platform::Exception^ pex)
{
- DNSException ex(__FILE__, __LINE__);
- ex.error = (int)SocketError::GetStatus(pex->HResult);
- ex.host = host;
- throw ex;
+ throw DNSException(__FILE__, __LINE__, (int)SocketError::GetStatus(pex->HResult), host);
}
}
@@ -1143,10 +1126,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
}
else if(rs != 0)
{
- DNSException ex(__FILE__, __LINE__);
- ex.error = rs;
- ex.host = host;
- throw ex;
+ throw DNSException(__FILE__, __LINE__, rs, host);
}
for(struct addrinfo* p = info; p != ICE_NULLPTR; p = p->ai_next)
@@ -1180,9 +1160,7 @@ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol
if(result.empty())
{
- DNSException ex(__FILE__, __LINE__);
- ex.host = host;
- throw ex;
+ throw DNSException(__FILE__, __LINE__, 0, host);
}
sortAddresses(result, protocol, selType, preferIPv6);
return result;
@@ -1376,9 +1354,7 @@ IceInternal::createServerSocket(bool udp, const Address& addr, ProtocolSupport p
}
#endif
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
return fd;
@@ -1430,9 +1406,7 @@ IceInternal::closeSocket(SOCKET fd)
int error = WSAGetLastError();
if(closesocket(fd) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
WSASetLastError(error);
#else
@@ -1449,9 +1423,7 @@ IceInternal::closeSocket(SOCKET fd)
if(close(fd) == SOCKET_ERROR)
# endif
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
errno = error;
#endif
@@ -1472,9 +1444,7 @@ IceInternal::fdToLocalAddress(SOCKET fd, Address& addr)
socklen_t len = static_cast<socklen_t>(sizeof(sockaddr_storage));
if(getsockname(fd, &addr.sa, &len) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
#else
StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
@@ -1505,9 +1475,7 @@ IceInternal::fdToRemoteAddress(SOCKET fd, Address& addr)
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -1958,9 +1926,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(ioctlsocket(fd, FIONBIO, &arg) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = WSAGetLastError();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, WSAGetLastError());
}
}
else
@@ -1969,9 +1935,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(ioctlsocket(fd, FIONBIO, &arg) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = WSAGetLastError();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, WSAGetLastError());
}
}
#else
@@ -1982,9 +1946,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(fcntl(fd, F_SETFL, flags) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = errno;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, errno);
}
}
else
@@ -1994,9 +1956,7 @@ IceInternal::setBlock(SOCKET fd, bool block)
if(fcntl(fd, F_SETFL, flags) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = errno;
- throw ex;
+ throw SocketException(__FILE__, __LINE__, errno);
}
}
#endif
@@ -2010,9 +1970,7 @@ IceInternal::setSendBufferSize(SOCKET fd, int sz)
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&sz), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
#else
StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
@@ -2033,9 +1991,7 @@ IceInternal::getSendBufferSize(SOCKET fd)
static_cast<unsigned int>(len) != sizeof(sz))
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
return sz;
#else
@@ -2060,9 +2016,7 @@ IceInternal::setRecvBufferSize(SOCKET fd, int sz)
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&sz), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2077,9 +2031,7 @@ IceInternal::getRecvBufferSize(SOCKET fd)
static_cast<unsigned int>(len) != sizeof(sz))
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
return sz;
#else
@@ -2118,9 +2070,7 @@ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string& intf)
if(rc == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -2190,9 +2140,7 @@ IceInternal::setMcastInterface(SOCKET fd, const string& intf, const Address& add
if(rc == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2218,9 +2166,7 @@ IceInternal::setMcastTtl(SOCKET fd, int ttl, const Address& addr)
if(rc == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2238,9 +2184,7 @@ IceInternal::setReuseAddress(SOCKET fd, bool reuse)
if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif
@@ -2365,9 +2309,7 @@ IceInternal::doBind(SOCKET fd, const Address& addr, const string&)
if(::bind(fd, &addr.sa, size) == SOCKET_ERROR)
{
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
Address local;
@@ -2570,9 +2512,7 @@ repeatListen:
}
closeSocketNoThrow(fd);
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -2603,21 +2543,15 @@ repeatConnect:
closeSocketNoThrow(fd);
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -2633,9 +2567,7 @@ repeatConnect:
fdToLocalAddress(fd, localAddr);
if(compareAddress(addr, localAddr) == 0)
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = 0; // No appropriate errno
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, 0); // No appropriate errno
}
}
catch(const LocalException&)
@@ -2668,9 +2600,7 @@ IceInternal::doFinishConnect(SOCKET fd)
socklen_t len = static_cast<socklen_t>(sizeof(int));
if(getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&val), &len) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
if(val > 0)
@@ -2682,21 +2612,15 @@ IceInternal::doFinishConnect(SOCKET fd)
#endif
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
@@ -2711,9 +2635,7 @@ IceInternal::doFinishConnect(SOCKET fd)
Address remoteAddr;
if(fdToRemoteAddress(fd, remoteAddr) && compareAddress(remoteAddr, localAddr) == 0)
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = 0; // No appropriate errno
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, 0); // No appropriate errno
}
#endif
}
@@ -2735,9 +2657,7 @@ repeatAccept:
goto repeatAccept;
}
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
setTcpNoDelay(ret);
@@ -2818,9 +2738,7 @@ IceInternal::createPipe(SOCKET fds[2])
if(::pipe(fds) != 0)
{
- SyscallException ex(__FILE__, __LINE__);
- ex.error = getSystemErrno();
- throw ex;
+ throw SyscallException(__FILE__, __LINE__, getSocketErrno());
}
try
@@ -2855,16 +2773,12 @@ IceInternal::checkConnectErrorCode(const char* file, int line, HRESULT herr)
{
if(herr == E_ACCESSDENIED)
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(herr);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(herr));
}
SocketErrorStatus error = SocketError::GetStatus(herr);
if(error == SocketErrorStatus::ConnectionRefused)
{
- ConnectionRefusedException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw ConnectionRefusedException(file, line, static_cast<int>(error));
}
else if(error == SocketErrorStatus::NetworkDroppedConnectionOnReset ||
error == SocketErrorStatus::ConnectionTimedOut ||
@@ -2873,21 +2787,15 @@ IceInternal::checkConnectErrorCode(const char* file, int line, HRESULT herr)
error == SocketErrorStatus::ConnectionResetByPeer ||
error == SocketErrorStatus::SoftwareCausedConnectionAbort)
{
- ConnectFailedException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw ConnectFailedException(file, line, static_cast<int>(error));
}
else if(error == SocketErrorStatus::HostNotFound)
{
- DNSException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw DNSException(file, line, static_cast<int>(error), "");
}
else
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(error));
}
}
@@ -2896,30 +2804,22 @@ IceInternal::checkErrorCode(const char* file, int line, HRESULT herr)
{
if(herr == E_ACCESSDENIED)
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(herr);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(herr));
}
SocketErrorStatus error = SocketError::GetStatus(herr);
if(error == SocketErrorStatus::NetworkDroppedConnectionOnReset ||
error == SocketErrorStatus::SoftwareCausedConnectionAbort ||
error == SocketErrorStatus::ConnectionResetByPeer)
{
- ConnectionLostException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw ConnectionLostException(file, line, static_cast<int>(error));
}
else if(error == SocketErrorStatus::HostNotFound)
{
- DNSException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw DNSException(file, line, static_cast<int>(error), "");
}
else
{
- SocketException ex(file, line);
- ex.error = static_cast<int>(error);
- throw ex;
+ throw SocketException(file, line, static_cast<int>(error));
}
}
@@ -2989,9 +2889,7 @@ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourc
if(::bind(fd, &bindAddr.sa, size) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
LPFN_CONNECTEX ConnectEx = ICE_NULLPTR; // a pointer to the 'ConnectEx()' function
@@ -3007,9 +2905,7 @@ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourc
ICE_NULLPTR,
ICE_NULLPTR) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
if(!ConnectEx(fd, &addr.sa, size, 0, 0, 0, &info))
@@ -3018,21 +2914,15 @@ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourc
{
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
}
@@ -3051,29 +2941,21 @@ IceInternal::doFinishConnectAsync(SOCKET fd, AsyncInfo& info)
WSASetLastError(info.error);
if(connectionRefused())
{
- ConnectionRefusedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectionRefusedException(__FILE__, __LINE__, getSocketErrno());
}
else if(connectFailed())
{
- ConnectFailedException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw ConnectFailedException(__FILE__, __LINE__, getSocketErrno());
}
else
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
if(setsockopt(fd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, ICE_NULLPTR, 0) == SOCKET_ERROR)
{
- SocketException ex(__FILE__, __LINE__);
- ex.error = getSocketErrno();
- throw ex;
+ throw SocketException(__FILE__, __LINE__, getSocketErrno());
}
}
#endif