From 022e2c3afee3b5ded7173d30584af2431b15dbd7 Mon Sep 17 00:00:00 2001 From: Tatsushi Demachi Date: Sun, 25 Oct 2015 14:47:07 +0900 Subject: [PATCH] Remove packet struct The recv channel isn't used anymore so it doesn't need to pack received packet bytes and a remote address into a packet struct. This removes packet struct, fixes procRecv arguments and so on. --- fastping.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/fastping.go b/fastping.go index 2a79593..2271078 100644 --- a/fastping.go +++ b/fastping.go @@ -110,11 +110,6 @@ func numGoRoutines() int { return runtime.NumCPU() * 4 } -type packet struct { - bytes []byte - addr net.Addr -} - type context struct { stop chan bool done chan bool @@ -642,13 +637,13 @@ func (p *Pinger) recvICMP(conn *icmp.PacketConn, ctx *context, wg *sync.WaitGrou } } } - p.procRecv(&packet{bytes: bytes, addr: ra}) + p.procRecv(bytes, ra) } } -func (p *Pinger) procRecv(recv *packet) { +func (p *Pinger) procRecv(bytes []byte, ra net.Addr) { var ipaddr *net.IPAddr - switch adr := recv.addr.(type) { + switch adr := ra.(type) { case *net.IPAddr: ipaddr = adr case *net.UDPAddr: @@ -665,17 +660,13 @@ func (p *Pinger) procRecv(recv *packet) { } p.mu.Unlock() - var bytes []byte var proto int if isIPv4(ipaddr.IP) { if p.network == "ip" { - bytes = ipv4Payload(recv.bytes) - } else { - bytes = recv.bytes + bytes = ipv4Payload(bytes) } proto = ProtocolICMP } else if isIPv6(ipaddr.IP) { - bytes = recv.bytes proto = ProtocolIPv6ICMP } else { return