[erlang-questions] how does an erlang Socket/Port look from inside?
Wed Mar 26 18:20:35 CET 2014
It works! thank you!
On Wednesday, March 26, 2014 7:00 PM, Fred Hebert <> wrote:
Hi, I have a solution.
As part of recon (which allows to use strings and whatnot as ports) to
diagnose issues, I have developed a term_to_port function that uses the
serialized binary form of a port and uses binary_to_term/1 to make it
into a real Erlang term:
%% @doc Transforms a given term to a port
-spec term_to_port(recon:port_term()) -> port().
term_to_port(Port) when is_port(Port) -> Port;
term_to_port(Name) when is_atom(Name) -> whereis(Name);
N = list_to_integer(lists:sublist(Id, length(Id)-1)), % drop trailing '>'
term_to_port(N) when is_integer(N) ->
%% We rebuild the term from the int received:
Name = iolist_to_binary(atom_to_list(node())),
NameLen = iolist_size(Name),
Vsn = binary:last(term_to_binary(self())),
Bin = <<131, % term encoding value
102, % port tag
100, % atom ext tag, used for node name
N:4/unit:8, % actual counter value
Vsn:8>>, % version
I'm guessing this could be useful in your case here, if gen_tcp:listen
doesn't work (and it should totally work)
On 03/26, Dror Mein wrote:
> Hey all,
> I want to eunit+meck test a simple telnet client which uses the guard is_port(Port).
> how can I pass something in meck:expect/4 that will pass the guard?
> is it a record/reference that I can make up?
> can I use hd(erlang:ports()) -> #Port<0.0> without blowing up?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions