Commit b0769798 b0769798ab5dc2daaca5559289eac6714554568b by Sergey Poznyakoff

Bugfixes.

* imap4d/io.c (imap4d_tokbuf_decrlf): Rewrite to run in
O(n).
* libmailutils/server/ipsrv.c (mu_ip_tcp_accept): Return 0 on
EINTR (unless srv->f_intr tells otherwise) and EAGAIN.  The caller
will retry.
(mu_ip_server_accept): output a diagnostic message before
returning error.
1 parent 43d9797e
......@@ -436,16 +436,17 @@ imap4d_tokbuf_decrlf (struct imap4d_tokbuf *tok, size_t off, size_t *plen)
size_t len = *plen;
char *p, *end = buf + len;
for (p = end - 1; p > buf; p--)
for (p = buf; p < end; )
{
if (*p == '\n' && p > buf && p[-1] == '\r')
if (*p == '\r' && p + 1 < end && p[1] == '\n')
{
memmove (p - 1, p, end - p);
end--;
p--;
p++;
len--;
}
else
*buf++ = *p++;
}
*plen = end - buf;
*plen = len;
}
static void
......
......@@ -361,10 +361,14 @@ mu_ip_tcp_accept (mu_ip_server_t srv, void *call_data)
if (connfd == -1)
{
int ec = errno;
if (ec == EINTR)
{
if (srv->f_intr && srv->f_intr (srv->data, call_data))
mu_ip_server_shutdown (srv);
switch (ec)
{
case EINTR:
if (srv->f_intr && srv->f_intr (srv->data, call_data))
break;
/* fall through */
case EAGAIN:
ec = 0;
}
return ec;
}
......@@ -493,7 +497,11 @@ mu_ip_server_accept (mu_ip_server_t srv, void *call_data)
}
if (rc)
mu_ip_server_shutdown (srv);
{
mu_error (_("socket error on \"%s\": %s"), IDENTSTR (srv),
mu_strerror (rc));
mu_ip_server_shutdown (srv);
}
return rc;
}
......