зеркало из https://github.com/github/putty.git
Log when a network connection succeeds.
Now I've got an enum for PlugLogType, it's easier to add things to it. We were giving a blow-by-blow account of each connection attempt, and when it failed, saying what went wrong before we moved on to the next candidate address, but when one finally succeeded, we never logged _that_. Now we do.
This commit is contained in:
Родитель
91bb475087
Коммит
630cac3aa2
|
@ -28,6 +28,10 @@ void backend_socket_log(Seat *seat, LogContext *logctx,
|
|||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
||||
msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
|
||||
break;
|
||||
case PLUGLOG_CONNECT_SUCCESS:
|
||||
sk_getaddr(addr, addrbuf, lenof(addrbuf));
|
||||
msg = dupprintf("Connected to %s", addrbuf);
|
||||
break;
|
||||
case PLUGLOG_PROXY_MSG:
|
||||
/* Proxy-related log messages have their own identifying
|
||||
* prefix already, put on by our caller. */
|
||||
|
|
|
@ -47,6 +47,7 @@ struct Plug {
|
|||
typedef enum PlugLogType {
|
||||
PLUGLOG_CONNECT_TRYING,
|
||||
PLUGLOG_CONNECT_FAILED,
|
||||
PLUGLOG_CONNECT_SUCCESS,
|
||||
PLUGLOG_PROXY_MSG,
|
||||
} PlugLogType;
|
||||
|
||||
|
@ -66,6 +67,9 @@ struct PlugVtable {
|
|||
* addresses to fall back to. When it _is_ fatal, the closing()
|
||||
* function will be called.
|
||||
*
|
||||
* - PLUGLOG_CONNECT_SUCCESS means we have succeeded in
|
||||
* connecting to address `addr'.
|
||||
*
|
||||
* - PLUGLOG_PROXY_MSG means that error_msg contains a line of
|
||||
* logging information from whatever the connection is being
|
||||
* proxied through. This will typically be a wodge of
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
#include "putty.h"
|
||||
|
||||
static void nullplug_socket_log(Plug *plug, int type, SockAddr *addr, int port,
|
||||
const char *error_msg, int error_code)
|
||||
static void nullplug_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
|
||||
int port, const char *err_msg, int err_code)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
11
unix/uxnet.c
11
unix/uxnet.c
|
@ -733,6 +733,10 @@ static int try_connect(NetSocket *sock)
|
|||
*/
|
||||
sock->connected = true;
|
||||
sock->writable = true;
|
||||
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(sock->addr, &sock->step);
|
||||
plug_log(sock->plug, PLUGLOG_CONNECT_SUCCESS,
|
||||
&thisaddr, sock->port, NULL, 0);
|
||||
}
|
||||
|
||||
uxsel_tell(sock);
|
||||
|
@ -1435,6 +1439,13 @@ static void net_select_result(int fd, int event)
|
|||
}
|
||||
if (!s->connected)
|
||||
return; /* another async attempt in progress */
|
||||
} else {
|
||||
/*
|
||||
* The connection attempt succeeded.
|
||||
*/
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(s->addr, &s->step);
|
||||
plug_log(s->plug, PLUGLOG_CONNECT_SUCCESS,
|
||||
&thisaddr, s->port, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1068,6 +1068,9 @@ static DWORD try_connect(NetSocket *sock)
|
|||
* and we should set the socket as writable.
|
||||
*/
|
||||
sock->writable = true;
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(sock->addr, &sock->step);
|
||||
plug_log(sock->plug, PLUGLOG_CONNECT_SUCCESS,
|
||||
&thisaddr, sock->port, NULL, 0);
|
||||
}
|
||||
|
||||
err = 0;
|
||||
|
@ -1546,12 +1549,18 @@ void select_result(WPARAM wParam, LPARAM lParam)
|
|||
case FD_CONNECT:
|
||||
s->connected = true;
|
||||
s->writable = true;
|
||||
|
||||
/*
|
||||
* Once a socket is connected, we can stop falling
|
||||
* back through the candidate addresses to connect
|
||||
* to.
|
||||
* Once a socket is connected, we can stop falling back
|
||||
* through the candidate addresses to connect to. But first,
|
||||
* let the plug know we were successful.
|
||||
*/
|
||||
if (s->addr) {
|
||||
SockAddr thisaddr = sk_extractaddr_tmp(
|
||||
s->addr, &s->step);
|
||||
plug_log(s->plug, PLUGLOG_CONNECT_SUCCESS,
|
||||
&thisaddr, s->port, NULL, 0);
|
||||
|
||||
sk_addr_free(s->addr);
|
||||
s->addr = NULL;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче