Skip to content

Commit

Permalink
Set timeout based on OS
Browse files Browse the repository at this point in the history
On Linux, a timeout of 0 will block until the next packet is received.

On BSD/Mac OS X, 0 will block until the snaplen buffer is full, so set
the default timeout to 500 ms.
  • Loading branch information
msantos committed Apr 11, 2012
1 parent f0c59d6 commit 2865c2e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/epcap.erl
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ start_link(Pid, Options) ->
init([Pid, Options]) -> init([Pid, Options]) ->
process_flag(trap_exit, true), process_flag(trap_exit, true),
Chroot = chroot_path(), Chroot = chroot_path(),
Cmd = make_args(Options ++ [{chroot, Chroot}]), Timeout = case os:type() of
{unix, linux} -> 0;
_ -> 500
end,
Cmd = make_args(Options ++ [{chroot, Chroot}, {timeout, Timeout}]),
Port = open_port({spawn, Cmd}, [{packet, 2}, binary, exit_status]), Port = open_port({spawn, Cmd}, [{packet, 2}, binary, exit_status]),
{ok, #state{ {ok, #state{
pid = Pid, pid = Pid,
Expand Down

0 comments on commit 2865c2e

Please sign in to comment.