views:

66

answers:

1

Hi.

I have a problem with one module of ejabberd. It is http_bind. But when I debug deeply I found that after accept socket and spawning hadling process and when reasign process for recieve data for new created process by calling gen_tcp:controlling_process() failed with badarg, WHY?

...

{ok, Socket} = get_tcp:accept(ListenSocket),
Opts = [{active, false}, ...],

% here function return result of proc_lib:spawn_link(handler, ...)
{ok, Pid} = ejabberd_http:start({gen_tcp, Socket}, Opts),

gen_tcp:controlling_process(Socket, Pid),

: {badarg, [
   {erlang, port_connect, [#Port<0.140743856>, <0.5939.4350>]}, 
   {inet, tcp_controlling_process, 2},
   {ejabberd_socket,start,4},
   {ejabberd_listener,accept,3},
   {proc_lib,init_p,5}
]}

any help?

+1  A: 

Most probably the socket or the process has crashed before the call to controlling_process.

http://www.erlang.org/doc/man/erlang.html#port_connect-2

Why they would have crashed I don't know, have you made sure that the ejabberd process is running as it should?

Lukas
From the documentation page: "Failure: badarg if Port is not an open port or the registered name of an open port, or if Pid is not an existing local pid."
Adam Lindberg
i think process was created succesfully, but maybe before controlling_process() calling it was crashed, but why?... do you know how can I test process pid validity before?
vinnitu
You can always do erlang:process_info(Pid) and see what that returns to find out if the process is running or not.
Lukas