summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2017-10-21 21:20:46 +0100
committerJeremy Harris <jgh146exb@wizmail.org>2017-10-21 21:20:46 +0100
commitee25093663e5a72df66ba5b2c2934ea844a12133 (patch)
treef5ba1284cba66c3f0495e3970a490cd81d14aca1
parente72cfa5b8529a6fe8e674d70dc83df8bcf5e551c (diff)
tidying
-rw-r--r--src/src/deliver.c52
-rw-r--r--src/src/exim.c45
-rw-r--r--src/src/exim.h4
3 files changed, 48 insertions, 53 deletions
diff --git a/src/src/deliver.c b/src/src/deliver.c
index 295ae42c4..3180272a3 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -81,6 +81,52 @@ static uschar *used_return_path = NULL;
/*************************************************
+* read as much as requested *
+*************************************************/
+
+/* The syscall read(2) doesn't always returns as much as we want. For
+several reasons it might get less. (Not talking about signals, as syscalls
+are restartable). When reading from a network or pipe connection the sender
+might send in smaller chunks, with delays between these chunks. The read(2)
+may return such a chunk.
+
+The more the writer writes and the smaller the pipe between write and read is,
+the more we get the chance of reading leass than requested. (See bug 2130)
+
+This function read(2)s until we got all the data we *requested*.
+
+Note: This function may block. Use it only if you're sure about the
+amount of data you will get.
+
+Argument:
+ fd the file descriptor to read from
+ buffer pointer to a buffer of size len
+ len the requested(!) amount of bytes
+
+Returns: the amount of bytes read
+*/
+static ssize_t
+readn(int fd, void * buffer, size_t len)
+{
+ void * next = buffer;
+ void * end = buffer + len;
+
+ while (next < end)
+ {
+ ssize_t got = read(fd, next, end - next);
+
+ /* I'm not sure if there are signals that can interrupt us,
+ for now I assume the worst */
+ if (got == -1 && errno == EINTR) continue;
+ if (got <= 0) return next - buffer;
+ next += got;
+ }
+
+ return len;
+}
+
+
+/*************************************************
* Make a new address item *
*************************************************/
@@ -3312,8 +3358,7 @@ while (!done)
If we get less, we can assume the subprocess do be done and do not expect any further
information from it. */
- got = readn(fd, pipeheader, required);
- if (got != required)
+ if ((got = readn(fd, pipeheader, required)) != required)
{
msg = string_sprintf("got " SSIZE_T_FMT " of %d bytes (pipeheader) "
"from transport process %d for transport %s",
@@ -3349,8 +3394,7 @@ while (!done)
/* Same as above, the transport process will write the bytes announced
in a timely manner, so we can just wait for the bytes, getting less than expected
is considered a problem of the subprocess, we do not expect anything else from it. */
- got = readn(fd, big_buffer, required);
- if (got != required)
+ if ((got = readn(fd, big_buffer, required)) != required)
{
msg = string_sprintf("got only " SSIZE_T_FMT " of " SIZE_T_FMT
" bytes (pipedata) from transport process %d for transport %s",
diff --git a/src/src/exim.c b/src/src/exim.c
index 5a1437c3b..e15864839 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -5828,50 +5828,5 @@ exim_exit(EXIT_SUCCESS, US"main"); /* Never returns */
return 0; /* To stop compiler warning */
}
-/*************************************************
-* read as much as requested *
-*************************************************/
-
-/* The syscall read(2) doesn't always returns as much as we want. For
-several reasons it might get less. (Not talking about signals, as syscalls
-are restartable). When reading from a network or pipe connection the sender
-might send in smaller chunks, with delays between these chunks. The read(2)
-may return such a chunk.
-
-The more the writer writes and the smaller the pipe between write and read is,
-the more we get the chance of reading leass than requested. (See bug 2130)
-
-This function read(2)s until we got all the data we *requested*.
-
-Note: This function may block. Use it only if you're sure about the
-amount of data you will get.
-
-Argument:
- fd the file descriptor to read from
- buffer pointer to a buffer of size len
- len the requested(!) amount of bytes
-
-Returns: the amount of bytes read
-*/
-ssize_t
-readn(int fd, void *buffer, size_t len)
-{
- void *next = buffer;
- void *end = buffer + len;
-
- while (next < end)
- {
- ssize_t got = read(fd, next, end - next);
-
- /* I'm not sure if there are signals that can interrupt us,
- for now I assume the worst */
- if (got == -1 && errno == EINTR) continue;
- if (got <= 0) return next - buffer;
- next += got;
- }
-
- return len;
-}
-
/* End of exim.c */
diff --git a/src/src/exim.h b/src/src/exim.h
index e12049a9c..4a171003c 100644
--- a/src/src/exim.h
+++ b/src/src/exim.h
@@ -597,10 +597,6 @@ default to EDQUOT if it exists, otherwise ENOSPC. */
# undef DISABLE_DNSSEC
#endif
-/* Wrapper around read(2) to read all the data we requested (BLOCKING) */
-ssize_t
-readn(int fd, void *buffer, size_t len);
-
/* Some platforms (FreeBSD, OpenBSD, Solaris) do not seem to define this */
#ifndef POLLRDHUP