Skip to content

Commit

Permalink
README updated
Browse files Browse the repository at this point in the history
  • Loading branch information
yedf committed Aug 14, 2015
1 parent 4d8e66e commit d6a932b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
19 changes: 7 additions & 12 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,17 @@ only 10 lines can finish a complete server

```c
#include <handy/handy.h>

using namespace std;
using namespace handy;


int main(int argc, const char* argv[]) {
EventBase bases; //event dispatcher
Signal::signal(SIGINT, [&]{ bases.exit(); }); // handle Ctrl+C
TcpServer echo(&bases); //create tcpserver
int r = echo.bind("", 99); //bind port
exitif(r, "bind failed %d %s", errno, strerror(errno));
echo.onConnRead([](const TcpConnPtr& con) {
con->send(con->getInput()); // echo the data read
EventBase base;
Signal::signal(SIGINT, [&]{ base.exit(); });
TcpServerPtr svr = TcpServer::startServer(&base, "", 99);
exitif(svr == NULL, "start tcp server failed");
svr->onConnRead([](const TcpConnPtr& con) {
con->send(con->getInput());
});
bases.loop(); //enter event loop
}
base.loop();
```
### half sync half async pattern
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,17 @@ handy[![Build Status](https://travis-ci.org/yedf/handy.png)](https://travis-ci.o

```c
#include <handy/handy.h>

using namespace std;
using namespace handy;


int main(int argc, const char* argv[]) {
EventBase bases; //事件分发器
Signal::signal(SIGINT, [&]{ bases.exit(); }); //注册Ctrl+C的信号处理器--退出事件分发循环
TcpServer echo(&bases); //创建服务器
int r = echo.bind("", 99); //绑定端口
exitif(r, "bind failed %d %s", errno, strerror(errno));
echo.onConnRead([](const TcpConnPtr& con) {
con->send(con->getInput()); // echo 读取的数据
EventBase base;
Signal::signal(SIGINT, [&]{ base.exit(); });
TcpServerPtr svr = TcpServer::startServer(&base, "", 99);
exitif(svr == NULL, "start tcp server failed");
svr->onConnRead([](const TcpConnPtr& con) {
con->send(con->getInput());
});
bases.loop(); //进入事件分发循环
base.loop();
}
```
Expand Down
3 changes: 0 additions & 3 deletions examples/echo.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <handy/handy.h>

using namespace std;
using namespace handy;


int main(int argc, const char* argv[]) {
EventBase base;
Signal::signal(SIGINT, [&]{ base.exit(); });
Expand Down

0 comments on commit d6a932b

Please sign in to comment.