Function: tramp-send-string
tramp-send-string is a byte-compiled function defined in tramp.el.gz.
Signature
(tramp-send-string VEC STRING)
Documentation
Send the STRING via connection VEC.
The STRING is expected to use Unix line-endings, but the lines sent to
the remote host use line-endings as defined in the variable
tramp-rsh-end-of-line. The communication buffer is erased before sending.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
;; It seems that Tru64 Unix does not like it if long strings are sent
;; to it in one go. (This happens when sending the Perl
;; `file-attributes' implementation, for instance.) Therefore, we
;; have this function which sends the string in chunks.
(defun tramp-send-string (vec string)
"Send the STRING via connection VEC.
The STRING is expected to use Unix line-endings, but the lines sent to
the remote host use line-endings as defined in the variable
`tramp-rsh-end-of-line'. The communication buffer is erased before sending."
(let* ((p (tramp-get-connection-process vec))
(chunksize (tramp-get-connection-property p "chunksize" nil)))
(unless p
(tramp-error
vec 'file-error "Can't send string to remote host -- not logged in"))
(tramp-set-connection-property p "last-cmd-time" (current-time))
(tramp-message vec 10 "%s" string)
(with-current-buffer (tramp-get-connection-buffer vec)
;; Clean up the buffer. We cannot call `erase-buffer' because
;; narrowing might be in effect.
(let ((inhibit-read-only t)) (delete-region (point-min) (point-max)))
;; Replace "\n" by `tramp-rsh-end-of-line'.
(setq string
(mapconcat
#'identity (split-string string "\n") tramp-rsh-end-of-line))
(unless (or (string-empty-p string)
(string-equal (substring string -1) tramp-rsh-end-of-line))
(setq string (concat string tramp-rsh-end-of-line)))
;; This must be protected by the "locked" property.
(with-tramp-locked-connection p
;; Send the string.
(with-local-quit
(if (and chunksize (not (zerop chunksize)))
(let ((pos 0)
(end (length string)))
(while (< pos end)
(tramp-message
vec 10 "Sending chunk from %s to %s"
pos (min (+ pos chunksize) end))
(process-send-string
p (substring string pos (min (+ pos chunksize) end)))
(setq pos (+ pos chunksize))))
(process-send-string p string)))))))