Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select.poll() not supported on OSX #91

Open
ccsalway opened this issue Sep 8, 2018 · 1 comment
Open

select.poll() not supported on OSX #91

ccsalway opened this issue Sep 8, 2018 · 1 comment

Comments

@ccsalway
Copy link

ccsalway commented Sep 8, 2018

https://github.com/wichert/pyrad/blob/2d64523dcf1aedee672841b297570c37d291992b/example/server.py#L69

Traceback (most recent call last):
  File "/venv/lib/python2.7/site-packages/pyrad/server.py", line 300, in Run
    self._poll = select.poll()
AttributeError: 'module' object has no attribute 'poll'

This makes it impossible to develop on OSX :(

@ccsalway ccsalway changed the title Cannot start server AttributeError: 'module' object has no attribute 'poll' Sep 8, 2018
@ccsalway ccsalway changed the title AttributeError: 'module' object has no attribute 'poll' select.poll() not supported on OSX Sep 8, 2018
@ccsalway
Copy link
Author

ccsalway commented Sep 9, 2018

To make this work on OSX, I did the following (this wont work on Linux):

In server.py:

changed the Run method as follows:

def Run(self):
    self._kq = select.kqueue()
    self._fdmap = {}
    self._PrepareSockets()

    while True:
        revents = self._kq.control([], 1, None)
        for event in revents:
            if event.filter == select.KQ_FILTER_READ:
                try:
                    fd = event.ident
                    fdo = self._fdmap[fd]
                    self._ProcessInput(fdo)
                except ServerPacketError as err:
                    logger.info('Dropping packet: ' + str(err))
                except packet.PacketError as err:
                    logger.info('Received a broken packet: ' + str(err))
            else:
                logger.error('Unexpected event in server main loop')

changed the _PrepareSockets method as follows:

def _PrepareSockets(self):
    """Prepare all sockets to receive packets."""
    for fd in self.authfds + self.acctfds + self.coafds:
        self._fdmap[fd.fileno()] = fd
        ev = select.kevent(fd.fileno(),
                           filter=select.KQ_FILTER_READ,
                           flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE)
        self._kq.control([ev], 0, 0)
    if self.auth_enabled:
        self._realauthfds = list(map(lambda x: x.fileno(), self.authfds))
    if self.acct_enabled:
        self._realacctfds = list(map(lambda x: x.fileno(), self.acctfds))
    if self.coa_enabled:
        self._realcoafds = list(map(lambda x: x.fileno(), self.coafds))

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

No branches or pull requests

1 participant