[erlang-questions] port_command and marshalling
Paul Oliver
puzza007@REDACTED
Mon Oct 29 16:39:03 CET 2007
Hi,
I have a port open with opts [{packet, 4}, binary] and call it using:
port_command(Port, term_to_binary(Msg)),
With the definition of receive_erlang_port_msg below, for a
particular call, I get:
lengthstr[0]=0
lengthstr[1]=0
lengthstr[2]=5
lengthstr[3]=-103
LEN=-103
Does anyone know where the -103 comes from?
Is there any standard marshalling code I can lift?
Thanks!
Paul.
byte* receive_erlang_port_msg(void)
{
int i, len = 0;
byte *buffer;
byte lengthstr[4];
if (read_exact(lengthstr, 4) !=4) {
exit(1);
}
for (i=0;i<4;i++) {
fprintf(stderr,"lengthstr[%d]=%d\n",i, lengthstr[i]);
}
len = (unsigned) lengthstr[3];
len |= ((unsigned) lengthstr[2]) << 8;
len |= ((unsigned) lengthstr[1]) << 16;
len |= ((unsigned) lengthstr[0]) << 24;
fprintf(stderr, "LEN=%d\n", len);
buffer = (byte *)malloc(len);
if (read_exact(buffer, len) <= 0) {
exit(1);
}
return buffer;
}
More information about the erlang-questions
mailing list