-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
THIRD_LIBS=-levent | ||
LIBS=-ldl | ||
CFLAGS=-I./include | ||
|
||
master:src/master.o src/worker.o src/listener.o src/connection.o src/main.o | ||
g++ -g -o $@ src/master.o src/worker.o src/listener.o src/connection.o src/main.o $(THIRD_LIBS) $(LIBS) | ||
|
||
src/master.o:src/master.cpp include/master.h | ||
g++ -g -o $@ -c $< $(CFLAGS) | ||
|
||
src/worker.o:src/worker.cpp include/worker.h include/util.h | ||
g++ -g -o $@ -c $< $(CFLAGS) | ||
|
||
src/listener.o:src/listener.cpp include/listener.h include/util.h | ||
g++ -g -o $@ -c $< $(CFLAGS) | ||
|
||
src/connection.o:src/connection.cpp include/connection.h include/util.h | ||
g++ -g -o $@ -c $< $(CFLAGS) | ||
|
||
src/main.o:src/main.cpp include/master.h | ||
g++ -g -o $@ -c $< $(CFLAGS) | ||
|
||
clean: | ||
rm -f src/*.o master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
High performance HTTP Server.It is designed to study Lighttpd(so I call it "slighttpd"). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/************************************************************************* | ||
> File Name: connection.h | ||
> Author: Jiange | ||
> Mail: jiangezh@qq.com | ||
> Created Time: 2016年01月27日 星期三 20时10分35秒 | ||
************************************************************************/ | ||
|
||
#ifndef _CONNECTION_H | ||
#define _CONNECTION_H | ||
|
||
#include <string> | ||
#include <queue> | ||
|
||
#include "event2/event.h" | ||
#include "event2/util.h" | ||
|
||
#include "util.h" | ||
|
||
class Worker; | ||
|
||
class Connection | ||
{ | ||
public: | ||
Connection(); | ||
~Connection(); | ||
|
||
bool InitConnection(Worker *worker); | ||
|
||
void WantRead(); | ||
void NotWantRead(); | ||
void WantWrite(); | ||
void NotWantWrite(); | ||
|
||
static void ConEventCallback(evutil_socket_t fd, short event, void *arg); | ||
|
||
Worker *con_worker; | ||
|
||
evutil_socket_t con_sockfd; | ||
struct sockaddr_in con_addr; | ||
struct event *con_event; //这里用两个event,一个注册读,一个注册写会效率高点 | ||
//struct event *write_event; | ||
//struct event *read_event; | ||
|
||
std::string con_inbuf; | ||
std::string con_intmp; | ||
std::string con_outbuf; | ||
|
||
static void FreeConnection(Connection *con); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/************************************************************************* | ||
> File Name: listener.h | ||
> Author: Jiange | ||
> Mail: jiangezh@qq.com | ||
> Created Time: 2016年01月27日 星期三 19时46分34秒 | ||
************************************************************************/ | ||
|
||
#ifndef _LISTENER_H | ||
#define _LISTENER_H | ||
|
||
#include <string> | ||
|
||
#include "event2/event.h" | ||
#include "event2/util.h" | ||
|
||
#include "util.h" | ||
|
||
class Worker; | ||
|
||
class Listener | ||
{ | ||
public: | ||
Listener(const std::string &ip, unsigned short port); | ||
~Listener(); | ||
|
||
bool InitListener(Worker *worker); | ||
void AddListenEvent(); | ||
|
||
static void ListenEventCallback(evutil_socket_t fd, short event, void *arg); | ||
|
||
Worker *listen_worker; | ||
evutil_socket_t listen_sockfd; | ||
struct sockaddr_in listen_addr; | ||
struct event *listen_event; | ||
uint64_t cnt_connection; | ||
}; | ||
|
||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/************************************************************************* | ||
> File Name: server.h | ||
> Author: Jiange | ||
> Mail: jiangezh@qq.com | ||
> Created Time: 2016年01月27日 星期三 19时33分00秒 | ||
************************************************************************/ | ||
|
||
#ifndef _MASTER_H | ||
#define _MASTER_H | ||
|
||
#include "worker.h" | ||
|
||
#include <string> | ||
|
||
#include "event2/event.h" | ||
#include "event2/util.h" | ||
|
||
class Master | ||
{ | ||
public: | ||
|
||
Master(const std::string &ip, unsigned short port); | ||
~Master(); | ||
|
||
bool StartMaster(); | ||
|
||
static void MasterExitSignal(evutil_socket_t signo, short event, void *arg); | ||
|
||
static void MasterChldSignal(evutil_socket_t signo, short event, void *arg); | ||
|
||
Worker worker; | ||
|
||
struct event_base *m_base; | ||
struct event *m_exit_event; | ||
struct event *m_chld_event; | ||
|
||
int nums_of_child; | ||
|
||
private: | ||
|
||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/************************************************************************* | ||
> File Name: util.h | ||
> Author: Jiange | ||
> Mail: jiangezh@qq.com | ||
> Created Time: 2016年01月28日 星期四 10时39分22秒 | ||
************************************************************************/ | ||
|
||
#ifndef _UTIL_H | ||
#define _UTIL_H | ||
|
||
#include <signal.h> | ||
#include <unistd.h> | ||
#include <sys/socket.h> | ||
#include <netinet/in.h> | ||
#include <arpa/inet.h> | ||
#include <errno.h> | ||
#include <stdint.h> | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/************************************************************************* | ||
> File Name: worker.h | ||
> Author: Jiange | ||
> Mail: jiangezh@qq.com | ||
> Created Time: 2016年01月27日 星期三 20时10分35秒 | ||
************************************************************************/ | ||
|
||
#ifndef _WORKER_H | ||
#define _WORKER_H | ||
|
||
#include "listener.h" | ||
|
||
#include <string> | ||
#include <map> | ||
|
||
#include "event2/event.h" | ||
#include "event2/util.h" | ||
|
||
#include "util.h" | ||
|
||
class Master; | ||
class Connection; | ||
|
||
class Worker | ||
{ | ||
public: | ||
|
||
typedef std::map<evutil_socket_t, Connection*> ConnectionMap; | ||
|
||
Worker(const std::string &ip, unsigned short port); | ||
~Worker(); | ||
|
||
void Run(); | ||
|
||
static void WorkerExitSignal(evutil_socket_t signo, short event, void *arg); | ||
|
||
Master *master; | ||
Listener listener; | ||
ConnectionMap con_map; | ||
|
||
struct event_base *w_base; | ||
struct event *w_exit_event; | ||
|
||
std::string s_inbuf; | ||
std::string s_intmp; | ||
std::string s_outbuf; | ||
|
||
}; | ||
|
||
#endif |
Oops, something went wrong.