Skip to content

Commit

Permalink
fix(plc4go): fix so_reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jun 23, 2022
1 parent e016585 commit fd0eddd
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions plc4go/internal/spi/transports/udp/Transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,19 @@ func (m *TransportInstance) Connect() error {

// "connect" to the remote
var err error
if m.SoReUse {
if m.udpConn, err = net.ListenUDP("udp", m.LocalAddress); err != nil {
if m.RemoteAddress != nil {
if m.udpConn, err = net.DialUDP("upd", m.LocalAddress, m.RemoteAddress); err != nil {
return errors.Wrap(err, "error connecting to remote address")
}
rawConn, err := m.udpConn.SyscallConn()
if err != nil {
return errors.Wrap(err, "Error getting syscall connection")
}
if err := reuseport.Control("", "", rawConn); err != nil {
return errors.Wrap(err, "Error setting re-use control")
} else if m.SoReUse {
if packetConn, err := reuseport.ListenPacket("udp", m.LocalAddress.String()); err != nil {
return errors.Wrap(err, "error connecting to local address")
} else {
m.udpConn = packetConn.(*net.UDPConn)
}
} else {
if m.udpConn, err = net.ListenUDP("udp", m.LocalAddress); err != nil {
return errors.Wrap(err, "error connecting to remote address")
return errors.Wrap(err, "error connecting to local address")
}
}

Expand Down

0 comments on commit fd0eddd

Please sign in to comment.