Skip to content

Commit

Permalink
Ignore SIGPIPE in send() and recv(), so RServe exits correctly when r…
Browse files Browse the repository at this point in the history
…eceiving EPIPE

This solution is intended to solve issue s-u#100. The method is very similar
to what is being done in the internal R http server (see Rhttpd.c).
It should therefore not cause any issues in other parts of R.
  • Loading branch information
rfaelens committed Mar 9, 2018
1 parent 05ff32d commit 6ed9621
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Rserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3012,13 +3012,30 @@ extern char Rserve_oc_prefix;

#define COMPUTE_OC_PREFIX '@'

#ifdef FORKED
extern int R_ignore_SIGPIPE; // see src/main/main.c::handlePipe in R
int server_recv(args_t *arg, void *buf, rlen_t len) {
R_ignore_SIGPIPE = 1;
int result = recv(arg->s, buf, len, 0);
R_ignore_SIGPIPE = 0;
return result;
}

int server_send(args_t *arg, const void *buf, rlen_t len) {
R_ignore_SIGPIPE = 1;
int result = send(arg->s, buf, len, 0);
R_ignore_SIGPIPE = 0;
return result;
}
#else
int server_recv(args_t *arg, void *buf, rlen_t len) {
return recv(arg->s, buf, len, 0);
}

int server_send(args_t *arg, const void *buf, rlen_t len) {
return send(arg->s, buf, len, 0);
}
#endif

SEXP Rserve_kill_compute(SEXP sSig) {
int sig = asInteger(sSig);
Expand Down

0 comments on commit 6ed9621

Please sign in to comment.