LCOV - code coverage report
Current view: top level - include/hpactor/net - reactor_backend.hpp (source / functions) Coverage Total Hit
Test: HPActor Coverage Lines: 100.0 % 1 1
Test Date: 2026-05-20 02:24:49 Functions: 50.0 % 2 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright 2026 HPActor Contributors
       2                 :             : #pragma once
       3                 :             : 
       4                 :             : #include <hpactor/net/async_io_fwd.hpp>
       5                 :             : 
       6                 :             : #include <sys/socket.h>
       7                 :             : #include <sys/uio.h>
       8                 :             : 
       9                 :             : namespace hpactor {
      10                 :             : namespace net {
      11                 :             : 
      12                 :             : enum class IoEvent : uint32_t {
      13                 :             :     Read = 1 << 0,
      14                 :             :     Write = 1 << 1,
      15                 :             : };
      16                 :             : 
      17                 :             : class IReactorBackend {
      18                 :             : public:
      19                 :          75 :     virtual ~IReactorBackend() = default;
      20                 :             : 
      21                 :             :     virtual bool start() = 0;
      22                 :             :     virtual void stop() = 0;
      23                 :             : 
      24                 :             :     virtual bool add_fd(int fd, IoEvent events) = 0;
      25                 :             :     virtual bool update_fd(int fd, IoEvent events) = 0;
      26                 :             :     virtual bool remove_fd(int fd) = 0;
      27                 :             : 
      28                 :             :     virtual int register_buffer(const void* addr, size_t len) = 0;
      29                 :             :     virtual bool unregister_buffer(int buffer_id) = 0;
      30                 :             : 
      31                 :             :     virtual uint64_t run_after(ActorId actor, int delay_ms) = 0;
      32                 :             :     virtual uint64_t run_every(ActorId actor, int interval_ms) = 0;
      33                 :             :     virtual void cancel_timer(uint64_t handle) = 0;
      34                 :             : 
      35                 :             :     virtual int wait(int timeout_ms) = 0;
      36                 :             :     virtual void process_events() = 0;
      37                 :             : 
      38                 :             :     // Proactor methods - used directly by connection code
      39                 :             :     virtual void async_send(int fd, const iovec* bufs, int buf_count,
      40                 :             :                             ActorId actor, uint32_t op_type) = 0;
      41                 :             :     virtual void async_recv(int fd, const iovec* bufs, int buf_count,
      42                 :             :                             ActorId actor, uint32_t op_type) = 0;
      43                 :             :     virtual void async_accept(int fd, ActorId actor) = 0;
      44                 :             :     virtual void async_connect(int fd, const sockaddr* addr, socklen_t addrlen,
      45                 :             :                                ActorId actor) = 0;
      46                 :             :     virtual void async_sendto(int fd, const iovec* bufs, int buf_count,
      47                 :             :                                const sockaddr* addr, socklen_t addrlen,
      48                 :             :                                ActorId actor, uint32_t op_type) = 0;
      49                 :             :     virtual void async_recvfrom(int fd, const iovec* bufs, int buf_count,
      50                 :             :                                 ActorId actor, uint32_t op_type) = 0;
      51                 :             : 
      52                 :             :     // Read handler management — reactor backends read data in wait() and
      53                 :             :     // dispatch via callback. Proactor backends use async_recv completions.
      54                 :             :     virtual void set_read_handler(int fd, read_callback handler) = 0;
      55                 :             :     virtual void clear_read_handler(int fd) = 0;
      56                 :             : 
      57                 :             :     // Returns true if this backend supports calling read handlers directly
      58                 :             :     // from wait(). Reactor backends (epoll, kqueue) return true.
      59                 :             :     // Proactor backends (io_uring, GCD) return false.
      60                 :             :     virtual bool supports_read_handler() const = 0;
      61                 :             : 
      62                 :             :     // Write handler management — reactor backends dispatch writable events
      63                 :             :     // via callback. Used for non-blocking connect completion.
      64                 :             :     virtual void set_write_handler(int fd, write_callback handler) = 0;
      65                 :             :     virtual void clear_write_handler(int fd) = 0;
      66                 :             :     virtual bool supports_write_handler() const = 0;
      67                 :             : };
      68                 :             : 
      69                 :             : } // namespace net
      70                 :             : } // namespace hpactor
        

Generated by: LCOV version 2.0-1