Function: process-send-eof

process-send-eof is a function defined in process.c.

Signature

(process-send-eof &optional PROCESS)

Documentation

Make PROCESS see end-of-file in its input.

EOF comes after any text already sent to it. PROCESS may be a process, a buffer, the name of a process or buffer, or nil, indicating the current buffer's process. If PROCESS is a network connection, or is a process communicating through a pipe (as opposed to a pty), then you cannot send any more text to PROCESS after you call this function. If PROCESS is a serial process, wait until all output written to the process has been transmitted to the serial port.

View in manual

Source Code

// Defined in /usr/src/emacs/src/process.c
{
  Lisp_Object proc;
  struct coding_system *coding = NULL;
  int outfd;

  proc = get_process (process);

  if (NETCONN_P (proc))
    wait_while_connecting (proc);

  if (DATAGRAM_CONN_P (proc))
    return process;


  outfd = XPROCESS (proc)->outfd;
  eassert (outfd < FD_SETSIZE);
  if (outfd >= 0)
    coding = proc_encode_coding_system[outfd];

  /* Make sure the process is really alive.  */
  if (XPROCESS (proc)->raw_status_new)
    update_status (XPROCESS (proc));
  if (! EQ (XPROCESS (proc)->status, Qrun))
    error ("Process %s not running: %s", SDATA (XPROCESS (proc)->name), SDATA (status_message (XPROCESS (proc))));

  if (coding && CODING_REQUIRE_FLUSHING (coding))
    {
      coding->mode |= CODING_MODE_LAST_BLOCK;
      send_process (proc, "", 0, Qnil);
    }

  if (XPROCESS (proc)->pty_in)
    send_process (proc, "\004", 1, Qnil);
  else if (EQ (XPROCESS (proc)->type, Qserial))
    {
#if !defined WINDOWSNT && defined HAVE_TCDRAIN
      if (tcdrain (XPROCESS (proc)->outfd) != 0)
	report_file_error ("Failed tcdrain", Qnil);
#endif /* not WINDOWSNT && not TCDRAIN */
      /* Do nothing on Windows because writes are blocking.  */
    }
  else
    {
      struct Lisp_Process *p = XPROCESS (proc);
      int old_outfd = p->outfd;
      int new_outfd;

#ifdef HAVE_SHUTDOWN
      /* If this is a network connection, or socketpair is used
	 for communication with the subprocess, call shutdown to cause EOF.
	 (In some old system, shutdown to socketpair doesn't work.
	 Then we just can't win.)  */
      if (0 <= old_outfd
	  && (EQ (p->type, Qnetwork) || p->infd == old_outfd))
	shutdown (old_outfd, 1);
#endif
      close_process_fd (&p->open_fd[WRITE_TO_SUBPROCESS]);
      new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0);
      if (new_outfd < 0)
	report_file_error ("Opening null device", Qnil);
      p->open_fd[WRITE_TO_SUBPROCESS] = new_outfd;
      p->outfd = new_outfd;

      eassert (0 <= new_outfd && new_outfd < FD_SETSIZE);
      if (!proc_encode_coding_system[new_outfd])
	proc_encode_coding_system[new_outfd]
	  = xmalloc (sizeof (struct coding_system));
      if (old_outfd >= 0)
	{
	  eassert (old_outfd < FD_SETSIZE);
	  *proc_encode_coding_system[new_outfd]
	    = *proc_encode_coding_system[old_outfd];
	  memset (proc_encode_coding_system[old_outfd], 0,
		  sizeof (struct coding_system));
	}
      else
	setup_coding_system (p->encode_coding_system,
			     proc_encode_coding_system[new_outfd]);
    }
  return process;
}