README
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
spserver README
1.Introduction
spserver is a TCP server framework library written in C++ based on libevent.
spserver implements the Half-Sync/Half-Async and the Leader/Follower patterns.
More detail about the Half-Sync/Half-Async and Leader/Follower patterns:
http://www.cs.wustl.edu/~schmidt/PDF/HS-HA.pdf
http://www.cs.wustl.edu/~schmidt/PDF/lf.pdf
Code description:
SP_Server class implements the Half-Sync/Half-Async pattern.
SP_Server, SP_EventCallback, SP_Session, SP_Request(SP_MsgDecoder), SP_Response(SP_Message)
The asynchronous layer, which receives the asynchronous requests
SP_EventArg::mInputResultQueue, SP_EventArg::mOutputResultQueue
The queueing layer, which buffers the requests
SP_Executor, SP_ThreadPool, SP_Handler
The synchronous layer, which contains several threads of control blocked
on the queueing layer
SP_LFServer class implements the Leader/Follower pattern.
The spserver code was developed under Linux, but has also been tested under Solaris.
You can get the code from the spserver home page:
http://code.google.com/p/spserver/
2.Building
Before building spserver, libevent must been installed. Test with libevent 1.1 and 1.2.
You can donwload libevent from its home page:
http://www.monkey.org/~provos/libevent/
Edit spserver/Makefile to specify the path of libevent:
LIBEVENT_INCL = -I<path_to_libevent_include>
LIBEVENT_LIB = -L<path_to_libevent_library> -levent
To build libspserver.so, type
$ cd spserver
$ make
This will build all the targets include examples. You can run the
example programs:
$ ./testsmtp
[msg] This server is listening on port [1025].
Open another console, use telnet to test:
$ telnet 127.0.0.1 1025
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 SMTP Server Ready
helo abc
250 ok.
mail from:<abc@abc.com>
250 sender ok.
rcpt to:<foo@bar.com>
250 recipient ok.
data
354 Start mail input; end with <CRLF>.<CRLF>
From: abc@abc.com
To: foo@bar.com
Subject: test
test
.
250 Requested mail action okay, completed.
quit
221 Closing connection. Good bye.
Connection closed by foreign host.
3.Credits
Special thanks go to Andrew Danforth, who provides a good solution to
use libevent in multithreaded environment.
Any and all comments are appreciated.
Enjoy!
-- stephen liu <stephen.nil@gmail.com>