From 6e6eb688d7a7b2e6861b35be851a51556024d46f Mon Sep 17 00:00:00 2001 From: evilsocket Date: Wed, 24 Jan 2018 13:40:08 +0100 Subject: [PATCH] refact: encapsulating synt.Mutex in packets.Queue struct --- packets/queue.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packets/queue.go b/packets/queue.go index 88864be1..cb2d8aa9 100644 --- a/packets/queue.go +++ b/packets/queue.go @@ -25,10 +25,11 @@ type Traffic struct { } type Queue struct { + sync.Mutex + iface *bnet.Endpoint handle *pcap.Handle source *gopacket.PacketSource - lock *sync.Mutex active bool Activities chan Activity `json:"-"` @@ -46,7 +47,6 @@ func NewQueue(iface *bnet.Endpoint) (*Queue, error) { q := &Queue{ iface: iface, handle: nil, - lock: &sync.Mutex{}, active: true, source: nil, Sent: 0, @@ -139,8 +139,8 @@ func (q *Queue) worker() { } func (q *Queue) Send(raw []byte) error { - q.lock.Lock() - defer q.lock.Unlock() + q.Lock() + defer q.Unlock() if q.active { err := q.handle.WritePacketData(raw) @@ -155,18 +155,9 @@ func (q *Queue) Send(raw []byte) error { } } -func (q *Queue) Lock() { - q.lock.Lock() -} - -func (q *Queue) Unlock() { - q.lock.Unlock() -} - func (q *Queue) Stop() { - q.lock.Lock() - defer q.lock.Unlock() - + q.Lock() + defer q.Unlock() q.handle.Close() q.active = false }