mirror of https://gitee.com/bigwinds/arangodb
issue 389.1: ensure GeneralClientConnection socket is valid for MSVC (#5328)
This commit is contained in:
parent
1c1d8f2528
commit
b13a8da1ce
|
@ -83,11 +83,41 @@ int EndpointMock::port() const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
GeneralClientConnectionMock::GeneralClientConnectionMock()
|
||||
: GeneralClientConnection(&endpoint, 0, 0, 0),
|
||||
nil(file_open((const file_path_t)nullptr, "rw")) {
|
||||
_socket.fileDescriptor = file_no(nil.get()); // must be a readable/writable descriptor
|
||||
}
|
||||
#else
|
||||
GeneralClientConnectionMock::GeneralClientConnectionMock()
|
||||
: GeneralClientConnection(&endpoint, 0, 0, 0) {
|
||||
struct sockaddr_in addr;
|
||||
auto size = (int)sizeof(addr);
|
||||
auto sock = socket(AF_INET, SOCK_DGRAM, 0); // should not return INVALID_SOCKET
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
inet_pton(addr.sin_family, "127.0.0.1", &addr.sin_addr);
|
||||
addr.sin_port = 0;
|
||||
sock = socket(AF_INET, SOCK_DGRAM, 0); // should not return INVALID_SOCKET
|
||||
bind(sock, (const struct sockaddr*)&addr, size); // should return 0
|
||||
memset(&addr, 0, size);
|
||||
getsockname(sock, (struct sockaddr*)&addr, &size); // should return 0
|
||||
|
||||
// make sure something in the socket
|
||||
sendto(sock, "", 0, 0, (const struct sockaddr*)&addr, size); // should not return SOCKET_ERROR
|
||||
|
||||
_socket.fileHandle = sock; // must be a readable/writable descriptor
|
||||
}
|
||||
#endif
|
||||
|
||||
GeneralClientConnectionMock::~GeneralClientConnectionMock() {
|
||||
#ifdef _WIN32
|
||||
if (INVALID_SOCKET != _socket.fileHandle) {
|
||||
closesocket(_socket.fileHandle);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GeneralClientConnectionMock::connectSocket() {
|
||||
_isConnected = true;
|
||||
|
|
|
@ -77,9 +77,13 @@ class GeneralClientConnectionMock
|
|||
: public arangodb::httpclient::GeneralClientConnection {
|
||||
public:
|
||||
EndpointMock endpoint;
|
||||
|
||||
#ifndef _WIN32
|
||||
irs::file_utils::handle_t nil;
|
||||
#endif
|
||||
|
||||
GeneralClientConnectionMock();
|
||||
~GeneralClientConnectionMock();
|
||||
virtual bool connectSocket() override;
|
||||
virtual void disconnectSocket() override;
|
||||
virtual bool readable() override;
|
||||
|
|
Loading…
Reference in New Issue