Should the caller consume partial events returned by io_getevents(2) due to interrupt

As per the documentation of io_getevents(2),

On success, io_getevents() returns the number of events read.
This may be 0, or a value less than min_nr, if the timeout
expired. It may also be a nonzero value less than min_nr, if the
call was interrupted by a signal handler.

It indicates in case of error EINTR call may returns partial events. But it not clear if we are supposed to consume the partially returned events or let the call retry unless it returns at least min_nr event that was expected in successful case?

Are we supposed to consume the partially returned events something like as following which is similar to what happens in case of read() call?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>ssize_t io_wait_for_events(io_context_t ctx, struct io_event *events, int min_nr, int max_nr) {
ssize_t num_events = 0;
do {
// Attempt to fetch events (it may return fewer than min_nr if interrupted)
num_events = io_getevents(ctx, min_nr, max_nr, events, nullptr);
if (num_events >= 0) {
// Process the successfully retrieved events
if (num_events > 0) {
process_events(events, num_events); // Handle partially retrieved events
}
// Check if we need to retry for more events
if (num_events < min_nr) {
min_nr -= num_events; // Adjust the number of remaining events we need
events += num_events; // Move the pointer forward
}
} else if (num_events == -EINTR) {
// Retry if we were interrupted by a signal (no valid events retrieved)
continue;
} else {
// Handle other potential errors from io_getevents
std::cerr << "Error in io_getevents: " << strerror(-num_events) << std::endl;
return num_events;
}
} while (num_events < min_nr); // Continue until we get at least min_nr events
return num_events;
}
</code>
<code>ssize_t io_wait_for_events(io_context_t ctx, struct io_event *events, int min_nr, int max_nr) { ssize_t num_events = 0; do { // Attempt to fetch events (it may return fewer than min_nr if interrupted) num_events = io_getevents(ctx, min_nr, max_nr, events, nullptr); if (num_events >= 0) { // Process the successfully retrieved events if (num_events > 0) { process_events(events, num_events); // Handle partially retrieved events } // Check if we need to retry for more events if (num_events < min_nr) { min_nr -= num_events; // Adjust the number of remaining events we need events += num_events; // Move the pointer forward } } else if (num_events == -EINTR) { // Retry if we were interrupted by a signal (no valid events retrieved) continue; } else { // Handle other potential errors from io_getevents std::cerr << "Error in io_getevents: " << strerror(-num_events) << std::endl; return num_events; } } while (num_events < min_nr); // Continue until we get at least min_nr events return num_events; } </code>
ssize_t io_wait_for_events(io_context_t ctx, struct io_event *events, int min_nr, int max_nr) {
    ssize_t num_events = 0;
    do {
        // Attempt to fetch events (it may return fewer than min_nr if interrupted)
        num_events = io_getevents(ctx, min_nr, max_nr, events, nullptr);
        
        if (num_events >= 0) {
            // Process the successfully retrieved events
            if (num_events > 0) {
                process_events(events, num_events);  // Handle partially retrieved events
            }

            // Check if we need to retry for more events
            if (num_events < min_nr) {
                min_nr -= num_events; // Adjust the number of remaining events we need
                events += num_events; // Move the pointer forward
            }

        } else if (num_events == -EINTR) {
            // Retry if we were interrupted by a signal (no valid events retrieved)
            continue;

        } else {
            // Handle other potential errors from io_getevents
            std::cerr << "Error in io_getevents: " << strerror(-num_events) << std::endl;
            return num_events;
        }
    } while (num_events < min_nr);  // Continue until we get at least min_nr events
    
    return num_events;
}

It gets even more confusing when looking at the manual of io_getevents(3) that doesn’t even mention what happens in case of call is interrupted. What does one supposed to do if using libaio based wrapper APIs ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật