megaco_transport(3erl)

πŸ’… megaco_transport β€” the Megaco transport behaviour, bestie edition

okay so this is megaco_transport, an Erlang module, and it's basically the vibe check for anyone who wants to be a transport for Megaco. it's a behaviour, meaning you write the callback module and it has to bring these functions, no cap. iykyk 🫢


✨ DESCRIPTION ✨

so here's the tea: your callback module needs to export these functions. this is the whole roster:

  • send_message/2 β€” mandatory (like, you literally cannot skip this one πŸ’€)
  • send_message/3 β€” optional
  • resend_message/2 β€” optional
  • (and there's a fourth bullet in the original list that's just… empty. a mystery. a ghost. we respect it πŸŽ€)

🌈 EXPORTS 🌈

πŸ’Œ send_message/2 and send_message/3 β€” the main characters

Module:send_message(Handle, Msg) -> ok | {cancel, Reason} | Error
Module:send_message(Handle, Msg, Resend) -> ok | {cancel, Reason} | Error

the types, exactly as written:

Handle = term()
Msg = binary() | iolist()
Resend = boolean()
Reason = term()
Error = term()

so like. this is the "send a megaco message" function. that's the job. πŸ“€

now here's the interesting part β€” if it returns {cancel, Reason}, that means the transport module decided not to send the message. and listen, this is not an error, okay? no error messages get issued, no error counters get incremented, nothing is on fire. it's a whole intentional choice. what actually happens next depends on what kind of message was going out. πŸ”₯

for requests β€” megaco will cancel the message, super similar to how it'd behave if megaco:cancel had been called (after a successful send). the info gets propagated back to the user, but the route it takes depends on how the request was issued:

  • requests issued with megaco:call β†’ the info comes back to you in the return value ✨
  • requests issued with megaco:cast β†’ the info arrives via a call to the callback function handle_trans_reply πŸŽ€

for a reply β€” megaco will cancel the reply, and word of that gets returned to the user via a call to the callback function handle_trans_ack. simple as that πŸ’…

btw, send_message/3 only gets called if the resend_indication config option has been set to the value flag. and the third argument, Resend, tells you whether this message send is a resend or not. that's it, that's the whole thing.


πŸ¦‹ resend_message/2 β€” the re-run, the encore

Module:resend_message(Handle, Msg) -> ok | {cancel, Reason} | Error

types:

Handle = term()
Msg = binary() | iolist()
Reason = term()
Error = term()

this one re-sends a megaco message. πŸ’«

real talk though: this function only gets called if the user has set the resend_indication config option to true and it's actually a message resend. if both of those conditions aren't met, send_message gets called instead. both boxes gotta be checked, no exceptions 🎯

and same energy as before β€” if it returns {cancel, Reason}, the transport module decided not to send it. not an error. no error messages, no counter increments, none of that. the consequences depend on the message type:

for requests β€” megaco cancels the message, basically just like megaco:cancel had been called (after a successful send). the info heads back to the user depending on how the request was issued:

  • megaco:call β†’ info delivered in the return value 🫢
  • megaco:cast β†’ info delivered via a call to the callback function handle_trans_reply

for a reply β€” megaco cancels the reply, and that info goes back to the user via a call to the callback function handle_trans_ack. periodt. πŸ‘‘


and that's the page, bestie β€” go forth and transport responsibly 🌸

with love from Ericsson AB, megaco 4.4.3, dated the very day this manpage was born β€” mwah πŸ’–

πŸ“¦ where this page comes from