Skip to content

Inconsistent Transport API for UDP server #207

Description

@dragonhunt02

I'm trying to use Transport:controlling_process(Sock, NewPid) inside process spawned by esockd:open(..., MFArgs), but it fails when using UDP with badarg. Sock argument is from

loop(Transport = {udp, Server, Sock}, Peer = {IP, Port}) ->
receive

It seems that gen_udp:controlling_process is not implemented.

-spec(controlling_process(socket(), pid()) -> ok | {error, Reason} when
Reason :: closed | not_owner | badarg | inet:posix()).
controlling_process(Sock, NewOwner) when is_port(Sock) ->
gen_tcp:controlling_process(Sock, NewOwner);
controlling_process(#ssl_socket{ssl = SslSock}, NewOwner) ->
ssl:controlling_process(SslSock, NewOwner);
controlling_process(#proxy_socket{socket = Sock}, NewOwner) ->
controlling_process(Sock, NewOwner);

I can't simply use gen_udp:controlling_process() as workaround since socket is in a different process (error current process is not the owner of the socket)



I think we could fix it by updating the Pid assigned to a Peer with an exported function.

esockd/src/esockd_udp.erl

Lines 273 to 278 in d0c3edc

handle_info({udp, Sock, IP, InPortNo, Packet},
State = #state{sock = Sock, peers = Peers, access_rules = Rules}) ->
case maps:find(Peer = {IP, InPortNo}, Peers) of
{ok, Pid} ->
Pid ! {datagram, self(), Packet},
{noreply, State};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions