header refactoring
This commit is contained in:
parent
bf6f057777
commit
06d2b68696
@ -36,6 +36,7 @@ set( IXWEBSOCKET_HEADERS
|
||||
ixwebsocket/IXSetThreadName.h
|
||||
ixwebsocket/IXDNSLookup.h
|
||||
ixwebsocket/IXCancellationRequest.h
|
||||
ixwebsocket/IXNetSystem.h
|
||||
ixwebsocket/IXWebSocket.h
|
||||
ixwebsocket/IXWebSocketServer.h
|
||||
ixwebsocket/IXWebSocketTransport.h
|
||||
|
@ -5,18 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "IXDNSLookup.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <basetsd.h>
|
||||
# include <WinSock2.h>
|
||||
# include <ws2def.h>
|
||||
# include <WS2tcpip.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
#include "IXNetSystem.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <chrono>
|
||||
|
25
ixwebsocket/IXNetSystem.h
Normal file
25
ixwebsocket/IXNetSystem.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* IXNetSystem.h
|
||||
* Author: Benjamin Sergeant
|
||||
* Copyright (c) 2019 Machine Zone. All rights reserved.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <WS2tcpip.h>
|
||||
# include <WinSock2.h>
|
||||
# include <basetsd.h>
|
||||
# include <io.h>
|
||||
# include <ws2def.h>
|
||||
#else
|
||||
# include <arpa/inet.h>
|
||||
# include <errno.h>
|
||||
# include <netdb.h>
|
||||
# include <netinet/tcp.h>
|
||||
# include <sys/select.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
@ -6,23 +6,7 @@
|
||||
|
||||
#include "IXSocket.h"
|
||||
#include "IXSocketConnect.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <basetsd.h>
|
||||
# include <WinSock2.h>
|
||||
# include <ws2def.h>
|
||||
# include <WS2tcpip.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <errno.h>
|
||||
# include <netdb.h>
|
||||
# include <netinet/tcp.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/select.h>
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#include "IXNetSystem.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -4,29 +4,9 @@
|
||||
* Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
//
|
||||
// http://itamarst.org/writings/win32sockets.html
|
||||
//
|
||||
|
||||
#include "IXSocketConnect.h"
|
||||
#include "IXDNSLookup.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <basetsd.h>
|
||||
# include <WinSock2.h>
|
||||
# include <ws2def.h>
|
||||
# include <WS2tcpip.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <errno.h>
|
||||
# include <netdb.h>
|
||||
# include <netinet/tcp.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/time.h>
|
||||
# include <sys/select.h>
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#include "IXNetSystem.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
@ -89,6 +69,7 @@ namespace ix
|
||||
}
|
||||
}
|
||||
|
||||
// Use select to see if the connect did succeed.
|
||||
fd_set wfds;
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(fd, &wfds);
|
||||
@ -122,7 +103,7 @@ namespace ix
|
||||
socklen_t optlen = sizeof(optval);
|
||||
|
||||
#ifdef _WIN32
|
||||
//
|
||||
// On connect error, in async mode, windows will write to the exceptions fds
|
||||
if (FD_ISSET(fd, &efds))
|
||||
#else
|
||||
// getsockopt() puts the errno value for connect into optval so 0
|
||||
@ -143,7 +124,7 @@ namespace ix
|
||||
}
|
||||
|
||||
closeSocket(fd);
|
||||
errMsg = "connect timed out after 60 seconds";
|
||||
errMsg = "connect timed out";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -8,24 +8,10 @@
|
||||
#include "IXWebSocketTransport.h"
|
||||
#include "IXWebSocket.h"
|
||||
#include "IXSocketConnect.h"
|
||||
#include "IXNetSystem.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <future>
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <basetsd.h>
|
||||
# include <WinSock2.h>
|
||||
# include <ws2def.h>
|
||||
# include <WS2tcpip.h>
|
||||
# include <io.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <netdb.h>
|
||||
# include <stdio.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace ix
|
||||
|
@ -65,7 +65,7 @@ TEST_CASE("socket", "[socket]")
|
||||
int port = 80;
|
||||
std::string request("GET / HTTP/1.1\r\n\r\n");
|
||||
int expectedStatus = 200;
|
||||
int timeoutSecs = 1;
|
||||
int timeoutSecs = 3;
|
||||
|
||||
testSocket(host, port, request, socket, expectedStatus, timeoutSecs);
|
||||
}
|
||||
@ -82,7 +82,7 @@ TEST_CASE("socket", "[socket]")
|
||||
int port = 443;
|
||||
std::string request("GET / HTTP/1.1\r\n\r\n");
|
||||
int expectedStatus = 200;
|
||||
int timeoutSecs = 1;
|
||||
int timeoutSecs = 3;
|
||||
|
||||
testSocket(host, port, request, socket, expectedStatus, timeoutSecs);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user