Skip to content

Commit cc647bb

Browse files
committed
Replace 3.39.8 with new release 3.39.9
Small changes since 3.39.7
1 parent b058cf3 commit cc647bb

File tree

6 files changed

+28
-35
lines changed

6 files changed

+28
-35
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image:
22
- Visual Studio 2013
33

4-
version: 3.39.8.{build}
4+
version: 3.39.9.{build}
55

66
environment:
77
global:

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
yasio-3.39.8
1+
yasio-3.39.9
22

33
1. Remove unsafe option: `YOPT_S_FORWARD_EVENT`, may cause internal channel behavior incorrect.
44
2. Add forward packet event support, new option: `YOPT_S_FORWARD_PACKET`, after enable forward packet:
@@ -8,6 +8,8 @@ yasio-3.39.8
88
- No deferred packet
99
- No GC alloc
1010
3. Fix `sort_timers` may cause `std::sort` crash on sort callback when system clock slow
11+
4. Fix typo `YASIO_ENABLE_PASSIVE_EVENT`
12+
5. Fix timer queue empty check
1113

1214
yasio-3.39.7
1315

yasio.pc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ includedir=${exec_prefix}/include
55

66
Name: yasio
77
Description: A multi-platform support c++11 library with focus on asio (asynchronous socket I/O) for any client application.
8-
Version: 3.39.8
8+
Version: 3.39.9
99
Libs: -L${libdir}
1010
Cflags: -I${includedir}/yasio

yasio/detail/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ SOFTWARE.
198198
/*
199199
** The yasio version macros
200200
*/
201-
#define YASIO_VERSION_NUM 0x033908
201+
#define YASIO_VERSION_NUM 0x033909
202202

