libp2p / go-reuseport

reuse tcp/udp ports in golang
ISC License
765 stars 108 forks source link

feat: add support for ListenUDP #93

Closed sruehl closed 2 years ago

sruehl commented 2 years ago

This PR adds support for the ListenUDP function of the net package

sruehl commented 2 years ago

multicast and broadcast http://www.kohala.com/start/mcast.api.txt

sruehl commented 2 years ago

the doc of net.ListenUDP excludes multi cast. So not sure if that includes broadcast messages. In that case this PR would be indeed useless...

sruehl commented 2 years ago

ok nvm that PR is non-sense, sorry for the inconvenience

sruehl commented 2 years ago

for those who find this by google: you can cast the packetCon to a udpCon:

packetConn, err := reuseport.ListenPacket("udp","192.168.178.255:47808")
udpConn := packetConn.(*net.UDPConn)
sot-tech commented 2 years ago

Hello.

Can you tell us about your use case?

UDP server, which reached limit of using event loop (for { ... sock.ReadFrom(*bytea) ... }) for incoming datagrams.

How does this work? If I'm listening on the same local address twice, how does the kernel know which listener to deliver the packets to?

Connection for certain protocol (i.e. UDP) identified by tuple of 4 values: src address, src port, dst address, dst port, so if you're listening same endpoint twice with REUSE*, but there are two peers with different src addresses and/or ports, kernel will (well... should) route them to diferrent listeners.

Just FYI, @sruehl's workaround with assertion works fine.