From 1f900a23c847753723ee31fbbea690e3e470d649 Mon Sep 17 00:00:00 2001 From: Dan Taras Date: Mon, 20 Jun 2022 11:39:52 +0200 Subject: [PATCH 1/5] Do not write header and close streams if they are not owned --- src/splitcap.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/splitcap.jl b/src/splitcap.jl index e52d32d..45d9508 100644 --- a/src/splitcap.jl +++ b/src/splitcap.jl @@ -30,7 +30,8 @@ function splitcap( reader::PcapReader, record2key, key2stream, - progress_callback = progress_noop_ + progress_callback = progress_noop_; + own_streams = true ) where {KeyType, StreamType} buffer_size = 1024 * 1024 * 2 max_pending_buffers = 4 @@ -46,7 +47,7 @@ function splitcap( output = get!(outputs, dst) do stream = key2stream(dst) buffer = sizehint!(UInt8[], buffer_size + 1500) - append!(buffer, reader.raw_header) + own_streams && append!(buffer, reader.raw_header) output = SplitCapOutput{StreamType}( buffer, Channel{Vector{UInt8}}(max_pending_buffers), @@ -79,8 +80,10 @@ function splitcap( sleep(0.1) end finally - for output in values(outputs) - close(output.stream) + if own_streams + for output in values(outputs) + close(output.stream) + end end end nothing @@ -90,9 +93,10 @@ function splitcap( reader::PcapReader, record2key, key2stream, - progress_callback = progress_noop_ + progress_callback = progress_noop_; + own_streams = true ) KeyType = strip_nothing_(Core.Compiler.return_type(record2key, (PcapRecord,))) StreamType = Core.Compiler.return_type(key2stream, (KeyType,)) - splitcap(KeyType, StreamType, reader, record2key, key2stream, progress_callback) + splitcap(KeyType, StreamType, reader, record2key, key2stream, progress_callback; own_streams) end From eb83b14da401e3bfcd105b4c9a6cf297d184d691 Mon Sep 17 00:00:00 2001 From: dantaras <47561995+dantaras@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:51:55 +0200 Subject: [PATCH 2/5] Update src/splitcap.jl Co-authored-by: Christian Rorvik --- src/splitcap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/splitcap.jl b/src/splitcap.jl index 45d9508..e16a57c 100644 --- a/src/splitcap.jl +++ b/src/splitcap.jl @@ -31,7 +31,7 @@ function splitcap( record2key, key2stream, progress_callback = progress_noop_; - own_streams = true + own_streams::Bool = true ) where {KeyType, StreamType} buffer_size = 1024 * 1024 * 2 max_pending_buffers = 4 From 37d78b0e2aeab81162ff0461f3ca189a24ca277d Mon Sep 17 00:00:00 2001 From: dantaras <47561995+dantaras@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:52:00 +0200 Subject: [PATCH 3/5] Update src/splitcap.jl Co-authored-by: Christian Rorvik --- src/splitcap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/splitcap.jl b/src/splitcap.jl index e16a57c..1ca806b 100644 --- a/src/splitcap.jl +++ b/src/splitcap.jl @@ -94,7 +94,7 @@ function splitcap( record2key, key2stream, progress_callback = progress_noop_; - own_streams = true + kwargs... ) KeyType = strip_nothing_(Core.Compiler.return_type(record2key, (PcapRecord,))) StreamType = Core.Compiler.return_type(key2stream, (KeyType,)) From 6f55fdfc02094805c3e68b70035370fefbda5467 Mon Sep 17 00:00:00 2001 From: dantaras <47561995+dantaras@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:52:05 +0200 Subject: [PATCH 4/5] Update src/splitcap.jl Co-authored-by: Christian Rorvik --- src/splitcap.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/splitcap.jl b/src/splitcap.jl index 1ca806b..0f7e04e 100644 --- a/src/splitcap.jl +++ b/src/splitcap.jl @@ -98,5 +98,5 @@ function splitcap( ) KeyType = strip_nothing_(Core.Compiler.return_type(record2key, (PcapRecord,))) StreamType = Core.Compiler.return_type(key2stream, (KeyType,)) - splitcap(KeyType, StreamType, reader, record2key, key2stream, progress_callback; own_streams) + splitcap(KeyType, StreamType, reader, record2key, key2stream, progress_callback; kwargs...) end From 6f46357edd2264f55bafccff8bd404cab7e4a24e Mon Sep 17 00:00:00 2001 From: Dan Taras Date: Mon, 20 Jun 2022 13:03:30 +0200 Subject: [PATCH 5/5] Bump version to 1.1.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b855432..e2e2e5d 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PcapTools" uuid = "222fe7e8-3f39-464a-bf97-d9bbb753f246" authors = ["Christian Rorvik "] -version = "1.0.0" +version = "1.1.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"