Commit 968e25ed authored by jan.koester's avatar jan.koester
Browse files

reworked syncronesation

parent fddad130
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -78,9 +78,6 @@ namespace netplus {

            /*set sending state*/
            void    sending(bool state);

            /*connection locking*/
            std::mutex conlock;
        protected:
            con();
            /*Incomming Data*/
+10 −30
Original line number Diff line number Diff line
@@ -100,7 +100,6 @@ namespace netplus {
    };

    int poll::pollState(int pos){
        const std::lock_guard<std::mutex> lock(_StateLock);
        NetException exception;
        con* ccon = (con*)_Events[pos].data.ptr;
        if (!ccon) {
@@ -113,6 +112,7 @@ namespace netplus {
    }

    unsigned int poll::waitEventHandler() {
        const std::lock_guard<std::mutex> lock(_StateLock);
        int ret = epoll_wait(_pollFD, (struct epoll_event*)_Events, _ServerSocket->getMaxconnections(), -1);
        if (ret == -1) {
            NetException exception;
@@ -127,7 +127,6 @@ namespace netplus {
        con *ccon;
        try {
            ccon = new con(this);
            ccon->conlock.lock();
            ccon->csock = _ServerSocket->accept();
            ccon->csock->setnonblocking();

@@ -143,9 +142,7 @@ namespace netplus {
            ccon->csock->getAddress(ip);
            std::cout << "Connected: " << ip  << std::endl;
            ConnectEvent(ccon);
            ccon->conlock.unlock();
        } catch (NetException& e) {
            ccon->conlock.unlock();
            delete ccon->csock;
            delete ccon;
        }
@@ -254,20 +251,6 @@ namespace netplus {
        }
    };

    void poll::unlockCon(int pos){
        con *curcon=(con*)_Events[pos].data.ptr;
        if(curcon)
            curcon->conlock.unlock();
    }

    bool poll::trylockCon(int pos){
        const std::lock_guard<std::mutex> lock(_StateLock);
        con *curcon=(con*)_Events[pos].data.ptr;
        if(curcon)
            return curcon->conlock.try_lock();
        return false;
    }

    bool event::_Run = true;
    bool event::_Restart = false;

@@ -284,7 +267,6 @@ namespace netplus {
                            int state=eventptr->pollState(i);
                            if(state==poll::EVCON)
                                eventptr->ConnectEventHandler(i);
                            if(eventptr->trylockCon(i)){
                            switch (state) {
                                case poll::EVIN:
                                    eventptr->ReadEventHandler(i);
@@ -295,8 +277,6 @@ namespace netplus {
                                default:
                                    break;
                            }
                                eventptr->unlockCon(i);
                            }
                        } catch (NetException& e) {
                            eventptr->CloseEventHandler(i);
                            if (e.getErrorType() == NetException::Critical) {