Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PcapTools"
uuid = "222fe7e8-3f39-464a-bf97-d9bbb753f246"
authors = ["Christian Rorvik <christian.rorvik@gmail.com>"]
version = "1.0.0"
version = "1.1.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
16 changes: 10 additions & 6 deletions src/splitcap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function splitcap(
reader::PcapReader,
record2key,
key2stream,
progress_callback = progress_noop_
progress_callback = progress_noop_;
own_streams::Bool = true
) where {KeyType, StreamType}
buffer_size = 1024 * 1024 * 2
max_pending_buffers = 4
Expand All @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, but maybe something like will work?

Suggested change
own_streams && append!(buffer, reader.raw_header)
position(stream) == 0 && append!(buffer, reader.raw_header)

output = SplitCapOutput{StreamType}(
buffer,
Channel{Vector{UInt8}}(max_pending_buffers),
Expand Down Expand Up @@ -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
Expand All @@ -90,9 +93,10 @@ function splitcap(
reader::PcapReader,
record2key,
key2stream,
progress_callback = progress_noop_
progress_callback = progress_noop_;
kwargs...
)
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; kwargs...)
end