From 4ca7e7b82651009473ab23a8a24bf7f5700f61bd Mon Sep 17 00:00:00 2001 From: "Dolf Schimmel (Freeaqingme)" Date: Sun, 3 Apr 2016 20:48:59 +0200 Subject: [PATCH] Allow to abort scanning a stream prematurely --- clamd.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/clamd.go b/clamd.go index 92fe235..5199f63 100644 --- a/clamd.go +++ b/clamd.go @@ -258,12 +258,22 @@ the actual chunk. Streaming is terminated by sending a zero-length chunk. Note: do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will reply with INSTREAM size limit exceeded and close the connection */ -func (c *Clamd) ScanStream(r io.Reader) (chan *ScanResult, error) { +func (c *Clamd) ScanStream(r io.Reader, abort chan bool) (chan *ScanResult, error) { conn, err := c.newConnection() if err != nil { return nil, err } + go func() { + for { + _, allowRunning := <-abort + if !allowRunning { + break + } + } + conn.Close() + }() + conn.sendCommand("INSTREAM") for {