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