Ticket #454: udpbroadcast-fix.patch

File udpbroadcast-fix.patch, 1.9 KB (added by hawkowl, 3 years ago)

Fixes to udpbroadcast.patch, for IOCP + TwistedChecker

  • twisted/internet/iocpreactor/udp.py

    diff --git twisted/internet/iocpreactor/udp.py twisted/internet/iocpreactor/udp.py
    index 4dec51f..cf30450 100644
    class Port(abstract.FileHandle): 
    275275        return address.IPv4Address('UDP', *self.socket.getsockname())
    276276
    277277
     278    def setBroadcastAllowed(self, enabled):
     279        """
     280        Set whether this UDP socket may broadcast. This is disabled by default.
     281
     282        @param enabled: Whether the socket may broadcast.
     283        @type enabled: C{bool}
     284        """
     285        self.socket.setsockopt(
     286            socket.SOL_SOCKET, socket.SO_BROADCAST, enabled)
     287
     288
     289    def getBroadcastAllowed(self):
     290        """
     291        Checks if broadcast is currently allowed.
     292
     293        @return: Whether this UDP socket may broadcast.
     294        @rtype: C{bool}
     295        """
     296        return operator.truth(
     297            self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST))
     298
     299
    278300
    279301class MulticastMixin:
    280302    """
  • twisted/internet/udp.py

    diff --git twisted/internet/udp.py twisted/internet/udp.py
    index b68f63d..7378b52 100644
    class Port(base.BasePort): 
    361361        @param enabled: Whether the socket may broadcast.
    362362        @type enabled: C{bool}
    363363        """
    364         if enabled == True: enabled_int = 1
    365         else: enabled_int = 0
    366364        self.socket.setsockopt(
    367             socket.SOL_SOCKET, socket.SO_BROADCAST, enabled_int)
     365            socket.SOL_SOCKET, socket.SO_BROADCAST, enabled)
    368366
    369367
    370368    def getBroadcastAllowed(self):
    371369        """
    372         Return whether this UDP socket may broadcast.
     370        Checks if broadcast is currently allowed.
     371
     372        @return: Whether this UDP socket may broadcast.
     373        @rtype: C{bool}
    373374        """
    374375        return operator.truth(
    375376            self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST))