Support Windows for client
This commit is contained in:
		
							parent
							
								
									1f82e94296
								
							
						
					
					
						commit
						915975fba8
					
				@ -5,12 +5,19 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <arpa/inet.h>
 | 
			
		||||
#include <netdb.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <openssl/ssl.h>
 | 
			
		||||
#include <openssl/err.h>
 | 
			
		||||
 | 
			
		||||
#if __linux__
 | 
			
		||||
    #include <arpa/inet.h>
 | 
			
		||||
    #include <netdb.h>
 | 
			
		||||
    #include <unistd.h>
 | 
			
		||||
#elif _WIN32
 | 
			
		||||
    // #include <sstream>
 | 
			
		||||
    #include <WinSock.h>
 | 
			
		||||
    #include <ws2tcpip.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "ip.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
@ -118,6 +118,15 @@ secure::~secure () {
 | 
			
		||||
 | 
			
		||||
client::client(const string address, const ushort port, const uint timeout, SSL_CTX* securefds) {
 | 
			
		||||
 | 
			
		||||
    #if _WIN32
 | 
			
		||||
        WSADATA wsa;
 | 
			
		||||
        SOCKET s;
 | 
			
		||||
        if (WSAStartup(MAKEWORD(2,2),&wsa) != 0) {
 | 
			
		||||
            //printf("Failed. Error Code : %d",WSAGetLastError());
 | 
			
		||||
            throw string("[ERROR] Unable to set WinSock " + to_string(WSAGetLastError()));
 | 
			
		||||
        }
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    conn = socket(AF_INET, SOCK_STREAM, 0);
 | 
			
		||||
	if (conn < 0) {
 | 
			
		||||
        throw string("[ERROR] Unable to open TCP socket ");
 | 
			
		||||
@ -215,6 +224,10 @@ client::client(const server *_srv, const uint timeout, SSL_CTX* securefds) {
 | 
			
		||||
 | 
			
		||||
client::~client () {
 | 
			
		||||
 | 
			
		||||
    #if _WIN32
 | 
			
		||||
        WSACleanup();
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    if (ssl) {
 | 
			
		||||
        SSL_shutdown(ssl);
 | 
			
		||||
        SSL_free(ssl);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user