undocumented inet (and gen_tcp)

Matthias Lang <>
Wed Sep 11 13:56:01 CEST 2002


Hi,

This should be useful for others. Inet (and related stuff,
e.g. gen_tcp) have many undocumented features. Some of these are
really useful:

    getopts/2   (lets you inspect the options in setopts)
    options/0   (gives a complete list of the options for
                 get and setopts. There are 22 in R8B-2, the
                 inet manpage documents only 10 of them.)
    getif/0     (list of network interfaces)
    getiflist/0 (ditto)
    ifget/2     (information about an interface, e.g. IP addr)
    ifset/2     
    getstat/2   (call stats/0 for the possible atoms)

(Background: Normal gen_tcp behaviour when the remote receiver can't
keep up is to block on send/2. Sometimes this is NOT what I want,
sometimes I want to kill the 'full' socket rather than wait forever.

The dumb solution which does something vaguely similar to what I want:

   Write code like this:

    {ok, Tref} = timer:apply_after(500, erlang, exit, [self(), kill]),
    gen_tcp:send(S, Data),
    timer:cancel(Tref).

The nice, but undocumented, solution which does exactly what I want:

    gen_tcp:connect(Host, Port, [{send_timeout, 0}])

)

Question for Tony: what's that (unimplemented) 'pushf' stuff intended for?

Matthias



More information about the erlang-questions mailing list