package io.netty.channel.kqueue;
import io.netty.channel.Channel;
import io.netty.channel.EventLoop;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.util.internal.UnstableApi;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import static io.netty.channel.kqueue.BsdSocket.newSocketStream;
import static io.netty.channel.unix.NativeInetAddress.address;
@UnstableApi
public final class KQueueServerSocketChannel extends AbstractKQueueServerChannel implements ServerSocketChannel {
private final KQueueServerSocketChannelConfig config;
public KQueueServerSocketChannel() {
super(newSocketStream(), false);
config = new KQueueServerSocketChannelConfig(this);
}
public KQueueServerSocketChannel(int fd) {
this(new BsdSocket(fd));
}
KQueueServerSocketChannel(BsdSocket fd) {
super(fd);
config = new KQueueServerSocketChannelConfig(this);
}
KQueueServerSocketChannel(BsdSocket fd, boolean active) {
super(fd, active);
config = new KQueueServerSocketChannelConfig(this);
}
@Override
protected boolean isCompatible(EventLoop loop) {
return loop instanceof KQueueEventLoop;
}
@Override
protected void doBind(SocketAddress localAddress) throws Exception {
super.doBind(localAddress);
socket.listen(config.getBacklog());
active = true;
}
@Override
public InetSocketAddress remoteAddress() {
return (InetSocketAddress) super.remoteAddress();
}
@Override
public InetSocketAddress localAddress() {
return (InetSocketAddress) super.localAddress();
}
@Override
public KQueueServerSocketChannelConfig config() {
return config;
}
@Override
protected Channel newChildChannel(int fd, byte[] address, int offset, int len) throws Exception {
return new KQueueSocketChannel(this, new BsdSocket(fd), address(address, offset, len));
}
}