mirror of
https://github.com/tmate-io/tmate.git
synced 2025-06-20 09:37:53 +02:00
Replay commands
This commit is contained in:
parent
a7c5507464
commit
474487c33e
@ -150,13 +150,48 @@ int tmate_should_replicate_cmd(const struct cmd_entry *cmd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tmate_exec_cmd(const char *cmd)
|
#define sc (&session->saved_tmux_cmds)
|
||||||
|
#define SAVED_TMUX_CMD_INITIAL_SIZE 256
|
||||||
|
static void __tmate_exec_cmd(const char *cmd);
|
||||||
|
|
||||||
|
static void append_saved_cmd(struct tmate_session *session,
|
||||||
|
const char *cmd)
|
||||||
|
{
|
||||||
|
if (!sc->cmds) {
|
||||||
|
sc->capacity = SAVED_TMUX_CMD_INITIAL_SIZE;
|
||||||
|
sc->cmds = xmalloc(sizeof(char *) * sc->capacity);
|
||||||
|
sc->tail = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sc->tail == sc->capacity) {
|
||||||
|
sc->capacity *= 2;
|
||||||
|
sc->cmds = xrealloc(sc->cmds, sizeof(char *) * sc->capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc->cmds[sc->tail++] = xstrdup(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void replay_saved_cmd(struct tmate_session *session)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < sc->tail; i++)
|
||||||
|
__tmate_exec_cmd(sc->cmds[i]);
|
||||||
|
}
|
||||||
|
#undef sc
|
||||||
|
|
||||||
|
static void __tmate_exec_cmd(const char *cmd)
|
||||||
{
|
{
|
||||||
pack(array, 2);
|
pack(array, 2);
|
||||||
pack(int, TMATE_OUT_EXEC_CMD);
|
pack(int, TMATE_OUT_EXEC_CMD);
|
||||||
pack(string, cmd);
|
pack(string, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tmate_exec_cmd(const char *cmd)
|
||||||
|
{
|
||||||
|
__tmate_exec_cmd(cmd);
|
||||||
|
append_saved_cmd(&tmate_session, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
void tmate_failed_cmd(int client_id, const char *cause)
|
void tmate_failed_cmd(int client_id, const char *cause)
|
||||||
{
|
{
|
||||||
pack(array, 3);
|
pack(array, 3);
|
||||||
@ -363,6 +398,7 @@ void tmate_send_reconnection_state(struct tmate_session *session)
|
|||||||
|
|
||||||
tmate_write_header();
|
tmate_write_header();
|
||||||
tmate_send_reconnection_data(session);
|
tmate_send_reconnection_data(session);
|
||||||
|
replay_saved_cmd(session);
|
||||||
/* TODO send all option variables */
|
/* TODO send all option variables */
|
||||||
tmate_write_ready();
|
tmate_write_ready();
|
||||||
|
|
||||||
|
11
tmate.h
11
tmate.h
@ -175,6 +175,17 @@ struct tmate_session {
|
|||||||
struct event ev_connection_retry;
|
struct event ev_connection_retry;
|
||||||
char *last_server_ip;
|
char *last_server_ip;
|
||||||
char *reconnection_data;
|
char *reconnection_data;
|
||||||
|
/*
|
||||||
|
* When we reconnect, instead of serializing the key bindings and
|
||||||
|
* options, we replay all the tmux commands we replicated.
|
||||||
|
* It may be a little innacurate to replicate the state, but
|
||||||
|
* it's much easier.
|
||||||
|
*/
|
||||||
|
struct {
|
||||||
|
unsigned int capacity;
|
||||||
|
unsigned int tail;
|
||||||
|
char **cmds;
|
||||||
|
} saved_tmux_cmds;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct tmate_session tmate_session;
|
extern struct tmate_session tmate_session;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user