Skip to content

Commit

Permalink
set reuse address for udp reader
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Nov 7, 2024
1 parent 7229915 commit 7cc2d6b
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions server/handler/udpreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def canDeleteHandler(cls):

def __init__(self,param):
self.socket=None
self.mcinterfaces=[]
AVNWorker.__init__(self, param)

def updateConfig(self, param, child=None):
Expand All @@ -97,7 +96,6 @@ def checkConfig(self, param):
self.checkUsedResource(UsedResource.T_UDP,self.P_PORT.fromDict(param))

def joinGroup(self,mcgroup):
self.mcinterfaces=[]
interfaces=netifaces.interfaces()
for intf in interfaces:
intfaddr=netifaces.ifaddresses(intf)
Expand All @@ -110,16 +108,8 @@ def joinGroup(self,mcgroup):
try:
mreq = struct.pack("4s4s", socket.inet_aton(mcgroup), socket.inet_aton(addr))
self.socket.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
self.mcinterfaces.append(mreq)
except:
pass
def leaveGroup(self):
for mreq in self.mcinterfaces:
try:
self.socket.setsockopt(socket.IPPROTO_IP,socket.IP_DROP_MEMBERSHIP,mreq)
except:
pass
self.mcinterfaces=[]

#thread run method - just try forever
def run(self):
Expand All @@ -133,11 +123,11 @@ def run(self):
self.claimUsedResource(UsedResource.T_UDP,self.getParamValue('port'))
self.setNameIfEmpty("%s-%s:%d" % (self.getName(), host, port))
info="unknown"
self.leaveGroup()
try:
info = "%s:%d" % (host,port)
self.setInfo(INAME,"trying udp listen at %s"%(info,),WorkerStatus.INACTIVE)
self.socket=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,True)
self.socket.bind((host, port))
if self.getWParam(self.P_ALLOWMC):
mcgroup=self.getWParam(self.P_MCADDR)
Expand All @@ -163,7 +153,7 @@ def run(self):
minTime=self.P_MINTIME.fromDict(self.param))
except:
AVNLog.info("exception while reading data from %s:%d %s",self.getStringParam('host'),self.getIntParam('port'),traceback.format_exc())
self.leaveGroup()

avnav_handlerList.registerHandler(AVNUdpReader)


Expand Down

0 comments on commit 7cc2d6b

Please sign in to comment.