Commit be7e0c41 authored by jan.koester's avatar jan.koester
Browse files

test

parent e3b84f40
Loading
Loading
Loading
Loading
+30 −11
Changes for src/event/kqueue.cpp: 30 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h>
#include <stdint.h>
#include <mutex>
#include <map>

#include <cstring>
#include <errno.h>
@@ -55,17 +56,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace netplus {
    std::atomic<bool> RUNNING(true);
    std::mutex POLL_HANDLER_MUTEX;

    void signalHandler(int signum) {
        switch(signum){
            case SIGINT:
                RUNNING=false;
                break;
            default:
                break;
        }
    }
    std::mutex POLL_HANDLER_
    std::map<int,con*>    CONNECTIONS;

    class pollapi {
    public:
@@ -219,8 +211,13 @@ namespace netplus {
                    throw exception;
                }

                evconnection ->ConnectEvent(*ccon,tid,args);
                {
                    std::lock_guard<std::mutex> clock(ccon->event_mutex),global_lock(POLL_HANDLER_MUTEX);
                    CONNECTIONS.emplace(ccon->csock->fd(),ccon.get());
                    ccon.release();
                }
            }
        };

        void ReadEventHandler(int pos,const int tid,ULONG_PTR args) {
@@ -350,6 +347,8 @@ namespace netplus {
                        evconnection->DisconnectEvent(*ccon, tid, args);

                        _Events[pos].udata  = nullptr;

                        CONNECTIONS.erase(ccon->csock->fd());
                    } catch (NetException &e) {
                        throw e;
                    }
@@ -477,6 +476,26 @@ public:
    event::~event() {
    }

    void signalHandler(int signum) {
        std::lock_guard<std::mutex> lock(POLL_HANDLER_MUTEX);
        switch(signum){
            case SIGINT:
                for(auto ssock : SSOCKETS){
                    ssock->close();
                }
                for(auto ccon : CONNECTIONS){
                    {
                        std::lock_guard<std::mutex> clock(ccon.second->event_mutex);
                        ccon.second->csock->close();
                    }
                }
                RUNNING=false;
                break;
            default:
                break;
        }
    }

    void event::runEventloop(ULONG_PTR args) {
        NetException exception;