Commit f9576591 authored by captainwong's avatar captainwong

update

parent 0754f4e8
...@@ -159,12 +159,12 @@ struct simple_libevent_client::Impl ...@@ -159,12 +159,12 @@ struct simple_libevent_client::Impl
static void timercb(evutil_socket_t, short, void* user_data) static void timercb(evutil_socket_t, short, void* user_data)
{ {
simple_libevent_client* client = (simple_libevent_client*)user_data; simple_libevent_client* client = (simple_libevent_client*)user_data;
struct timeval tv = { 1, 0 };
if (client->strictTimer_) { if (client->strictTimer_) {
if (client->userData_ && client->onTimer_) { if (client->userData_ && client->onTimer_) {
client->onTimer_(client->userData_); client->onTimer_(client->userData_);
} }
struct timeval tv = { client->timeout_, 0 }; tv.tv_sec = client->timeout_;
event_add(event_new(client->impl_->base, -1, 0, Impl::timercb, client), &tv);
} else { } else {
auto now = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now();
auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - client->lastTimeSendData); auto diff = std::chrono::duration_cast<std::chrono::seconds>(now - client->lastTimeSendData);
...@@ -172,8 +172,12 @@ struct simple_libevent_client::Impl ...@@ -172,8 +172,12 @@ struct simple_libevent_client::Impl
if (client->userData_ && client->onTimer_) { if (client->userData_ && client->onTimer_) {
client->onTimer_(client->userData_); client->onTimer_(client->userData_);
} }
} else {
return;
}
} }
struct timeval tv = { 1, 0 };
if (client->connected_) {
client->impl_->timer = event_new(client->impl_->base, -1, 0, Impl::timercb, client); client->impl_->timer = event_new(client->impl_->base, -1, 0, Impl::timercb, client);
event_add(client->impl_->timer, &tv); event_add(client->impl_->timer, &tv);
} }
...@@ -181,6 +185,7 @@ struct simple_libevent_client::Impl ...@@ -181,6 +185,7 @@ struct simple_libevent_client::Impl
static void reconn_timercb(evutil_socket_t, short, void* user_data) static void reconn_timercb(evutil_socket_t, short, void* user_data)
{ {
AUTO_LOG_FUNCTION;
simple_libevent_client* client = (simple_libevent_client*)user_data; simple_libevent_client* client = (simple_libevent_client*)user_data;
do { do {
...@@ -220,6 +225,7 @@ struct simple_libevent_client::Impl ...@@ -220,6 +225,7 @@ struct simple_libevent_client::Impl
bool simple_libevent_client::start(const std::string& ip, uint16_t port, std::string& msg) bool simple_libevent_client::start(const std::string& ip, uint16_t port, std::string& msg)
{ {
AUTO_LOG_FUNCTION;
do { do {
stop(); stop();
...@@ -271,6 +277,7 @@ bool simple_libevent_client::start(const std::string& ip, uint16_t port, std::st ...@@ -271,6 +277,7 @@ bool simple_libevent_client::start(const std::string& ip, uint16_t port, std::st
void simple_libevent_client::stop() void simple_libevent_client::stop()
{ {
AUTO_LOG_FUNCTION;
std::lock_guard<std::mutex> lg(mutex_); std::lock_guard<std::mutex> lg(mutex_);
if (!impl_) { return; } if (!impl_) { return; }
......
...@@ -87,6 +87,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net", "net", "{FEAECF59-4F3 ...@@ -87,6 +87,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net", "net", "{FEAECF59-4F3
..\jlib\net\icmp_header.hpp = ..\jlib\net\icmp_header.hpp ..\jlib\net\icmp_header.hpp = ..\jlib\net\icmp_header.hpp
..\jlib\net\ipv4_header.hpp = ..\jlib\net\ipv4_header.hpp ..\jlib\net\ipv4_header.hpp = ..\jlib\net\ipv4_header.hpp
..\jlib\net\ping.h = ..\jlib\net\ping.h ..\jlib\net\ping.h = ..\jlib\net\ping.h
..\jlib\net\resolve_fastest_ip.h = ..\jlib\net\resolve_fastest_ip.h
..\jlib\net\simple_libevent_client.cpp = ..\jlib\net\simple_libevent_client.cpp
..\jlib\net\simple_libevent_client.h = ..\jlib\net\simple_libevent_client.h
..\jlib\net\simple_libevent_server.cpp = ..\jlib\net\simple_libevent_server.cpp
..\jlib\net\simple_libevent_server.h = ..\jlib\net\simple_libevent_server.h
EndProjectSection EndProjectSection
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util", "util", "{E13021FA-C9A3-4627-B7EF-16E97B7E2E14}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "util", "util", "{E13021FA-C9A3-4627-B7EF-16E97B7E2E14}"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment