@Override protected void doBind(SocketAddress localAddress) throws Exception { super.doBind(localAddress); // TODO(scott): tcp fast open here! socket.listen(config.getBacklog()); active = true; }
@Override @SuppressWarnings("deprecation") public boolean isActive() { return socket.isOpen() && (config.getActiveOnOpen() && isRegistered() || active); }
@Override public void run() { if (!unsafe.readPending && !config().isAutoRead()) { // Still no read triggered so clear it now unsafe.clearReadFilter0(); } } });
@Override protected void doDeregister() throws Exception { // Make sure we unregister our filters from kqueue! readFilter(false); writeFilter(false); evSet0(Native.EVFILT_SOCK, Native.EV_DELETE, 0); ((KQueueEventLoop) eventLoop()).remove(this); }
final void readEOF() { // This must happen before we attempt to read. This will ensure reading continues until an error occurs. final KQueueRecvByteAllocatorHandle allocHandle = recvBufAllocHandle(); allocHandle.readEOF(); if (isActive()) { // If it is still active, we need to call readReady as otherwise we may miss to // read pending data from the underlying file descriptor. // See https://github.com/netty/netty/issues/3709 readReady(allocHandle); } else { // Just to be safe make sure the input marked as closed. shutdownInput(true); } }
@Override public <T> boolean setOption(ChannelOption<T> option, T value) { validate(option, value); if (option == SO_REUSEPORT) { setReusePort((Boolean) value); } else if (option == SO_ACCEPTFILTER) { setAcceptFilter((AcceptFilter) value); } else { return super.setOption(option, value); } return true; }
void evSet(AbstractKQueueChannel ch, short filter, short flags, int fflags) { reallocIfNeeded(); evSet(getKEventOffset(size++) + memoryAddress, ch.socket.intValue(), filter, flags, fflags); }
@Override protected void doBind(SocketAddress localAddress) throws Exception { socket.bind(localAddress); socket.listen(config.getBacklog()); local = (DomainSocketAddress) localAddress; active = true; }
@Override public <T> boolean setOption(ChannelOption<T> option, T value) { validate(option, value); if (option == DOMAIN_SOCKET_READ_MODE) { setReadMode((DomainSocketReadMode) value); } else { return super.setOption(option, value); } return true; }
@Override protected void doBind(SocketAddress local) throws Exception { if (local instanceof InetSocketAddress) { checkResolvable((InetSocketAddress) local); } socket.bind(local); this.local = socket.localAddress(); }
AcceptFilter getAcceptFilter() throws IOException { String[] result = getAcceptFilter(intValue()); return result == null ? PLATFORM_UNSUPPORTED : new AcceptFilter(result[0], result[1]); }
@Override protected Channel newChildChannel(int fd, byte[] addr, int offset, int len) throws Exception { return new KQueueDomainSocketChannel(this, new BsdSocket(fd)); }
@Override public Map<ChannelOption<?>, Object> getOptions() { return getOptions( super.getOptions(), SO_RCVBUF, SO_SNDBUF, TCP_NODELAY, SO_KEEPALIVE, SO_REUSEADDR, SO_LINGER, IP_TOS, ALLOW_HALF_CLOSURE, SO_SNDLOWAT, TCP_NOPUSH); }
private void adjustMaxBytesPerGatheringWrite(long attempted, long written, long oldMaxBytesPerGatheringWrite) { // By default we track the SO_SNDBUF when ever it is explicitly set. However some OSes may dynamically change // SO_SNDBUF (and other characteristics that determine how much data can be written at once) so we should try // make a best effort to adjust as OS behavior changes. if (attempted == written) { if (attempted << 1 > oldMaxBytesPerGatheringWrite) { config().setMaxBytesPerGatheringWrite(attempted << 1); } } else if (attempted > MAX_BYTES_PER_GATHERING_WRITE_ATTEMPTED_LOW_THRESHOLD && written < attempted >>> 1) { config().setMaxBytesPerGatheringWrite(attempted >>> 1); } }
@SuppressWarnings("unchecked") @Override public <T> T getOption(ChannelOption<T> option) { if (option == DOMAIN_SOCKET_READ_MODE) { return (T) getReadMode(); } return super.getOption(option); }
@Override @SuppressWarnings("deprecation") public Map<ChannelOption<?>, Object> getOptions() { return getOptions( super.getOptions(), SO_BROADCAST, SO_RCVBUF, SO_SNDBUF, SO_REUSEADDR, IP_MULTICAST_LOOP_DISABLED, IP_MULTICAST_ADDR, IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_TOS, DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION, SO_REUSEPORT); }
public KQueueDatagramChannel() { super(null, newSocketDgram(), false); config = new KQueueDatagramChannelConfig(this); }
public KQueueSocketChannel() { super(null, BsdSocket.newSocketStream(), false); config = new KQueueSocketChannelConfig(this); }
@Override public Map<ChannelOption<?>, Object> getOptions() { return getOptions(super.getOptions(), DOMAIN_SOCKET_READ_MODE); }