Use a new message type for stdio events

Make a new message type (alcove_ctl) for informing the erlang process
when a stdio descriptor has been closed.
This commit is contained in:
Michael Santos
2015-01-01 17:09:44 -05:00
parent 4ec936d5d7
commit 3b15781433
4 changed files with 17 additions and 15 deletions

View File

@@ -24,6 +24,7 @@ enum {
ALCOVE_MSG_PROXY,
ALCOVE_MSG_CALL,
ALCOVE_MSG_EVENT,
ALCOVE_MSG_CTL,
};
#define ALCOVE_CHILD_EXEC -2
@@ -645,7 +646,7 @@ exited_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
if ( (c->fdin >= 0) && (ap->opt & alcove_opt_stdin_closed)) {
index = alcove_mk_atom(t, sizeof(t), "stdin_closed");
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT, t, index) < 0)
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL, t, index) < 0)
return -1;
}
@@ -756,7 +757,7 @@ read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
c->fdctl = ALCOVE_CHILD_EXEC;
len = alcove_mk_atom(t, sizeof(t), "fdctl_closed");
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT, t, len) < 0)
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL, t, len) < 0)
return -1;
}
}
@@ -768,7 +769,7 @@ read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
case 0:
if (ap->opt & alcove_opt_stdout_closed) {
len = alcove_mk_atom(t, sizeof(t), "stdout_closed");
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT,
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL,
t, len) < 0)
return -1;
}
@@ -789,7 +790,7 @@ read_from_pid(alcove_state_t *ap, alcove_child_t *c, void *arg1, void *arg2)
case 0:
if (ap->opt & alcove_opt_stderr_closed) {
len = alcove_mk_atom(t, sizeof(t), "stderr_closed");
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_EVENT,
if (alcove_call_fake_reply(c->pid, ALCOVE_MSG_CTL,
t, len) < 0)
return -1;
}

View File

@@ -36,3 +36,4 @@
-define(ALCOVE_MSG_PROXY, 3).
-define(ALCOVE_MSG_CALL, 4).
-define(ALCOVE_MSG_EVENT, 5).
-define(ALCOVE_MSG_CTL, 6).

View File

@@ -80,4 +80,7 @@ decode(<<?UINT16(Len), ?UINT16(?ALCOVE_MSG_CALL), Data/binary>>, Pids) when Len
{alcove_call, lists:reverse(Pids), binary_to_term(Data)};
decode(<<?UINT16(Len), ?UINT16(?ALCOVE_MSG_EVENT), Data/binary>>, Pids) when Len =:= 2 + byte_size(Data) ->
{alcove_event, lists:reverse(Pids), binary_to_term(Data)}.
{alcove_event, lists:reverse(Pids), binary_to_term(Data)};
decode(<<?UINT16(Len), ?UINT16(?ALCOVE_MSG_CTL), Data/binary>>, Pids) when Len =:= 2 + byte_size(Data) ->
{alcove_ctl, lists:reverse(Pids), binary_to_term(Data)}.

View File

@@ -190,7 +190,7 @@ handle_info(Info, State) ->
%%--------------------------------------------------------------------
call_reply(Drv, Pids, false, Timeout) ->
receive
{alcove_event, Drv, Pids, fdctl_closed} ->
{alcove_ctl, Drv, Pids, fdctl_closed} ->
ok;
{alcove_call, Drv, _Pids, badpid} ->
exit(badpid);
@@ -202,15 +202,12 @@ call_reply(Drv, Pids, false, Timeout) ->
end;
call_reply(Drv, Pids, true, Timeout) ->
receive
{alcove_event, Drv, Pids, {termsig,_} = Signal} ->
exit(Signal);
{alcove_event, Drv, Pids, fdctl_closed} ->
receive
{alcove_event, Drv, Pids, {termsig,_} = Signal} ->
exit(Signal);
{alcove_event, Drv, Pids, {exit_status,_} = Status} ->
exit(Status)
end;
{alcove_ctl, Drv, Pids, fdctl_closed} ->
call_reply(Drv, Pids, true, Timeout);
{alcove_event, Drv, Pids, {termsig,_} = Event} ->
exit(Event);
{alcove_event, Drv, Pids, {exit_status,_} = Event} ->
exit(Event);
{alcove_call, Drv, _Pids, badpid} ->
exit(badpid);
{alcove_call, Drv, Pids, Event} ->