package com.seewo.remote.e.d;

import com.seewo.remote.e.h.g;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/* JADX INFO: compiled from: AbstractTCPConnector.java */
/* JADX INFO: loaded from: classes.dex */
public class a {
    private int a;
    private com.seewo.remote.e.i.a b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private EventLoopGroup f42c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private EventLoopGroup f43d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private ServerBootstrap f44e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Channel f45f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private g f46g;

    public a(int i2, com.seewo.remote.e.i.a aVar) {
        this.a = i2;
        this.b = aVar;
    }

    private void a() {
        if (this.f46g == null) {
            g gVar = new g(this.b);
            this.f46g = gVar;
            this.f44e.childHandler(gVar);
        }
    }

    private void b() {
        if (this.f46g != null) {
            this.f46g = null;
        }
    }

    public void c() {
        this.f42c = new NioEventLoopGroup();
        this.f43d = new NioEventLoopGroup();
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        this.f44e = serverBootstrap;
        serverBootstrap.group(this.f42c, this.f43d).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 32).childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
        a();
        this.f45f = this.f44e.bind(this.a).channel();
    }

    public void d() {
        b();
        Channel channel = this.f45f;
        if (channel != null) {
            channel.close();
            this.f45f = null;
        }
        EventLoopGroup eventLoopGroup = this.f42c;
        if (eventLoopGroup != null) {
            eventLoopGroup.shutdownGracefully();
            this.f42c = null;
        }
        EventLoopGroup eventLoopGroup2 = this.f43d;
        if (eventLoopGroup2 != null) {
            eventLoopGroup2.shutdownGracefully();
            this.f43d = null;
        }
        this.f44e = null;
    }
}
