Skip to content

Commit

Permalink
add SignHandler & rename MsgHandler -> MSGHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
mathetian committed Aug 9, 2014
1 parent a6c1b0e commit d0e1d0c
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 262 deletions.
4 changes: 2 additions & 2 deletions Make.defines
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ CLEAN = \
include/TimeEventSet \
include/Status \
include/TCPAcceptor \
include/Selector MsgHandler\
include/Selector MSGHandler\
tests/echo_client \
tests/echo_server \
tests/test_log \
Expand All @@ -29,4 +29,4 @@ CLEAN = \
utils/Atomic \
utils/Buffer \
utils/Thread \
include/MsgHandler
include/MSGHandler
11 changes: 11 additions & 0 deletions core/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,15 @@ void EventLoop::attach(const Callback<void> &call, const Timer &timer)
m_heap.add(call, timer);
}

void EventLoop::attach(int signo, void (*sighandler)(int))
{
m_signal -> attach(signo, sighandler);
}

void EventLoop::attach()
{
SignalOuter &outer = SignalOuter::Instance();
m_signal = new SignalHandler(this, outer.sockets().second);
}

};
8 changes: 8 additions & 0 deletions core/EventPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ EventPool::EventPool(int loopNum) : m_loopNum(loopNum)

for(int i=0; i < loopNum ; i++)
m_loops[i] = new EventLoop(this);

/// Attach Signal Handler to the master thread
m_loops[0] -> attach();
}

EventPool::~EventPool()
Expand Down Expand Up @@ -118,4 +121,9 @@ void* EventPool::ThreadFunc(void *arg)
pthread_exit(NULL);
}

void EventPool::attach(int signo, void (*sighandler)(int))
{
m_loops[0] -> attach(signo, sighandler);
}

};
165 changes: 0 additions & 165 deletions core/MsgHandler.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion http/HttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef _HTTP_CONN_H
#define _HTTP_CONN_H

#include "MsgHandler.h"
#include "MSGHandler.h"
using namespace eventserver;

namespace http
Expand Down
8 changes: 8 additions & 0 deletions include/EventLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using namespace utils;
#include "Handler.h"
#include "Acceptor.h"
#include "Selector.h"
#include "SignalHandler.h"

namespace eventserver
{
Expand Down Expand Up @@ -81,6 +82,12 @@ class EventLoop : public Noncopyable
/// Attach Timer to this loop
void attach(const Callback<void> &call, const Timer &timer);

/// Attach Signal Handler
void attach(int signo, void (*sighandler)(int));

/// Attach signal handler
void attach();

private:
/// Run After dispatch(for all active events)
void runAllActives();
Expand All @@ -103,6 +110,7 @@ class EventLoop : public Noncopyable
vector<Handler*> m_del;
map<int, Handler*> m_map;
TimerEvents m_heap;
SignalHandler *m_signal;

friend class Acceptor;
};
Expand Down
4 changes: 4 additions & 0 deletions include/EventPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class EventPool : public Noncopyable
/// get the Number of Loops
int getLoopNum() const;

public:
/// attach signal handler
void attach(int signo, void(*sighanler)(int));

private:
/// Threadxxxx is used to assist the `run`
void* ThreadBody(int id);
Expand Down
91 changes: 0 additions & 91 deletions include/MsgHandler.h

This file was deleted.

Loading

0 comments on commit d0e1d0c

Please sign in to comment.