X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fprocess-unix.c;h=05b50463890c349935cec1a0b5f08f5ba9307b86;hb=515ed47192a2fc212474dc246a875771890e0cbe;hp=424246f6f15bfb79cc7f177d68356e08e2a3ee5a;hpb=ee38d21b330f5001b47a577cefb5ba7b82a3b7d3;p=chise%2Fxemacs-chise.git.1 diff --git a/src/process-unix.c b/src/process-unix.c index 424246f..05b5046 100644 --- a/src/process-unix.c +++ b/src/process-unix.c @@ -1293,26 +1293,38 @@ unix_send_process (Lisp_Object proc, struct lstream* lstream) Bufbyte chunkbuf[512]; Bytecount chunklen; - while (1) + do { Lstream_data_count writeret; chunklen = Lstream_read (lstream, chunkbuf, 512); - if (chunklen <= 0) - break; /* perhaps should ABORT() if < 0? - This should never happen. */ old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap); - /* Lstream_write() will never successfully write less than - the amount sent in. In the worst case, it just buffers - the unwritten data. */ - writeret = Lstream_write (XLSTREAM (DATA_OUTSTREAM(p)), chunkbuf, - chunklen); - signal (SIGPIPE, old_sigpipe); - if (writeret < 0) - /* This is a real error. Blocking errors are handled - specially inside of the filedesc stream. */ - report_file_error ("writing to process", list1 (proc)); + if (chunklen > 0) + { + int save_errno; + + /* Lstream_write() will never successfully write less than + the amount sent in. In the worst case, it just buffers + the unwritten data. */ + writeret = Lstream_write (XLSTREAM (DATA_OUTSTREAM(p)), chunkbuf, + chunklen); + save_errno = errno; + signal (SIGPIPE, old_sigpipe); + errno = save_errno; + if (writeret < 0) + /* This is a real error. Blocking errors are handled + specially inside of the filedesc stream. */ + report_file_error ("writing to process", list1 (proc)); + } + else + { + /* Need to make sure that everything up to and including the + last chunk is flushed, even when the pipe is currently + blocked. */ + Lstream_flush (XLSTREAM (DATA_OUTSTREAM(p))); + signal (SIGPIPE, old_sigpipe); + } while (Lstream_was_blocked_p (XLSTREAM (p->pipe_outstream))) { /* Buffer is full. Wait, accepting input; @@ -1327,7 +1339,9 @@ unix_send_process (Lisp_Object proc, struct lstream* lstream) Lstream_flush (XLSTREAM (p->pipe_outstream)); signal (SIGPIPE, old_sigpipe); } + /* Perhaps should abort() if < 0? This should never happen. */ } + while (chunklen > 0); } else { /* We got here from a longjmp() from the SIGPIPE handler */ @@ -1670,13 +1684,13 @@ unix_open_network_stream (Lisp_Object name, Lisp_Object host, Lisp_Object servic volatile int xerrno = 0; volatile int failed_connect = 0; char *ext_host; + char portbuf[sizeof(long)*3 + 2]; /* * Caution: service can either be a string or int. * Convert to a C string for later use by getaddrinfo. */ if (INTP (service)) { - char portbuf[128]; snprintf (portbuf, sizeof (portbuf), "%ld", (long) XINT (service)); portstring = portbuf; port = htons ((unsigned short) XINT (service));