Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hewei.it committed Dec 8, 2020
1 parent 03ce9e8 commit 5050e49
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/tcp_chat_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "hbase.h"
#include "list.h"

// hloop_create_tcp_server
// on_accept => join
// on_recv => broadcast
// on_close => leave

typedef struct chatroom_s {
hloop_t* loop;
hio_t* listenio;
Expand Down
2 changes: 2 additions & 0 deletions examples/tcp_echo_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "hloop.h"
#include "hsocket.h"

// hloop_create_tcp_server -> on_accept -> hio_read -> on_recv -> hio_write

static void on_close(hio_t* io) {
printf("on_close fd=%d error=%d\n", hio_fd(io), hio_error(io));
}
Expand Down
9 changes: 5 additions & 4 deletions examples/tcp_proxy_server.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* tcp proxy server
*
* @test: make examples
* @build: make examples
* @http_server: bin/httpd -d
* @proxy_server: bin/tcp_proxy_server 1234 127.0.0.1:8080
* bin/tcp_proxy_server 1234 www.baidu.com
Expand All @@ -18,12 +18,13 @@
#include "hloop.h"
#include "hsocket.h"

// hloop_create_tcp_server => on_accept(connio) => proxyio = hloop_create_tcp_client
// on_proxy_connect => hio_read(connio) hio_read(proxyio)
// hloop_create_tcp_server
// on_accept(connio) => proxyio = hloop_create_tcp_client
// on_proxy_connect(proxyio) => hio_read(connio) hio_read(proxyio)
// on_recv(connio) => hio_write(proxyio)
// on_proxy_recv(proxyio) => hio_write(connio)
// on_close(connio) => hio_close(proxyio)
// on_proxy(proxyio) => hio_close(connio)
// on_proxy_close(proxyio) => hio_close(connio)

static char proxy_host[64] = "127.0.0.1";
static int proxy_port = 80;
Expand Down

0 comments on commit 5050e49

Please sign in to comment.