megaco_tcp(3)

πŸ“¦
version 29.0.6 Β· 2 versions
, in nixos 26.05, nixpkgs unstable, ubuntu stonking

✨ megaco_tcp ✨

okay bestie, so this is megaco_tcp, a page from the Erlang Module Definition manual, and it's literally the interface module to the TPKT transport protocol for Megaco/H.248 πŸ’… no cap. Let's get into it.


πŸ¦‹ NAME πŸ¦‹

megaco_tcp β€” the interface module to the TPKT transport protocol for Megaco/H.248. that's it, that's the name, she's simple and she serves πŸ’–


🌸 DESCRIPTION 🌸

This module contains the public interface to the TPKT (TCP/IP) version transport protocol for Megaco/H.248. so like, if you're doing Megaco/H.248 over TCP/IP, this is your girl 🫢


πŸŽ€ DATA TYPES πŸŽ€

  • counter() β€” defined as:
medGwyGatewayNumInMessages | medGwyGatewayNumInOctets |
medGwyGatewayNumOutMessages | medGwyGatewayNumOutOctets |
medGwyGatewayNumErrors

this defines the different counters handled by this transport, periodt ✨ those five atoms are your whole counter vocabulary, don't try to invent more πŸ™ˆ

  • -opaque handle() β€” an opaque data type representing a TPKT connection. opaque means you don't peek under the hood, bestie, you just hold it and pass it around πŸ’…

πŸ’– FUNCTIONS πŸ’–

πŸ’… block(Handle) -> ok when Handle :: handle().

Stop receiving incoming messages on the socket. so like, pause that inbox, girl πŸ›‘

πŸ’… close(Handle) -> ok when Handle :: handle().

This function is used for closing an active TPKT connection. bye bestie, it was real 😭

πŸ’… connect(TransportRef, Opts) -> {ok, Handle, ControlPid} | {error, Reason}

with all the type goodness:

when
    TransportRef :: pid() | RegName,
    RegName :: atom(),
    Opts :: [Option],
    Option ::
        {inet_backend, default | inet | socket} |
        {host, Host} |
        {port, PortNum} |
        {options, list()} |
        {receive_handle, term()} |
        {module, atom()},
    Host :: inet:socket_address() | inet:hostname(),
    PortNum :: inet:port_number(),
    Handle :: handle(),
    ControlPid :: pid(),
    Reason :: term().

This function is used to open a TPKT connection. here's the tea on the options πŸ‘‡

  • module β€” this option makes it possible for the user to provide their own callback module. the receive_message/4 or process_received_message/4 functions of this module is called when a new message is received. which one gets called depends on the size of the message, so:
    • small β†’ receive_message
    • large β†’ process_received_message

default value is megaco. iconic default behavior tbh ✨

  • inet_backend β€” choose the inet-backend. this option make it possible to use a different inet-backend ('default', 'inet' or 'socket'). default is default (system default). lowkey important, highkey chill πŸ¦‹

πŸ’… get_stats() -> {ok, TotalStats} | {error, Reason}

when
    TotalStats :: [{Handle, [{Counter, integer()}]}],
    Handle :: handle(),
    Counter :: counter(),
    Reason :: term().

Get all counter values for all known connections. the whole roster, every single one, no crumbs left πŸ“

πŸ’… get_stats(Handle) -> {ok, Stats} | {error, Reason}

when
    Handle :: handle(),
    Stats :: [{Counter, integer()}],
    Counter :: counter(),
    Reason :: term().

Get all counter values for a given (connection) handle. just the one connection's receipts πŸ’œ

πŸ’… get_stats(Handle, Counter) -> {ok, integer()} | {error, Reason}

when
    Handle :: handle(),
    Counter :: counter(),
    Reason :: term().

Get the value of a specific counter. main character energy: one handle, one counter, one number πŸ‘‘

πŸ’… listen(TransportRef, Options) -> ok

when
    TransportRef :: pid() | RegName,
    RegName :: atom(),
    Options :: [Option],
    Option ::
        {inet_backend, default | inet | socket} |
        {port, inet:port_number()} |
        {options, list()} |
        {receive_handle, term()}.

This function is used for starting new TPKT listening socket for TCP/IP. the option list contains the socket definitions. and yes, there's one option with lore:

  • inet_backend β€” choose the inet-backend. this option make it possible to use a different inet-backend ('default', 'inet' or 'socket'). default is default (system default). same energy as connect, bestie, consistency ate 🌈

πŸ’… reset_stats() -> megaco:void().

Reset all counters for all connections. clean slate, new era, we don't talk about the old numbers πŸ’€

πŸ’… reset_stats(Handle) -> megaco:void() when Handle :: handle().

Reset all counters for the given connection. just that one handle gets the fresh start 🌸

πŸ’… send_message(Handle, Msg) -> ok

when
    Handle :: handle(), Msg :: binary() | iolist().

Sends a message on a TPKT connection. binary() or iolist(), both are welcome here 🫢

πŸ’… socket(Handle) -> Socket

when Handle :: handle(), Socket :: inet:socket().

This function is used to convert a socket handle() to a inet socket(). glow-up transformation, she's giving inet realness ✨

πŸ’… start_transport() -> {ok, TransportRef} when TransportRef :: pid().

This function is used for starting the TCP/IP transport service.

⚠️ heads up bestie: use exit(TransportRef, Reason) to stop the transport service. that's the way you shut her down, iykyk.

πŸ’… unblock(Handle) -> ok when Handle :: handle().

Starting to receive incoming messages from the socket again. un-pause, the inbox is open for business again πŸŽ€

πŸ’… upgrade_receive_handle(ControlPid, NewRecvHandle) -> ok

when
    ControlPid :: pid(),
    NewRecvHandle :: term().

Upgrade the receive handle of the control process (e.g. after having changed protocol version). glow-up arc for the control process, she's evolved πŸ’…πŸ¦‹


and that's the whole page, no notes πŸ”₯

Ericsson AB Β· megaco 4.9.2 Β· and this documentation lives on the megaco_tcp(3) page, so if you cite it, cite her right πŸ’– periodt ✨

πŸ“¦ where this page comes from