Skip to content

Add read & write process_fd functions#245

Merged
saghul merged 2 commits intosaghul:masterfrom
Vizonex:add-read-write-process-fd-functions
Jul 19, 2025
Merged

Add read & write process_fd functions#245
saghul merged 2 commits intosaghul:masterfrom
Vizonex:add-read-write-process-fd-functions

Conversation

@Vizonex
Copy link
Contributor

@Vizonex Vizonex commented Jul 7, 2025

So recently I actually started to write my own cython version of this library and in doing so I came up with an idea to make it easier to use the socket callbacks. So instead of users needing to use ARES_SOCKET_BAD I made 2 functions that can be used to either process either a read or write file descriptor only. I'll be adding these changes to a future pull request to aiodns since the other reviewers didn't like that I accidently messed around with coverage. (I need to remember to close that pull request and open a new one if these changes get accepted and later updated)

Basically having these should allow users using an event loop to do something like this, this is what I wrote for my version of c-ares and I wanted aiodns to do the same with this library so that ARES_SOCKET_BAD doesn't have to be passed through to the different callbacks.

If you think I should add in sphinx doc strings to this library as well I would be happy to do so.

def _sock_state_cb(self, fd: int, readable: bool, writable: bool) -> None:
        if readable or writable:
            if readable:
                self.loop.add_reader(
                    fd, self._channel.process_read_fd, fd
                )
                self._read_fds.add(fd)
            if writable:
                self.loop.add_writer(
                    fd, self._channel.process_write_fd, fd
                )
                self._write_fds.add(fd)
            if self._timer is None:
                self._start_timer()

Copy link
Owner

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

@saghul saghul merged commit b66e535 into saghul:master Jul 19, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants