Skip to content

Commit

Permalink
Merge pull request #280 from sipcapture/exit_eof
Browse files Browse the repository at this point in the history
added exit on end of file
  • Loading branch information
lmangani authored Mar 12, 2024
2 parents 04e5b6d + 6152c67 commit e5add21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type InterfacesConfig struct {
ReadSpeed bool `config:"top_speed"`
OneAtATime bool `config:"one_at_a_time"`
Loop int `config:"loop"`
EOFExit bool `config:"eof_exit"`
FanoutID uint `config:"fanout_id"`
FanoutWorker int `config:"fanout_worker"`
CustomBPF string `config:"custom_bpf"`
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/sipcapture/heplify/sniffer"
)

const version = "heplify 1.66.1"
const version = "heplify 1.66.2"

func createFlags() {

Expand Down Expand Up @@ -82,6 +82,7 @@ func createFlags() {
flag.IntVar(&ifaceConfig.RotationTime, "rt", 60, "Pcap rotation time in minutes")
flag.BoolVar(&config.Cfg.Zip, "zf", false, "Enable pcap compression")
flag.IntVar(&ifaceConfig.Loop, "lp", 1, "Loop count over ReadFile. Use 0 to loop forever")
flag.BoolVar(&ifaceConfig.EOFExit, "eof-exit", false, "Exit on EOF of ReadFile")
flag.BoolVar(&ifaceConfig.ReadSpeed, "rs", false, "Use packet timestamps with maximum pcap read speed")
flag.StringVar(&ifaceConfig.PortRange, "pr", "5060-5090", "Portrange to capture SIP")
flag.BoolVar(&sys, "sl", false, "Log to syslog")
Expand Down
7 changes: 7 additions & 0 deletions sniffer/sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,14 @@ LOOP:
}

if err == io.EOF {

logp.Debug("sniffer", "End of file")

if sniffer.config.EOFExit {
sniffer.Close()
os.Exit(0)
}

loopCount++
if sniffer.config.Loop > 0 && loopCount > sniffer.config.Loop {
// Give the publish goroutine 200 ms to flush
Expand Down

0 comments on commit e5add21

Please sign in to comment.