M0r13n / pyais

AIS message decoding and encoding in Python (AIVDM/AIVDO)
MIT License
176 stars 61 forks source link

Expose stream close method and make udp-receiver socket optional reusable #148

Closed mib1185 closed 3 weeks ago

mib1185 commented 1 month ago

This will expose the self._fobj.close() as close() method, so we can close the stream even without running in a context manager. Further the udp listener socket can be set to be reusable, which helps in case of a fast close and reopen (reuse) of the same listener socket - eq. when the application restarts.

M0r13n commented 3 weeks ago

Hi @mib1185, looks good to me. However, there was a missing import statement, which caused some tests to fail. I have fixed this issue, and the changes are now available in version 2.7.1.

mib1185 commented 3 weeks ago

Hi @M0r13n yeah I already recognized my fault (see https://github.com/M0r13n/pyais/commit/59e223044de72bde5e0e412257043f8b0866e598#r145478945) :see_no_evil: Thanks for reviewing and merging this :slightly_smiling_face:

M0r13n commented 3 weeks ago

Hey @mib1185,

There was another issue with your PR. It causes an import error on Windows because the socket option for reusable sockets isn't available on that platform. Due to this, I decided to partially revert your changes. You can still set the socket options after creating a streaming instance (the socket attribute is public). I also yanked the faulty release from PyPI.

mib1185 commented 3 weeks ago

Hi @M0r13n thanks for informing me about this! OK, than I'll try to set these options afterwards direct in the socket property 👍