203203
/*
204204
** The macros used by io_service.

yasio/yasio.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,10 @@ static yasio__global_state& yasio__shared_globals(const print_fn2_t& prt = nullp
187187
void highp_timer::async_wait(io_service& service, timer_cb_t cb) { service.schedule_timer(this, std::move(cb)); }
188188
void highp_timer::cancel(io_service& service)
189189
{
190-
if (!expired(service))
190+
if (!expired())
191191
service.remove_timer(this);
192192
}
193193

194-
std::chrono::microseconds highp_timer::wait_duration(io_service& service) const
195-
{
196-
return std::chrono::duration_cast<std::chrono::microseconds>(this->expire_time_ - service.time_);
197-
}
198-
199194
/// io_send_op
200195
int io_send_op::perform(io_transport* transport, const void* buf, int n, int& error) { return transport->write_cb_(buf, n, nullptr, error); }
201196

@@ -894,12 +889,10 @@ void io_service::run()
894889
// The core event loop
895890
fd_set_adapter fd_set; // The temp file descriptor set
896891

897-
// Init time for 1st loop
898-
update_time();
899-
900892
do
901893
{
902-
fd_set = this->fd_set_;
894+
fd_set = this->fd_set_;
895+
903896
const auto waitd_usec = get_timeout(this->wait_duration_); // Gets current wait duration
904897
#if defined(YASIO_HAVE_CARES)
905898
/**
@@ -940,8 +933,6 @@ void io_service::run()
940933
}
941934
}
942935

943-
update_time();
944-
945936
#if defined(YASIO_HAVE_CARES)
946937
// process events for name resolution.
947938
do_ares_process_fds(ares_socks, ares_nfds, fd_set);
@@ -1653,7 +1644,7 @@ bool io_service::do_read(transport_handle_t transport, fd_set_adapter& fd_set)
16531644
int n = transport->do_read(revent, error, this->wait_duration_);
16541645
if (n >= 0)
16551646
{
1656-
if (!options_.forward_event_ && !options_.forward_packet_)
1647+
if (!options_.forward_packet_)
16571648
{
16581649
YASIO_KLOGV("[index: %d] do_read status ok, bytes transferred: %d, buffer used: %d", transport->cindex(), n, n + transport->offset_);
16591650
if (transport->expected_size_ == -1)
@@ -1800,7 +1791,7 @@ void io_service::process_timers()
18001791
while (!this->timer_queue_.empty())
18011792
{
18021793
auto timer_ctl = timer_queue_.back().first;
1803-
if (timer_ctl->expired(*this))
1794+
if (timer_ctl->expired())
18041795
{
18051796
// fetch timer
18061797
auto timer_impl = std::move(timer_queue_.back());
@@ -1830,7 +1821,7 @@ highp_time_t io_service::get_timeout(highp_time_t usec)
18301821
if (!this->timer_queue_.empty())
18311822
{
18321823
// microseconds
1833-
auto duration = timer_queue_.back().first->wait_duration(*this);
1824+
auto duration = timer_queue_.back().first->wait_duration();
18341825
if (std::chrono::microseconds(usec) > duration)
18351826
usec = duration.count();
18361827
}

yasio/yasio.hpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ enum
174174
// b. IPv6 addresses with ports require square brackets [fe80::1%lo0]:53
175175
YOPT_S_DNS_LIST,
176176

177-
178177
// Set ssl server cert and private key file
179178
// params:
180179
// crtfile: const char*
@@ -400,10 +399,10 @@ class YASIO_API highp_timer {
400399
void expires_from_now(const std::chrono::microseconds& duration)
401400
{
402401
this->duration_ = duration;
403-
this->expire_time_ = yasio::steady_clock_t::now() + this->duration_;
402+
this->expire_time_ = steady_clock_t::now() + this->duration_;
404403
}
405404

406-
void expires_from_now() { this->expire_time_ = yasio::steady_clock_t::now() + this->duration_; }
405+
void expires_from_now() { this->expire_time_ = steady_clock_t::now() + this->duration_; }
407406

408407
// Wait timer timeout once.
409408
void async_wait_once(io_service& service, timerv_cb_t cb)
@@ -428,13 +427,17 @@ class YASIO_API highp_timer {
428427
YASIO__DECL void cancel(io_service& service);
429428

430429
// Check if timer is expired?
431-
bool expired(io_service& service) const { return this->wait_duration(service).count() <= 0; }
430+
bool expired() const { return wait_duration().count() <= 0; }
432431

433432
// Gets wait duration of timer.
434-
YASIO__DECL std::chrono::microseconds wait_duration(io_service& service) const;
433+
std::chrono::microseconds wait_duration() const { return this->wait_duration(steady_clock_t::now()); }
434+
std::chrono::microseconds wait_duration(const std::chrono::time_point<steady_clock_t>& now_time) const
435+
{
436+
return std::chrono::duration_cast<std::chrono::microseconds>(this->expire_time_ - now_time);
437+
}
435438

436-
std::chrono::microseconds duration_ = {};
437-
std::chrono::time_point<yasio::steady_clock_t> expire_time_ = {};
439+
std::chrono::microseconds duration_ = {};
440+
std::chrono::time_point<steady_clock_t> expire_time_ = {};
438441
};
439442

440443
struct YASIO_API io_base {
@@ -1058,8 +1061,11 @@ class YASIO_API io_service // lgtm [cpp/class-many-fields]
10581061
}
10591062
void sort_timers()
10601063
{
1061-
std::sort(this->timer_queue_.begin(), this->timer_queue_.end(),
1062-
[](const timer_impl_t& lhs, const timer_impl_t& rhs) { return lhs.first->expire_time_ > rhs.first->expire_time_; });
1064+
// Must ensure time now stable, otherwise will cause std::sort pass invalid iterator to sort callback
1065+
const auto now_time = steady_clock_t::now();
1066+
std::sort(this->timer_queue_.begin(), this->timer_queue_.end(), [&now_time](const timer_impl_t& lhs, const timer_impl_t& rhs) {
1067+
return lhs.first->wait_duration(now_time) > rhs.first->wait_duration(now_time);
1068+
});
10631069
}
10641070

10651071
// Start a async domain name query
@@ -1128,7 +1134,7 @@ class YASIO_API io_service // lgtm [cpp/class-many-fields]
11281134
inline void fire_event(_Types&&... args)
11291135
{
11301136
auto event = cxx14::make_unique<io_event>(std::forward<_Types>(args)...);
1131-
if (options_.deferred_event_ && !options_.forward_event_)
1137+
if (options_.deferred_event_)
11321138
{
11331139
if (options_.on_defer_event_ && !options_.on_defer_event_(event))
11341140
return;
@@ -1169,16 +1175,11 @@ class YASIO_API io_service // lgtm [cpp/class-many-fields]
11691175
/* For log macro only */
11701176
inline const print_fn2_t& __get_cprint() const { return options_.print_; }
11711177

1172-
void update_time() { this->time_ = yasio::steady_clock_t::now(); }
1173-
11741178
private:
11751179
state state_ = state::UNINITIALIZED; // The service state
11761180
std::thread worker_;
11771181
std::thread::id worker_id_;
11781182

1179-
/* The current time according to the event loop. in msecs. */
1180-
std::chrono::time_point<yasio::steady_clock_t> time_;
1181-
11821183
privacy::concurrent_queue<event_ptr, true> events_;
11831184

11841185
std::vector<io_channel*> channels_;
@@ -1213,7 +1214,6 @@ class YASIO_API io_service // lgtm [cpp/class-many-fields]
12131214
bool deferred_event_ = true;
12141215
defer_event_cb_t on_defer_event_;
12151216

1216-
bool forward_event_ = false; // since v3.39.7
12171217
bool forward_packet_ = false; // since v3.39.8
12181218

12191219
// tcp keepalive settings

0 commit comments

Comments
 (0)