mirror of
https://github.com/tmate-io/tmate.git
synced 2025-06-19 17:17:53 +02:00
Cleanup hacks around ev_ssh.ev_flags
Fixes #69 Fix suggested by Leon M. George <leon@georgemail.eu>
This commit is contained in:
parent
6dc58ab6de
commit
c1846177fc
@ -162,18 +162,23 @@ static void request_passphrase(struct tmate_ssh_client *client)
|
|||||||
data->password_cb_private = client;
|
data->password_cb_private = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void register_session_fd_event(struct tmate_ssh_client *client)
|
static void init_conn_fd(struct tmate_ssh_client *client)
|
||||||
{
|
{
|
||||||
if (!event_initialized(&client->ev_ssh)) {
|
if (client->has_init_conn_fd)
|
||||||
int flag = 1;
|
return;
|
||||||
setsockopt(ssh_get_fd(client->session), IPPROTO_TCP,
|
|
||||||
TCP_NODELAY, &flag, sizeof(flag));
|
|
||||||
|
|
||||||
event_assign(&client->ev_ssh, client->tmate_session->ev_base,
|
if (ssh_get_fd(client->session) < 0)
|
||||||
ssh_get_fd(client->session),
|
return;
|
||||||
EV_READ | EV_PERSIST, __on_ssh_client_event, client);
|
|
||||||
event_add(&client->ev_ssh, NULL);
|
int flag = 1;
|
||||||
}
|
setsockopt(ssh_get_fd(client->session), IPPROTO_TCP,
|
||||||
|
TCP_NODELAY, &flag, sizeof(flag));
|
||||||
|
|
||||||
|
event_set(&client->ev_ssh, ssh_get_fd(client->session),
|
||||||
|
EV_READ | EV_PERSIST, __on_ssh_client_event, client);
|
||||||
|
event_add(&client->ev_ssh, NULL);
|
||||||
|
|
||||||
|
client->has_init_conn_fd = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_ssh_client_event(struct tmate_ssh_client *client)
|
static void on_ssh_client_event(struct tmate_ssh_client *client)
|
||||||
@ -232,14 +237,15 @@ static void on_ssh_client_event(struct tmate_ssh_client *client)
|
|||||||
case SSH_CONNECT:
|
case SSH_CONNECT:
|
||||||
switch (ssh_connect(session)) {
|
switch (ssh_connect(session)) {
|
||||||
case SSH_AGAIN:
|
case SSH_AGAIN:
|
||||||
register_session_fd_event(client);
|
init_conn_fd(client);
|
||||||
return;
|
return;
|
||||||
case SSH_ERROR:
|
case SSH_ERROR:
|
||||||
reconnect_ssh_client(client, "Error connecting: %s",
|
reconnect_ssh_client(client, "Error connecting: %s",
|
||||||
ssh_get_error(session));
|
ssh_get_error(session));
|
||||||
return;
|
return;
|
||||||
case SSH_OK:
|
case SSH_OK:
|
||||||
register_session_fd_event(client);
|
init_conn_fd(client);
|
||||||
|
|
||||||
tmate_debug("Establishing connection to %s", client->server_ip);
|
tmate_debug("Establishing connection to %s", client->server_ip);
|
||||||
client->state = SSH_AUTH_SERVER;
|
client->state = SSH_AUTH_SERVER;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
@ -383,9 +389,9 @@ static void __kill_ssh_client(struct tmate_ssh_client *client,
|
|||||||
else
|
else
|
||||||
tmate_debug("Disconnecting %s", client->server_ip);
|
tmate_debug("Disconnecting %s", client->server_ip);
|
||||||
|
|
||||||
if (event_initialized(&client->ev_ssh)) {
|
if (client->has_init_conn_fd) {
|
||||||
event_del(&client->ev_ssh);
|
event_del(&client->ev_ssh);
|
||||||
client->ev_ssh.ev_flags = 0;
|
client->has_init_conn_fd = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->session) {
|
if (client->session) {
|
||||||
@ -476,7 +482,7 @@ struct tmate_ssh_client *tmate_ssh_client_alloc(struct tmate_session *session,
|
|||||||
client->channel = NULL;
|
client->channel = NULL;
|
||||||
client->has_encoder = 0;
|
client->has_encoder = 0;
|
||||||
|
|
||||||
client->ev_ssh.ev_flags = 0;
|
client->has_init_conn_fd = false;
|
||||||
|
|
||||||
evtimer_assign(&client->ev_ssh_reconnect, session->ev_base,
|
evtimer_assign(&client->ev_ssh_reconnect, session->ev_base,
|
||||||
on_reconnect_timer, client);
|
on_reconnect_timer, client);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user