-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTcpServer Design
More file actions
22 lines (19 loc) · 849 Bytes
/
TcpServer Design
File metadata and controls
22 lines (19 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
TcpServer Design
class TcpServer
* goal - implement a one thread TcpServer
* member variables
status - denotes the status of TcpServer - start, stop, running
logger - log each meaningful info/exception
config - denotes what conifg this TcpServer depends on
socket - denotes listening socket of TcpServer
* member functions
initialize (config, http)- according to config, init socket of TcpServer.
start - start TcpServer
change server status to running
one thread's processing loop
uses IO.select to detect kinds of events
when one client connects TcpServer, non-blocking accept it
when clients' data comes, call HttpRequest.parse to parse Clients' request, then call HttpServer.process to pass the request to http, send the results back
change server status to stop
shutdown - close TcpServer
clear TcpServer socket