Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename poll to wait #38

Merged
merged 12 commits into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename poll() to wait()
  • Loading branch information
lbartnik committed Jan 3, 2017
commit 14906f26ba0768a11a12c296d624397bd76246a5
10 changes: 6 additions & 4 deletions src/rapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ static void C_child_process_finalizer(SEXP ptr)
// it might be necessary to terminate the process first
auto try_terminate = [&handle] {
try {
handle->poll(TIMEOUT_IMMEDIATE);
// refresh the handle and try terminating if the child
// is still running
handle->wait(TIMEOUT_IMMEDIATE);
handle->terminate();
}
catch (subprocess_exception) {
Expand Down Expand Up @@ -277,7 +279,7 @@ SEXP C_process_write (SEXP _handle, SEXP _message)
}


SEXP C_process_poll (SEXP _handle, SEXP _timeout)
SEXP C_process_wait (SEXP _handle, SEXP _timeout)
{
/* extract timeout */
if (!is_single_integer(_timeout)) {
Expand All @@ -290,7 +292,7 @@ SEXP C_process_poll (SEXP _handle, SEXP _timeout)
process_handle_t * handle = extract_process_handle(_handle);

/* check the process */
try_run(&process_handle_t::poll, handle, timeout);
try_run(&process_handle_t::wait, handle, timeout);

/* answer */
SEXP ans;
Expand Down Expand Up @@ -319,7 +321,7 @@ SEXP C_process_return_code (SEXP _handle)
{
process_handle_t * handle = extract_process_handle(_handle);

try_run(&process_handle_t::poll, handle, TIMEOUT_IMMEDIATE);
try_run(&process_handle_t::wait, handle, TIMEOUT_IMMEDIATE);

if (handle->state == process_handle_t::EXITED ||
handle->state == process_handle_t::TERMINATED)
Expand Down
2 changes: 1 addition & 1 deletion src/rapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ EXPORT SEXP C_process_close_input (SEXP _handle);

EXPORT SEXP C_process_write(SEXP _handle, SEXP _message);

EXPORT SEXP C_process_poll(SEXP _handle, SEXP _timeout);
EXPORT SEXP C_process_wait(SEXP _handle, SEXP _timeout);

EXPORT SEXP C_process_return_code(SEXP _handle);

Expand Down
10 changes: 5 additions & 5 deletions src/sub-linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ void process_handle_t::shutdown ()

/* closing pipes should let the child process exit */
// TODO there might be a need to send a termination signal first
poll(TIMEOUT_IMMEDIATE);
wait(TIMEOUT_IMMEDIATE);
kill();
poll(TIMEOUT_INFINITE);
wait(TIMEOUT_INFINITE);

state = SHUTDOWN;
}
Expand Down Expand Up @@ -456,10 +456,10 @@ void process_handle_t::close_input ()
}


/* --- process::poll ------------------------------------------------ */
/* --- process::wait ------------------------------------------------ */


void process_handle_t::poll (int _timeout)
void process_handle_t::wait (int _timeout)
{
if (!child_id) {
throw subprocess_exception(ECHILD, "child does not exist");
Expand Down Expand Up @@ -534,7 +534,7 @@ static void termination_signal (process_handle_t & _handle, int _signal, int _ti
throw subprocess_exception(errno, "system kill() failed");
}

_handle.poll(_timeout);
_handle.wait(_timeout);
}


Expand Down
4 changes: 2 additions & 2 deletions src/sub-windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void process_handle_t::close_input ()
/* ------------------------------------------------------------------ */


void process_handle_t::poll (int _timeout)
void process_handle_t::wait (int _timeout)
{
if (!child_handle || state != RUNNING)
return;
Expand Down Expand Up @@ -455,7 +455,7 @@ void process_handle_t::poll (int _timeout)
void process_handle_t::terminate()
{
// first make sure it's even still running
poll(TIMEOUT_IMMEDIATE);
wait(TIMEOUT_IMMEDIATE);
if (!child_handle || state != RUNNING)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/subprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ struct process_handle_t {

void close_input ();

void poll(int _timeout);
void wait(int _timeout);

void terminate();

Expand Down