Skip to content

Commit

Permalink
close connections in packetgen
Browse files Browse the repository at this point in the history
  • Loading branch information
arriven committed Apr 17, 2022
1 parent c6e8254 commit 8012b6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/packetgen/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func OpenConnection(ctx context.Context, c ConnectionConfig) (Connection, error)

type Connection interface {
Write(Packet) (int, error)
Close() error
Target() string
}

Expand Down Expand Up @@ -103,6 +104,10 @@ func (conn *rawConn) Write(packet Packet) (n int, err error) {
return conn.PacketConn.WriteTo(payloadBuf.Bytes(), nil, &net.IPAddr{IP: packet.IP()})
}

func (conn *rawConn) Close() error {
return conn.PacketConn.Close()
}

func (conn *rawConn) Target() string { return conn.target }

type netConnConfig struct {
Expand Down Expand Up @@ -170,4 +175,8 @@ func (conn *netConn) Write(packet Packet) (n int, err error) {
return conn.Conn.Write(payloadBuf.Bytes())
}

func (conn *netConn) Close() error {
return conn.Conn.Close()
}

func (conn *netConn) Target() string { return conn.target }
1 change: 1 addition & 0 deletions src/job/packetgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func sendPacket(ctx context.Context, logger *zap.Logger, jobConfig *packetgenJob
if err != nil {
return err
}
defer conn.Close()

for jobConfig.Next(ctx) {
packetTpl, more := <-packetsChan
Expand Down

0 comments on commit 8012b6c

Please sign in to comment.