rename ssh_connect_flag to ssh_estab_queue

This commit is contained in:
Ryo Nakamura
2023-03-14 01:20:55 +09:00
parent 72c27f16d6
commit 3077bb0856

View File

@@ -13,7 +13,7 @@
#include <message.h> #include <message.h>
#include <mscp.h> #include <mscp.h>
struct ssh_connect_flag { struct ssh_estab_queue {
lock lock; lock lock;
struct timeval enter; struct timeval enter;
long delay; /* msec */ long delay; /* msec */
@@ -32,32 +32,32 @@ static long timeval_sub(struct timeval a, struct timeval b)
return sec * 1000000 + usec; return sec * 1000000 + usec;
} }
static void ssh_connect_flag_init(struct ssh_connect_flag *f) static void ssh_estab_queue_init(struct ssh_estab_queue *q)
{ {
memset(f, 0, sizeof(f)); memset(q, 0, sizeof(q));
lock_init(&f->lock); lock_init(&q->lock);
f->delay = 10000; /* To be configurable */ q->delay = 10000; /* To be configurable */
} }
static void ssh_connect_ready(struct ssh_connect_flag *f) static void ssh_estab_queue_ready(struct ssh_estab_queue *q)
{ {
struct timeval now; struct timeval now;
long delta; long delta;
LOCK_ACQUIRE_THREAD(&f->lock); LOCK_ACQUIRE_THREAD(&q->lock);
if (f->enter.tv_sec == 0 && f->enter.tv_usec == 0) { if (q->enter.tv_sec == 0 && q->enter.tv_usec == 0) {
/* I'm the first one. */ /* I'm the first one. */
goto ready; goto ready;
} }
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
delta = timeval_sub(now, f->enter); delta = timeval_sub(now, q->enter);
if (delta <= f->delay) { if (delta <= q->delay) {
/* wait until enter + delay time */ /* wait until enter + delay time */
usleep(f->delay - delta); usleep(q->delay - delta);
} }
ready: ready:
gettimeofday(&f->enter, NULL); gettimeofday(&q->enter, NULL);
LOCK_RELEASE_THREAD(); LOCK_RELEASE_THREAD();
} }
@@ -74,7 +74,7 @@ struct mscp {
int *cores; /* usable cpu cores by COREMASK */ int *cores; /* usable cpu cores by COREMASK */
int nr_cores; /* length of array of cores */ int nr_cores; /* length of array of cores */
struct ssh_connect_flag ssh_flag; struct ssh_estab_queue ssh_queue;
sftp_session first; /* first sftp session */ sftp_session first; /* first sftp session */
@@ -270,7 +270,7 @@ struct mscp *mscp_init(const char *remote_host, int direction,
INIT_LIST_HEAD(&m->src_list); INIT_LIST_HEAD(&m->src_list);
INIT_LIST_HEAD(&m->path_list); INIT_LIST_HEAD(&m->path_list);
chunk_pool_init(&m->cp); chunk_pool_init(&m->cp);
ssh_connect_flag_init(&m->ssh_flag); ssh_estab_queue_init(&m->ssh_queue);
m->remote = strdup(remote_host); m->remote = strdup(remote_host);
if (!m->remote) { if (!m->remote) {
@@ -590,7 +590,7 @@ void *mscp_copy_thread(void *arg)
} }
} }
ssh_connect_ready(&m->ssh_flag); ssh_estab_queue_ready(&m->ssh_queue);
mpr_notice(m->msg_fd, "connecting to %s for a copy thread...\n", m->remote); mpr_notice(m->msg_fd, "connecting to %s for a copy thread...\n", m->remote);
t->sftp = ssh_init_sftp_session(m->remote, m->ssh_opts); t->sftp = ssh_init_sftp_session(m->remote, m->ssh_opts);
if (!t->sftp) { if (!t->sftp) {