mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-22 09:39:13 +00:00
sockets: Helper for scheduling acc job
There's only one place with this, but the helper makes the code look almost perfectly. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
This commit is contained in:
parent
bc9089e57e
commit
5b8c7bbf84
1 changed files with 33 additions and 31 deletions
64
sockets.c
64
sockets.c
|
|
@ -784,6 +784,36 @@ struct unix_accept_job {
|
|||
|
||||
static struct unix_accept_job *accept_jobs;
|
||||
|
||||
static int schedule_acc_job(int sk, struct unix_sk_entry *ue)
|
||||
{
|
||||
struct sockaddr_un addr;
|
||||
int len;
|
||||
struct unix_accept_job *aj;
|
||||
|
||||
prep_conn_addr(ue->id, &addr, &len);
|
||||
if (bind(sk, (struct sockaddr *)&addr, len) < 0) {
|
||||
pr_perror("Can't bind socket");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (listen(sk, 1) < 0) {
|
||||
pr_perror("Can't listen socket");
|
||||
goto err;
|
||||
}
|
||||
|
||||
aj = xmalloc(sizeof(*aj));
|
||||
if (aj == NULL)
|
||||
goto err;
|
||||
|
||||
aj->fd = ue->fd;
|
||||
aj->next = accept_jobs;
|
||||
accept_jobs = aj;
|
||||
unix_show_job("Sched acc", ue->fd, ue->id);
|
||||
return 0;
|
||||
err:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int run_accept_jobs(void)
|
||||
{
|
||||
struct unix_accept_job *aj, *next;
|
||||
|
|
@ -892,37 +922,9 @@ static int open_unix_sk_stream(int sk, struct unix_sk_entry *ue, int img_fd)
|
|||
* deferred to connect() later.
|
||||
*/
|
||||
|
||||
if (ue->peer < ue->id && !(ue->flags & USK_INFLIGHT)) {
|
||||
struct sockaddr_un addr;
|
||||
int len;
|
||||
struct unix_accept_job *aj;
|
||||
|
||||
/*
|
||||
* Will become a server
|
||||
*/
|
||||
|
||||
ret = -1;
|
||||
prep_conn_addr(ue->id, &addr, &len);
|
||||
if (bind(sk, (struct sockaddr *)&addr, len) < 0) {
|
||||
pr_perror("Can't bind socket");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (listen(sk, 1) < 0) {
|
||||
pr_perror("Can't listen socket");
|
||||
goto out;
|
||||
}
|
||||
|
||||
aj = xmalloc(sizeof(*aj));
|
||||
if (aj == NULL)
|
||||
goto out;
|
||||
|
||||
aj->fd = ue->fd;
|
||||
aj->next = accept_jobs;
|
||||
accept_jobs = aj;
|
||||
unix_show_job("Sched acc", ue->fd, ue->id);
|
||||
ret = 0;
|
||||
} else
|
||||
if (ue->peer < ue->id && !(ue->flags & USK_INFLIGHT))
|
||||
ret = schedule_acc_job(sk, ue);
|
||||
else
|
||||
ret = schedule_conn_job((ue->flags & USK_INFLIGHT) ?
|
||||
CJ_STREAM_INFLIGHT : CJ_STREAM, ue);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue