this repo has no description

Fix SimFile types

+8 -3
+7 -2
lib/trinity/sim_file.ex
··· 2 2 alias Trinity.Scheduler.Simulation 3 3 import Trinity.Scheduler, only: [simulation_key: 0, sim_node_key: 0] 4 4 5 + @type file_descriptor :: term 6 + @type posix :: :file.posix 7 + 5 8 @spec get_sim :: Simulation.t | nil 6 9 defp get_sim, do: Process.get(simulation_key()) 7 10 8 11 @spec get_proc_node :: atom 9 12 defp get_proc_node, do: Process.get(sim_node_key()) 10 13 11 - @spec open(String.t, [atom]) :: term 14 + @spec open(String.t, [atom]) :: {:ok, file_descriptor} | {:error, posix} 12 15 def open(path, modes) do 13 16 case get_sim() do 14 17 nil -> raise "not supported" ··· 16 19 end 17 20 end 18 21 22 + @spec pread(file_descriptor, non_neg_integer, non_neg_integer) :: {:ok, binary} | :eof | {:error, posix} 19 23 def pread(fd, loc, bytes) do 20 24 case get_sim() do 21 25 nil -> raise "not supported" ··· 96 100 >> = read_block(file_data, fd, start_block_index) 97 101 98 102 bytes_remaining = bytes - byte_size(bin_acc) 99 - do_read_blocks(file_data, fd, start_block_index + 1, bin_acc, bytes_remaining) 103 + bin = do_read_blocks(file_data, fd, start_block_index + 1, bin_acc, bytes_remaining) 104 + {:ok, bin} 100 105 end 101 106 102 107 defp do_read_blocks(_file_data, _fd, _block_index, bin_acc, 0) do
+1 -1
test/trinity_test.exs
··· 40 40 end 41 41 42 42 defp read_value(%{fd: fd, size: size}) do 43 - data = SimFile.pread(fd, 3, size) 43 + {:ok, data} = SimFile.pread(fd, 3, size) 44 44 "The current value of the counter is: " <> value_str = data 45 45 String.to_integer(value_str) 46 46 end