Home / Function/ connect() — netty Function Reference

connect() — netty Function Reference

Architecture documentation for the connect() function in AbstractIoUringChannel.java from the netty codebase.

Function java Buffer Telemetry calls 5 called by 1

Entity Profile

Dependency Diagram

graph TD
  793ea166_f553_4dcf_4a30_68f00e4e6f0f["connect()"]
  19011d76_ce85_4831_bbdf_3b21a88f2b1b["AbstractUringUnsafe"]
  793ea166_f553_4dcf_4a30_68f00e4e6f0f -->|defined in| 19011d76_ce85_4831_bbdf_3b21a88f2b1b
  02484f5e_fddd_74b7_e73c_1b14fb1d53cf["writeComplete()"]
  02484f5e_fddd_74b7_e73c_1b14fb1d53cf -->|calls| 793ea166_f553_4dcf_4a30_68f00e4e6f0f
  27b7f7cc_cc2f_f8b9_169c_fc129d8faa72["checkResolvable()"]
  793ea166_f553_4dcf_4a30_68f00e4e6f0f -->|calls| 27b7f7cc_cc2f_f8b9_169c_fc129d8faa72
  74154ae0_fd75_6c44_c1e5_89945141fcf3["freeMsgHdrArray()"]
  793ea166_f553_4dcf_4a30_68f00e4e6f0f -->|calls| 74154ae0_fd75_6c44_c1e5_89945141fcf3
  bc850991_35d5_bd07_eff9_1c3e0ca878dc["submitConnect()"]
  793ea166_f553_4dcf_4a30_68f00e4e6f0f -->|calls| bc850991_35d5_bd07_eff9_1c3e0ca878dc
  941f2659_0934_3a6d_3c64_960438f90518["close()"]
  793ea166_f553_4dcf_4a30_68f00e4e6f0f -->|calls| 941f2659_0934_3a6d_3c64_960438f90518
  67b2aa6c_a298_76f6_3e5b_4d861b518d3c["cancelConnectTimeoutFuture()"]
  793ea166_f553_4dcf_4a30_68f00e4e6f0f -->|calls| 67b2aa6c_a298_76f6_3e5b_4d861b518d3c
  style 793ea166_f553_4dcf_4a30_68f00e4e6f0f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringChannel.java lines 1055–1166

        @Override
        public void connect(
                final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {
            // Don't mark the connect promise as uncancellable as in fact we can cancel it as it is using
            // non-blocking io.
            if (promise.isDone() || !ensureOpen(promise)) {
                return;
            }

            if (delayedClose != null) {
                promise.tryFailure(annotateConnectException(new ClosedChannelException(), remoteAddress));
                return;
            }
            try {
                if (connectPromise != null) {
                    throw new ConnectionPendingException();
                }
                if (localAddress instanceof InetSocketAddress) {
                    checkResolvable((InetSocketAddress) localAddress);
                }

                if (remoteAddress instanceof InetSocketAddress) {
                    checkResolvable((InetSocketAddress) remoteAddress);
                }

                if (remote != null) {
                    // Check if already connected before trying to connect. This is needed as connect(...) will not#
                    // return -1 and set errno to EISCONN if a previous connect(...) attempt was setting errno to
                    // EINPROGRESS and finished later.
                    throw new AlreadyConnectedException();
                }

                if (localAddress != null) {
                    socket.bind(localAddress);
                }

                if (remoteAddress instanceof InetSocketAddress) {
                    InetSocketAddress inetSocketAddress = (InetSocketAddress) remoteAddress;
                    ByteBuf initialData = null;
                    if (IoUring.isTcpFastOpenClientSideAvailable() &&
                        config().getOption(ChannelOption.TCP_FASTOPEN_CONNECT) == Boolean.TRUE) {
                        ChannelOutboundBuffer outbound = unsafe().outboundBuffer();
                        outbound.addFlush();
                        Object curr;
                        if ((curr = outbound.current()) instanceof ByteBuf) {
                            initialData = (ByteBuf) curr;
                        }
                    }
                    if (initialData != null) {
                        msgHdrMemoryArray = new MsgHdrMemoryArray((short) 1);
                        MsgHdrMemory hdr = msgHdrMemoryArray.hdr(0);
                        hdr.set(socket, inetSocketAddress, IoUring.memoryAddress(initialData),
                                initialData.readableBytes(), (short) 0);

                        int fd = fd().intValue();
                        IoRegistration registration = registration();
                        IoUringIoOps ops = IoUringIoOps.newSendmsg(fd, (byte) 0, Native.MSG_FASTOPEN,
                                hdr.address(), hdr.idx());
                        connectId = registration.submit(ops);
                        if (connectId == 0) {
                            // Directly release the memory if submitting failed.
                            freeMsgHdrArray();
                        }
                    } else {
                        submitConnect(inetSocketAddress);
                    }
                } else if (remoteAddress instanceof DomainSocketAddress) {
                    DomainSocketAddress unixDomainSocketAddress = (DomainSocketAddress) remoteAddress;
                    submitConnect(unixDomainSocketAddress);
                } else {
                    throw new Error("Unexpected SocketAddress implementation " + className(remoteAddress));
                }

                if (connectId != 0) {
                    ioState |= CONNECT_SCHEDULED;
                }
            } catch (Throwable t) {
                closeIfClosed();
                promise.tryFailure(annotateConnectException(t, remoteAddress));
                return;
            }

Domain

Subdomains

Called By

Frequently Asked Questions

What does connect() do?
connect() is a function in the netty codebase, defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringChannel.java.
Where is connect() defined?
connect() is defined in transport-classes-io_uring/src/main/java/io/netty/channel/uring/AbstractIoUringChannel.java at line 1055.
What does connect() call?
connect() calls 5 function(s): cancelConnectTimeoutFuture, checkResolvable, close, freeMsgHdrArray, submitConnect.
What calls connect()?
connect() is called by 1 function(s): writeComplete.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free