Extend management socket state

Distinguish between management socket connected and
ready for interaction with the server. The former can
happen even if the server is connected to another client
and thus non-responsive.

Use manage.connected = 1 in place of true when connected
and = 2 when handshake with server completed and ready for
input.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/519/head
Selva Nair 2 years ago
parent e417976b27
commit 0baf486cb4

@ -65,7 +65,7 @@ OpenManagement(connection_t *c)
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
return FALSE; return FALSE;
c->manage.connected = FALSE; c->manage.connected = 0;
c->manage.sk = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); c->manage.sk = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (c->manage.sk == INVALID_SOCKET) if (c->manage.sk == INVALID_SOCKET)
{ {
@ -219,7 +219,7 @@ OnManagement(SOCKET sk, LPARAM lParam)
} }
} }
else else
c->manage.connected = TRUE; c->manage.connected = 1;
break; break;
case FD_READ: case FD_READ:
@ -337,6 +337,7 @@ OnManagement(SOCKET sk, LPARAM lParam)
{ {
/* delay until management interface accepts input */ /* delay until management interface accepts input */
Sleep(100); Sleep(100);
c->manage.connected = 2;
if (rtmsg_handler[ready_]) if (rtmsg_handler[ready_])
rtmsg_handler[ready_](c, pos + 5); rtmsg_handler[ready_](c, pos + 5);
} }
@ -437,7 +438,7 @@ CloseManagement(connection_t *c)
} }
closesocket(c->manage.sk); closesocket(c->manage.sk);
c->manage.sk = INVALID_SOCKET; c->manage.sk = INVALID_SOCKET;
c->manage.connected = FALSE; c->manage.connected = 0;
while (UnqueueCommand(c)) while (UnqueueCommand(c))
; ;
WSACleanup(); WSACleanup();

@ -1787,7 +1787,7 @@ DisconnectDaemon(connection_t *c)
{ {
if (c->flags & FLAG_DAEMON_PERSISTENT) if (c->flags & FLAG_DAEMON_PERSISTENT)
{ {
if (c->manage.connected) if (c->manage.connected > 1) /* connected and ready for input */
{ {
ManagementCommand(c, "hold on", NULL, regular); ManagementCommand(c, "hold on", NULL, regular);
ManagementCommand(c, "signal SIGHUP", NULL, regular); ManagementCommand(c, "signal SIGHUP", NULL, regular);

@ -146,7 +146,7 @@ struct connection {
char *saved_data; char *saved_data;
size_t saved_size; size_t saved_size;
mgmt_cmd_t *cmd_queue; mgmt_cmd_t *cmd_queue;
BOOL connected; /* True, if management interface has connected */ DWORD connected; /* 1: management interface connected, 2: connected and ready */
} manage; } manage;
HANDLE hProcess; /* Handle of openvpn process if directly started */ HANDLE hProcess; /* Handle of openvpn process if directly started */

Loading…
Cancel
Save