diff options
Diffstat (limited to 'dhcpv4/async')
-rw-r--r-- | dhcpv4/async/client.go | 18 | ||||
-rw-r--r-- | dhcpv4/async/client_test.go | 8 |
2 files changed, 19 insertions, 7 deletions
diff --git a/dhcpv4/async/client.go b/dhcpv4/async/client.go index 4c2d3c1..54b500d 100644 --- a/dhcpv4/async/client.go +++ b/dhcpv4/async/client.go @@ -3,6 +3,7 @@ package async import ( "context" "fmt" + "log" "net" "sync" "time" @@ -138,14 +139,18 @@ func (c *Client) send(packet *dhcpv4.DHCPv4) { raddr, err := c.remoteAddr() if err != nil { - p.Reject(err) + _ = p.Reject(err) return } - c.connection.SetWriteDeadline(time.Now().Add(c.WriteTimeout)) + if err := c.connection.SetWriteDeadline(time.Now().Add(c.WriteTimeout)); err != nil { + log.Printf("Warning: cannot set write deadline: %v", err) + return + } _, err = c.connection.WriteTo(packet.ToBytes(), raddr) if err != nil { - p.Reject(err) + _ = p.Reject(err) + log.Printf("Warning: cannot write to %s: %v", raddr, err) return } @@ -158,7 +163,10 @@ func (c *Client) receive(_ *dhcpv4.DHCPv4) { received *dhcpv4.DHCPv4 ) - c.connection.SetReadDeadline(time.Now().Add(c.ReadTimeout)) + if err := c.connection.SetReadDeadline(time.Now().Add(c.ReadTimeout)); err != nil { + log.Printf("Warning: cannot set write deadline: %v", err) + return + } for { buffer := make([]byte, client4.MaxUDPReceivedPacketSize) n, _, _, _, err := c.connection.ReadMsgUDP(buffer, oobdata) @@ -177,7 +185,7 @@ func (c *Client) receive(_ *dhcpv4.DHCPv4) { c.packetsLock.Lock() if p, ok := c.packets[received.TransactionID]; ok { delete(c.packets, received.TransactionID) - p.Resolve(received) + _ = p.Resolve(received) } c.packetsLock.Unlock() } diff --git a/dhcpv4/async/client_test.go b/dhcpv4/async/client_test.go index b134afe..2269d57 100644 --- a/dhcpv4/async/client_test.go +++ b/dhcpv4/async/client_test.go @@ -26,7 +26,9 @@ func serve(ctx context.Context, addr *net.UDPAddr, response *dhcpv4.DHCPv4) erro case <-ctx.Done(): return default: - conn.SetReadDeadline(time.Now().Add(1 * time.Second)) + if err := conn.SetReadDeadline(time.Now().Add(1 * time.Second)); err != nil { + panic(err) + } n, _, _, src, err := conn.ReadMsgUDP(buffer, oobdata) if err != nil { continue @@ -35,7 +37,9 @@ func serve(ctx context.Context, addr *net.UDPAddr, response *dhcpv4.DHCPv4) erro if err != nil { continue } - conn.SetWriteDeadline(time.Now().Add(1 * time.Second)) + if err := conn.SetWriteDeadline(time.Now().Add(1 * time.Second)); err != nil { + panic(err) + } _, err = conn.WriteTo(response.ToBytes(), src) if err != nil { continue |