class ugcs::vsm::internal::Poll_io_controller

Overview

Linux-specific implementation for I/O controller. More…

#include <poll_io_controller.h>

class Poll_io_controller: public ugcs::vsm::File_processor::Native_controller
{
public:
    // structs

    struct Io_cb;

    // classes

    class File_desc;

    // methods

    virtual void Enable();
    virtual void Disable();
    virtual void Register_handle(File_processor::Stream::Native_handle&);
    virtual void Unregister_handle(File_processor::Stream::Native_handle&);
    void Delete_handle(int fd);
    bool Queue_operation(Io_cb& io_cb);
    bool Cancel_operation(Io_cb& io_cb);
};

Inherited Members

public:
    // methods

    virtual void Enable() = 0;
    virtual void Disable() = 0;
    virtual void Register_handle(Stream::Native_handle& handle) = 0;
    virtual void Unregister_handle(Stream::Native_handle& handle) = 0;
    static std::unique_ptr<Native_controller> Create();

Detailed Documentation

Linux-specific implementation for I/O controller.

Methods

virtual void Enable()

Enable the controller.

virtual void Disable()

Disable the controller.

virtual void Register_handle(File_processor::Stream::Native_handle&)

Register new opened file handle.

virtual void Unregister_handle(File_processor::Stream::Native_handle&)

Unregister previously registered file handle.

void Delete_handle(int fd)

Delete handle.

Possibly deferred. This is a workaround of kernel panic bug in OSX. The scenario: 1) create pipe with descriptors p1, p2. 2) open serial port with descriptor fd. 3) poll on two descriptors p1 and fd in separate thread. 4) issue write on p2. This triggers read event on p1 and wakes up poll(). 5) close(fd)

Results:

  • When (4) and (5) are close enough poll does not wake up and close(fd) blocks and triggers kernel panic. This does not happen 100% of time but if the above code is put into loop it takes ~20-100 iterations to trigger.

  • When (4) and (5) are >10ms apart the poll wakes up and close succeeds.

  • If close(fd) is called before write(p2) then I could not repeat the kernel panic. Solution:

Do not close the fd while it is in polling state. Close it after poll returns.

bool Queue_operation(Io_cb& io_cb)

Queue IO operation.

The provided callback is called when the operation completes with Io_cb structure filled.

Returns:

True if succeeded, false otherwise. Check errno for error code.

bool Cancel_operation(Io_cb& io_cb)

Cancel pending operation.

Parameters:

io_cb

Operation control block.

Returns:

True if cancelled, false if not cancelled (e.g. too late).