Spaces:
Paused
Paused
xukc
commited on
Commit
·
94b5d39
1
Parent(s):
4b326a2
[fix]log fmt err
Browse files- main.cpp +1 -1
- tcp_inbound.cpp +7 -6
main.cpp
CHANGED
|
@@ -200,7 +200,7 @@ int main(int argc, char** argv) {
|
|
| 200 |
|
| 201 |
init_loop(thread_num, worker_thread);
|
| 202 |
|
| 203 |
-
spdlog::info("ProxyServer start: threadNum
|
| 204 |
|
| 205 |
accept_loop = hloop_new(HLOOP_FLAG_AUTO_FREE);
|
| 206 |
accept_thread(accept_loop);
|
|
|
|
| 200 |
|
| 201 |
init_loop(thread_num, worker_thread);
|
| 202 |
|
| 203 |
+
spdlog::info("ProxyServer start: threadNum:{:d}", thread_num);
|
| 204 |
|
| 205 |
accept_loop = hloop_new(HLOOP_FLAG_AUTO_FREE);
|
| 206 |
accept_thread(accept_loop);
|
tcp_inbound.cpp
CHANGED
|
@@ -13,18 +13,18 @@ class TcpClientShell {
|
|
| 13 |
io = _io;
|
| 14 |
int connfd = cli.createsocket(hio_peeraddr(io));
|
| 15 |
if (connfd < 0) {
|
| 16 |
-
return
|
| 17 |
}
|
| 18 |
cli.onConnection = [this](const hv::SocketChannelPtr& channel) {
|
| 19 |
std::string peeraddr = channel->peeraddr();
|
| 20 |
if (channel->isConnected()) {
|
| 21 |
-
spdlog::info("connected to
|
| 22 |
if (wait_send_buf.getDataSize() > 0)
|
| 23 |
{
|
| 24 |
cli.send(wait_send_buf.getData(), wait_send_buf.getDataSize());
|
| 25 |
}
|
| 26 |
} else {
|
| 27 |
-
spdlog::info("disconnected to
|
| 28 |
hio_close(io);
|
| 29 |
}
|
| 30 |
};
|
|
@@ -38,6 +38,7 @@ class TcpClientShell {
|
|
| 38 |
|
| 39 |
};
|
| 40 |
cli.start();
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
int send(const char* data, int size) {
|
|
@@ -61,12 +62,12 @@ class TcpClientShell {
|
|
| 61 |
};
|
| 62 |
|
| 63 |
static void tcp_on_close(hio_t* io) {
|
| 64 |
-
spdlog::info("tcp_on_close fd
|
| 65 |
ConnMap<hio_t*, TcpClientShell>::getInstance().remove(io);
|
| 66 |
}
|
| 67 |
|
| 68 |
static void tcp_on_recv(hio_t* io, void* buf, int readbytes) {
|
| 69 |
-
spdlog::info("tcp_on_recv fd
|
| 70 |
hio_write(io, buf, readbytes);
|
| 71 |
auto cli = ConnMap<hio_t*, TcpClientShell>::getInstance().get(io);
|
| 72 |
if(cli) {
|
|
@@ -79,7 +80,7 @@ void tcp_on_accept(hio_t* io, hevent_t* ev) {
|
|
| 79 |
|
| 80 |
char localaddrstr[SOCKADDR_STRLEN] = {0};
|
| 81 |
char peeraddrstr[SOCKADDR_STRLEN] = {0};
|
| 82 |
-
spdlog::info("tcp_on_accept tid=%ld connfd
|
| 83 |
(long)hv_gettid(),
|
| 84 |
(int)hio_fd(io),
|
| 85 |
SOCKADDR_STR(hio_localaddr(io), localaddrstr),
|
|
|
|
| 13 |
io = _io;
|
| 14 |
int connfd = cli.createsocket(hio_peeraddr(io));
|
| 15 |
if (connfd < 0) {
|
| 16 |
+
return false;
|
| 17 |
}
|
| 18 |
cli.onConnection = [this](const hv::SocketChannelPtr& channel) {
|
| 19 |
std::string peeraddr = channel->peeraddr();
|
| 20 |
if (channel->isConnected()) {
|
| 21 |
+
spdlog::info("connected to {:s}! connfd={:d}\n", peeraddr.c_str(), channel->fd());
|
| 22 |
if (wait_send_buf.getDataSize() > 0)
|
| 23 |
{
|
| 24 |
cli.send(wait_send_buf.getData(), wait_send_buf.getDataSize());
|
| 25 |
}
|
| 26 |
} else {
|
| 27 |
+
spdlog::info("disconnected to {:s}! connfd={:d}\n", peeraddr.c_str(), channel->fd());
|
| 28 |
hio_close(io);
|
| 29 |
}
|
| 30 |
};
|
|
|
|
| 38 |
|
| 39 |
};
|
| 40 |
cli.start();
|
| 41 |
+
return true;
|
| 42 |
}
|
| 43 |
|
| 44 |
int send(const char* data, int size) {
|
|
|
|
| 62 |
};
|
| 63 |
|
| 64 |
static void tcp_on_close(hio_t* io) {
|
| 65 |
+
spdlog::info("tcp_on_close fd={:d} error={:d}\n", hio_fd(io), hio_error(io));
|
| 66 |
ConnMap<hio_t*, TcpClientShell>::getInstance().remove(io);
|
| 67 |
}
|
| 68 |
|
| 69 |
static void tcp_on_recv(hio_t* io, void* buf, int readbytes) {
|
| 70 |
+
spdlog::info("tcp_on_recv fd={:d} buf({:d})={:s}\n", hio_fd(io), readbytes, buf);
|
| 71 |
hio_write(io, buf, readbytes);
|
| 72 |
auto cli = ConnMap<hio_t*, TcpClientShell>::getInstance().get(io);
|
| 73 |
if(cli) {
|
|
|
|
| 80 |
|
| 81 |
char localaddrstr[SOCKADDR_STRLEN] = {0};
|
| 82 |
char peeraddrstr[SOCKADDR_STRLEN] = {0};
|
| 83 |
+
spdlog::info("tcp_on_accept tid=%ld connfd={:d} [{:s}] <= [{:s}]\n",
|
| 84 |
(long)hv_gettid(),
|
| 85 |
(int)hio_fd(io),
|
| 86 |
SOCKADDR_STR(hio_localaddr(io), localaddrstr),
|