Commit 979e9a92 authored by jan.koester's avatar jan.koester
Browse files

fixes

parent a2bee1c1
Loading
Loading
Loading
Loading
+1 −1
Changes for src/event/iocp.cpp: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ namespace netplus {
			if (!giocp2 || g_iocp != giocp2) {
				DWORD err = GetLastError();
				NetException exp;
				exp[NetException::Error] << "AssociateWithIOCP fehlgeschlagen: Fehlercode " << err;
				exp[NetException::Error] << "AssociateWithIOCP failed: failcode " << err;
				throw exp;
			}
		}
+4 −6
Changes for src/windows/tcp.cpp: 4 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ netplus::tcp::tcp(const std::string& addr, int port, int maxconnections, int soc
    _Maxconnections = maxconnections;

    if (sockopts == -1)
        sockopts = SO_REUSEADDR | WSA_FLAG_OVERLAPPED;
        sockopts = WSA_FLAG_OVERLAPPED;

    struct addrinfo hints, * result = nullptr, * rp = nullptr;

@@ -75,8 +75,6 @@ netplus::tcp::tcp(const std::string& addr, int port, int maxconnections, int soc
        throw exception;
    }

    std::cerr << result << std::endl;

    for (rp = result; rp != nullptr; rp = rp->ai_next) {
        _Socket = ::WSASocket(rp->ai_family, rp->ai_socktype,
                           rp->ai_protocol,nullptr, 0, sockopts);
@@ -95,7 +93,7 @@ netplus::tcp::tcp(const std::string& addr, int port, int maxconnections, int soc

    if (rp != nullptr) {
        _SocketInfoLen = rp->ai_addrlen;
        copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp->ai_addr, rp->ai_addrlen);
        copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp, sizeof(hints));
    }
    
    ::freeaddrinfo(result);
@@ -186,7 +184,7 @@ void netplus::tcp::accept(LPFN_ACCEPTEX lpfnAcceptEx,std::unique_ptr<socket> &cs

        int etype = NetException::Error;
        if (GetLastError() == WSA_IO_PENDING)
            etype = NetException::Note;
            return;

        exception[etype] << "AcceptEX: failed on " << (int)csock->_Socket << " error code : " << GetLastError();
        throw exception;
@@ -195,7 +193,7 @@ void netplus::tcp::accept(LPFN_ACCEPTEX lpfnAcceptEx,std::unique_ptr<socket> &cs

void netplus::tcp::bind(){
    NetException exception;
    if (::bind(_Socket, ((struct addrinfo*)_SocketInfo)->ai_addr, (int)((struct addrinfo*)_SocketInfo)->ai_addrlen) < 0) {
    if (::bind(_Socket, ((struct addrinfo*)_SocketInfo)->ai_addr, (int)((struct addrinfo*)_SocketInfo)->ai_addrlen) != 0) {
        exception[NetException::Error] << "Can't bind Server Socket";
        throw exception;
    }
+20 −10
Changes for src/windows/udp.cpp: 20 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -52,12 +52,12 @@ netplus::udp::udp(const std::string &addr, int port, int maxconnections, int soc
    _Maxconnections = maxconnections;

    if (sockopts == -1)
        sockopts = SO_REUSEADDR | WSA_FLAG_OVERLAPPED;
        sockopts = WSA_FLAG_OVERLAPPED;

    struct addrinfo hints, * result = nullptr, * rp = nullptr;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET;
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_flags = AI_PASSIVE;
    hints.ai_protocol = IPPROTO_UDP;
@@ -65,12 +65,10 @@ netplus::udp::udp(const std::string &addr, int port, int maxconnections, int soc
    hints.ai_addr = NULL;
    hints.ai_next = NULL;

    int tsock;

    char serv[512];
    char serv[512] = { '\0' };
    snprintf(serv, 512, "%d", port);

    if ((tsock = ::getaddrinfo(addr.c_str(), serv, &hints, &result)) < 0) {
    if (::getaddrinfo(addr.c_str(), serv, &hints, &result) != 0) {
        exception[NetException::Critical] << "Socket Invalid address/ Address not supported";
        throw exception;
    }
@@ -78,15 +76,27 @@ netplus::udp::udp(const std::string &addr, int port, int maxconnections, int soc
    for (rp = result; rp != nullptr; rp = rp->ai_next) {
        _Socket = ::WSASocket(rp->ai_family, rp->ai_socktype,
            rp->ai_protocol, nullptr, 0, sockopts);
        if (_Socket == -1)

        if (_Socket == INVALID_SOCKET)
            continue;
        _SocketInfoLen = sizeof(hints);
        copyAddrInfo(&_SocketInfo,(ULONG_PTR)rp,sizeof(hints));

        break;
    }

    if (_Socket == INVALID_SOCKET) {
        ::freeaddrinfo(result);
        exception[NetException::Critical] << "Create Socket " << (int)_Socket << " failed : " << GetLastError();
        throw exception;
    }

    if (rp != nullptr) {
        _SocketInfoLen = rp->ai_addrlen;
        copyAddrInfo(&_SocketInfo, (ULONG_PTR)rp, sizeof(hints));
    }

    ::freeaddrinfo(result);

    _SocketInfoLen = sizeof(hints);
    _Type = sockettype::UDP;
}

@@ -173,7 +183,7 @@ void netplus::udp::accept(LPFN_ACCEPTEX lpfnAcceptEx, std::unique_ptr<socket> &c

        int etype = NetException::Error;
        if (GetLastError() == WSA_IO_PENDING)
            etype = NetException::Note;
            return;

        exception[etype] << "AcceptEX: failed on " << (int)csock->_Socket << " error code : " << GetLastError();
        throw exception;