WHERE unsigned short Counter INITVAL (0);
+WHERE short ConnectTimeout;
WHERE short HistSize;
WHERE short PagerContext;
WHERE short PagerIndexLines;
** When set, Mutt will prompt for confirmation when saving messages to a
** mailbox which does not yet exist before creating it.
*/
+ { "connect_timeout", DT_NUM, R_NONE, UL &ConnectTimeout, 30 },
+ /*
+ ** .pp
+ ** Causes Mutt to timeout a network connection (for IMAP or POP) after this
+ ** many seconds if the connection is not able to be established. A negative
+ ** value causes Mutt to wait indefinitely for the connection to succeed.
+ */
{ "copy", DT_QUAD, R_NONE, OPT_COPY, M_YES },
/*
** .pp
{
int sa_size;
int rc;
+ int save_errno;
+
/* old first_try_without_preconnect removed for now. unset $preconnect
first. */
dprint (1, (debugfile, "Preconnect result: %d\n", rc));
if (rc)
{
- mutt_perror (_("Preconnect command failed."));
- sleep (1);
+ save_errno = errno;
+ mutt_perror (_("Preconnect command failed."));
+ sleep (1);
- return -1;
+ return save_errno;
}
}
return -1;
}
+ if (ConnectTimeout > 0)
+ alarm (ConnectTimeout);
+
+ mutt_allow_interrupt (1);
+
+ save_errno = 0;
+
if (connect (fd, sa, sa_size) < 0)
{
- dprint (2, (debugfile, "Connection failed. errno: %d...\n", errno));
-
- return errno;
+ save_errno = errno;
+ dprint (2, (debugfile, "Connection failed. errno: %d...\n", errno));
+ SigInt = 0; /* reset in case we caugh SIGINTR while in connect() */
}
-
- return 0;
+
+ if (ConnectTimeout > 0)
+ alarm (0);
+ mutt_allow_interrupt (0);
+
+ return save_errno;
}
/* socket_new_conn: allocate and initialise a new connection. */
fd = socket (cur->ai_family, cur->ai_socktype, cur->ai_protocol);
if (fd >= 0)
{
- if (socket_connect (fd, res->ai_addr) == 0)
+ if ((rc = socket_connect (fd, res->ai_addr)) == 0)
{
conn->fd = fd;
- rc = 0;
break;
}
else
if (fd > 0)
{
- if (socket_connect (fd, (struct sockaddr*) &sin) == 0)
+ if ((rc = socket_connect (fd, (struct sockaddr*) &sin) == 0))
{
conn->fd = fd;
- rc = 0;
break;
}
else
if (rc)
{
mutt_error (_("Could not connect to %s (%s)."), conn->account.host,
- rc == ETIMEDOUT ? "timed out" :
- rc == ECONNREFUSED ? "connection refused" :
- rc == ENETUNREACH ? "host unreachable" :
- "unknown error");
+ (rc > 0) ? strerror (rc) : _("unknown error"));
sleep (2);
}
void mutt_adv_mktemp (char *, size_t);
void mutt_alias_menu (char *, size_t, ALIAS *);
+void mutt_allow_interrupt (int);
void mutt_block_signals (void);
void mutt_block_signals_system (void);
void mutt_body_handler (BODY *, STATE *);
/* we want to avoid race conditions */
sigaddset (&act.sa_mask, SIGTSTP);
+ act.sa_handler = sighandler;
+
+ /* we want SIGALRM to abort the current syscall, so we do this before
+ * setting the SA_RESTART flag below. currently this is only used to
+ * timeout on a connect() call in a reasonable amout of time.
+ */
+ sigaction (SIGALRM, &act, NULL);
+
/* we also don't want to mess with interrupted system calls */
#ifdef SA_RESTART
act.sa_flags = SA_RESTART;
#endif
- act.sa_handler = sighandler;
sigaction (SIGCONT, &act, NULL);
sigaction (SIGTSTP, &act, NULL);
sigaction (SIGINT, &act, NULL);
unset_option (OPTSYSSIGNALSBLOCKED);
}
}
+
+void mutt_allow_interrupt (int disposition)
+{
+ struct sigaction sa;
+
+ memset (&sa, 0, sizeof sa);
+ sa.sa_handler = sighandler;
+#ifdef SA_RESTART
+ if (disposition == 0)
+ sa.sa_flags |= SA_RESTART;
+#endif
+ sigaction (SIGINT, &sa, NULL);
+}