Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Sep 6, 2024
1 parent 2c33866 commit 0fd8535
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/flame/code_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ defmodule FLAME.CodeSync do
defp trim_leading_slash([?/ | path]), do: path
defp trim_leading_slash([_ | _] = path), do: path

defp recv_until_end_marker(socket, acc \\ "") do
{:ok, data} = :gen_tcp.recv(socket, 1024)

# Check if the data contains the end marker (0xFF)
case :binary.match(data, <<0xFF>>) do
{pos, 1} ->
# End marker found, append everything before it
acc <> binary_part(data, 0, pos)

:nomatch ->
# No end marker, continue receiving more data
recv_until_end_marker(socket, acc <> data)
end
end

def extract_packaged_stream(%PackagedStream{} = pkg, ip_port \\ nil) do
stream =
case ip_port do
Expand All @@ -237,9 +252,9 @@ defmodule FLAME.CodeSync do
])

# Receive the file from the server
{:ok, data} = :gen_tcp.recv(socket, 0)
data = recv_until_end_marker(socket)
:gen_tcp.close(socket)
File.stream!(data)
[data]
end

if stream do
Expand Down
1 change: 1 addition & 0 deletions lib/flame/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ defmodule FLAME.Runner do
{:ok, socket} = :gen_tcp.accept(listen_socket)
Logger.info("Sending binary over TCP")
Enum.each(base_sync_stream.stream, fn chunk -> :ok = :gen_tcp.send(socket, chunk) end)
:ok = :gen_tcp.send(socket, <<0xFF>>)
{:ok, _ack} = :gen_tcp.recv(socket, 0)
:gen_tcp.close(socket)
end)
Expand Down

0 comments on commit 0fd8535

Please sign in to comment.