Skip to content

Commit

Permalink
Fixed issue where not only some of the beam file would be read by the
Browse files Browse the repository at this point in the history
input stream, giving an incomplete beam.
  • Loading branch information
Andy Till committed Jun 13, 2015
1 parent bed7f6a commit 336bc3c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
24 changes: 17 additions & 7 deletions src/main/java/erlyberly/node/NodeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;

Expand Down Expand Up @@ -151,11 +152,13 @@ public void run() {

private void loadRemoteErlyberly() throws IOException, OtpErlangException {

sendRPC("code", "load_binary",
OtpErlangBinary otpErlangBinary = new OtpErlangBinary(loadBeamFile());
System.out.println("binary size=" + otpErlangBinary.size());
sendRPC("code", "load_binary",
list(
atom("erlyberly"),
new OtpErlangString(ERLYBERLY_BEAM_PATH),
new OtpErlangBinary(loadBeamFile())));
otpErlangBinary));

OtpErlangObject result = receiveRPC();

Expand Down Expand Up @@ -186,14 +189,21 @@ private OtpErlangObject receiveRPC() throws IOException, OtpErlangException {

private static byte[] loadBeamFile() throws IOException {
InputStream resourceAsStream = OtpUtil.class.getResourceAsStream(ERLYBERLY_BEAM_PATH);

byte[] b = new byte[BEAM_SIZE_LIMIT];
int read = resourceAsStream.read(b);

if(read >= BEAM_SIZE_LIMIT) {
int total = 0;
int read = 0;

do {
total += read;
read = resourceAsStream.read(b, total, BEAM_SIZE_LIMIT - total);
} while (read != -1);

if(total >= BEAM_SIZE_LIMIT) {
throw new RuntimeException("erlyberly.beam file is too big");
}

return b;
return Arrays.copyOf(b, total);
}

public synchronized void retrieveProcessInfo(ArrayList<ProcInfo> processes) throws Exception {
Expand Down
Binary file modified src/main/resources/erlyberly/beam/erlyberly.beam
Binary file not shown.
4 changes: 0 additions & 4 deletions src/main/resources/erlyberly/beam/erlyberly.erl
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ format_pid(Pid) when is_pid(Pid) ->
format_pid(Port) when is_port(Port) ->
erlang:port_to_list(Port).

%%
log_seq_trace(Seq_trace) ->
io:format("~s ~p~n", [format_utc_timestamp(), Seq_trace]).

%%
format_utc_timestamp() ->
TS = {_,_,Micro} = os:timestamp(),
Expand Down

0 comments on commit 336bc3c

Please sign in to comment.