diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2012-04-09 15:54:59 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2012-04-09 15:54:59 -0700 |
commit | 45e9f7da84c1bd3fc0d36d05c5708ed3b2d3a193 (patch) | |
tree | 5bc87a8b5a3c754b8eb44a612cc6c03561d6b968 /src/gnutls.c | |
parent | 9d6b4d53469a9ffd67bd770fabc6fe254e35c21d (diff) | |
parent | 05920a43fc18e696b464387e781e7cfdcea5b5af (diff) | |
download | emacs-45e9f7da84c1bd3fc0d36d05c5708ed3b2d3a193.tar.gz |
Merge from trunk.
Diffstat (limited to 'src/gnutls.c')
-rw-r--r-- | src/gnutls.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/gnutls.c b/src/gnutls.c index 99fc5c10e2b..8dbf01cedc9 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -247,18 +247,27 @@ init_gnutls_functions (Lisp_Object libraries) #endif /* !WINDOWSNT */ +/* Function to log a simple message. */ static void gnutls_log_function (int level, const char* string) { message ("gnutls.c: [%d] %s", level, string); } +/* Function to log a message and a string. */ static void gnutls_log_function2 (int level, const char* string, const char* extra) { message ("gnutls.c: [%d] %s %s", level, string, extra); } +/* Function to log a message and an integer. */ +static void +gnutls_log_function2i (int level, const char* string, int extra) +{ + message ("gnutls.c: [%d] %s %d", level, string, extra); +} + static int emacs_gnutls_handshake (struct Lisp_Process *proc) { @@ -399,10 +408,25 @@ emacs_gnutls_read (struct Lisp_Process *proc, char *buf, ptrdiff_t nbyte) ssize_t rtnval; gnutls_session_t state = proc->gnutls_state; + int log_level = proc->gnutls_log_level; + if (proc->gnutls_initstage != GNUTLS_STAGE_READY) { - emacs_gnutls_handshake (proc); - return -1; + /* If the handshake count is under the limit, try the handshake + again and increment the handshake count. This count is kept + per process (connection), not globally. */ + if (proc->gnutls_handshakes_tried < GNUTLS_EMACS_HANDSHAKES_LIMIT) + { + proc->gnutls_handshakes_tried++; + emacs_gnutls_handshake (proc); + GNUTLS_LOG2i (5, log_level, "Retried handshake", + proc->gnutls_handshakes_tried); + return -1; + } + + GNUTLS_LOG (2, log_level, "Giving up on handshake; resetting retries"); + proc->gnutls_handshakes_tried = 0; + return 0; } rtnval = fn_gnutls_record_recv (state, buf, nbyte); if (rtnval >= 0) |