Commit 94278dfd authored by jan.koester's avatar jan.koester
Browse files

fixes

parent 597dbab3
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -60,8 +60,6 @@ namespace netplus {
        client(eventapi* eapi) {
            api = eapi;
            api->CreateConnetion(&CurCon);
            m_pwbuf.buf = new char[BLOCKSIZE];
            m_pwbuf.len = BLOCKSIZE;
            OpCode = 0;
            m_pol.Internal = 0;
            m_pol.InternalHigh = 0;
@@ -72,11 +70,9 @@ namespace netplus {

        ~client() {
            api->deleteConnetion(CurCon);
            delete[] m_pwbuf.buf;
        };

        OVERLAPPED  m_pol;
        WSABUF      m_pwbuf;

        int         OpCode; //will be used by the worker thread to decide what operation to perform
        eventapi   *api;
@@ -164,8 +160,11 @@ namespace netplus {
                //Get data.
                DWORD dwFlags = 0;
                DWORD dwBytes = 0;
                WSABUF wbuf;
                wbuf.buf = new char[BLOCKSIZE];
                wbuf.len = BLOCKSIZE;
RECONNECT:
                int nBytesRecv = WSARecv(pClientContext->CurCon->csock->fd(), &pClientContext->m_pwbuf, 1,
                int nBytesRecv = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1,
                                         &dwBytes, &dwFlags,&pClientContext->m_pol, nullptr);

                if (SOCKET_ERROR == nBytesRecv){
@@ -176,10 +175,12 @@ RECONNECT:
                    e[NetException::Error] << "AcceptConnection Failed on: " << (int) pClientContext->CurCon->csock->fd()
                                           << "Error: " << WSAGetLastError();
                    RemoveFromClientList(pClientContext);
                    delete wbuf.buf;
                    throw e;
                }

                pClientContext->CurCon->RecvData.append(pClientContext->m_pwbuf.buf,dwBytes);
                pClientContext->CurCon->RecvData.append(wbuf.buf,dwBytes);
                delete wbuf.buf;

            }
            LeaveCriticalSection(&g_csClientList);
@@ -309,11 +310,12 @@ RECONNECT:

                        ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : pClientContext->CurCon->SendData.size();

                        pClientContext->m_pwbuf.buf = pClientContext->CurCon->SendData.data();
                        pClientContext->m_pwbuf.len = (ULONG)ssize;
                        WSABUF wbuf;
                        wbuf.buf = pClientContext->CurCon->SendData.data();
                        wbuf.len = ssize;

                        //Overlapped send
                        ret = WSASend(pClientContext->CurCon->csock->fd(), &pClientContext->m_pwbuf, 1,
                        ret = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1,
                            &dwBytes, dwFlags, &pClientContext->m_pol, nullptr);

                        if ((SOCKET_ERROR == ret) && (WSA_IO_PENDING != WSAGetLastError())){
@@ -332,20 +334,24 @@ RECONNECT:

                        ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : pClientContext->CurCon->SendData.size();

                        pClientContext->m_pwbuf.buf = pClientContext->CurCon->SendData.data();
                        pClientContext->m_pwbuf.len = (ULONG)ssize;
                        WSABUF wbuf;
                        wbuf.buf = new char[BLOCKSIZE];
                        wbuf.len = BLOCKSIZE;

                        //Get the data.
                        ret = WSARecv(pClientContext->CurCon->csock->fd(), &pClientContext->m_pwbuf, 1,
                        ret = WSARecv(pClientContext->CurCon->csock->fd(), &wbuf, 1,
                            &dwBytes, &dwFlags, &pClientContext->m_pol, nullptr);

                        if ((SOCKET_ERROR == ret) && (WSA_IO_PENDING != WSAGetLastError())) {
                            std::cerr << "Thread " << tid << " : Error occurred while executing WSARecv()." << std::endl;
                            //Let's not work with this client
                            eargs->event->DisconnectEvent(pClientContext->CurCon, tid, args);
                            eargs->evpoll->RemoveFromClientList(pClientContext);
                        }

                        pClientContext->CurCon->RecvData.append(pClientContext->m_pwbuf.buf, dwBytes);
                        pClientContext->CurCon->RecvData.append(wbuf.buf, dwBytes);

                        delete wbuf.buf;

                        eargs->event->RequestEvent(pClientContext->CurCon, tid, args);            
                    }
@@ -358,11 +364,12 @@ RECONNECT:

                    ssize = BLOCKSIZE < pClientContext->CurCon->SendData.size() ? BLOCKSIZE : pClientContext->CurCon->SendData.size();

                    pClientContext->m_pwbuf.buf = pClientContext->CurCon->SendData.data();
                    pClientContext->m_pwbuf.len = (ULONG)ssize;
                    WSABUF wbuf;
                    wbuf.buf = pClientContext->CurCon->SendData.data();
                    wbuf.len = ssize;

                    //Overlapped send
                    ret = WSASend(pClientContext->CurCon->csock->fd(), &pClientContext->m_pwbuf, 1,
                    ret = WSASend(pClientContext->CurCon->csock->fd(), &wbuf, 1,
                        &dwBytes, dwFlags, &pClientContext->m_pol, NULL);

                    if ((SOCKET_ERROR == ret) && (WSA_IO_PENDING != WSAGetLastError()))
+4 −0
Original line number Diff line number Diff line
@@ -100,3 +100,7 @@ void netplus::socket::setTimeout(int sec){

    }
}

SOCKET netplus::socket::fd() {
    return _Socket;
}
 No newline at end of file
+1 −5
Original line number Diff line number Diff line
@@ -151,10 +151,6 @@ void netplus::tcp::listen(){
    }
}

int netplus::tcp::fd(){
    return _Socket;
}

netplus::tcp& netplus::tcp::operator=(int sock){
     _Socket=sock;
     return *this;
@@ -165,7 +161,7 @@ int netplus::tcp::getMaxconnections(){
    return _Maxconnections;
}

void netplus::tcp::accept(socket *csock){
void netplus::tcp::accept(tcp *csock){
    NetException exception;
    struct sockaddr myaddr;
    socklen_t myaddrlen=sizeof(myaddr);
+0 −4
Original line number Diff line number Diff line
@@ -149,10 +149,6 @@ void netplus::udp::listen(){
    }
}

SOCKET netplus::udp::fd(){
    return _Socket;
}

netplus::udp& netplus::udp::operator=(int sock){
     _Socket=sock;
     return *this;
+3 −4
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ namespace netplus {

            virtual void             getAddress(std::string &addr)=0;

            virtual SOCKET           fd()=0;
            SOCKET                   fd();

            virtual socket&          operator=(SOCKET sock)=0;

@@ -90,7 +90,6 @@ namespace netplus {
            void          accept(socket *ssock);
            void          bind();
            void          listen();
            SOCKET        fd();
            tcp&          operator=(SOCKET socket);

            int           getMaxconnections();
@@ -122,7 +121,7 @@ namespace netplus {
            void          accept(socket * ssock);
            void          bind();
            void          listen();
            SOCKET        fd();

            udp&          operator=(int socket);

            int           getMaxconnections();
@@ -154,7 +153,7 @@ namespace netplus {
            void          accept(socket *ssock);
            void          bind();
            void          listen();
            SOCKET        fd();

            ssl&          operator=(int socket);
            int           getMaxconnections();
            
Loading