diff options
author | Andrea Barberio <insomniac@slackware.it> | 2019-05-08 11:49:26 +0100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-05-08 13:48:24 +0100 |
commit | 7f47189c0d8f5c8b06ab1787a94506fbb673e6e0 (patch) | |
tree | 54f3cdc124385c3f6ef57f029415aedf1fdacec0 /dhcpv6/async | |
parent | c781bfa866afb5cac93f2fcbb5ef9da53a486087 (diff) |
Addressed more linter warnings
Mostly addressed missing error checking.
Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Diffstat (limited to 'dhcpv6/async')
-rw-r--r-- | dhcpv6/async/client.go | 19 | ||||
-rw-r--r-- | dhcpv6/async/client_test.go | 8 |
2 files changed, 20 insertions, 7 deletions
diff --git a/dhcpv6/async/client.go b/dhcpv6/async/client.go index b2f977f..8a7fbff 100644 --- a/dhcpv6/async/client.go +++ b/dhcpv6/async/client.go @@ -3,6 +3,7 @@ package async import ( "context" "fmt" + "log" "net" "sync" "time" @@ -143,14 +144,20 @@ func (c *Client) send(packet dhcpv6.DHCPv6) { raddr, err := c.remoteAddr() if err != nil { - p.Reject(err) + _ = p.Reject(err) + log.Printf("Warning: cannot get remote address :%v", err) return } - c.connection.SetWriteDeadline(time.Now().Add(c.WriteTimeout)) + if err := c.connection.SetWriteDeadline(time.Now().Add(c.WriteTimeout)); err != nil { + _ = p.Reject(err) + 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 } @@ -163,7 +170,9 @@ func (c *Client) receive(_ dhcpv6.DHCPv6) { received dhcpv6.DHCPv6 ) - 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 read deadline :%v", err) + } for { buffer := make([]byte, client6.MaxUDPReceivedPacketSize) n, _, _, _, err := c.connection.ReadMsgUDP(buffer, oobdata) @@ -190,7 +199,7 @@ func (c *Client) receive(_ dhcpv6.DHCPv6) { c.packetsLock.Lock() if p, ok := c.packets[transactionID]; ok { delete(c.packets, transactionID) - p.Resolve(received) + _ = p.Resolve(received) } c.packetsLock.Unlock() } diff --git a/dhcpv6/async/client_test.go b/dhcpv6/async/client_test.go index 8603248..14b8026 100644 --- a/dhcpv6/async/client_test.go +++ b/dhcpv6/async/client_test.go @@ -37,7 +37,9 @@ func serve(ctx context.Context, addr *net.UDPAddr, response dhcpv6.DHCPv6) error 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 @@ -46,7 +48,9 @@ func serve(ctx context.Context, addr *net.UDPAddr, response dhcpv6.DHCPv6) error 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 |