Loading the catalog…
Loading the catalog…
시작하기에 앞서.. 여기서는 Tomcat이 리스닝 소켓을 생성하는 예시로 과정을 작성한다. 소켓 생성을 트리거 하는 주체(Tomcat) → 리눅스 커널까지 1. Tomcat → 트리거 Spring Boot가 실행되기 위해 톰캣도 실행되고 톰캣 내부적으로 Connector라는 주체가 소켓을 생성하기 위한 함수를 트리거 한다. 단계 Tomcat 부팅 (Spring Boot면 내장 톰캣 시작) Connector 생성/초기화 Connector start 과정에서 포트 바인드(bind) 수행 Acceptor thread 시작(accept loop) 이제부터 연결을 받기 시작 2. 톰캣 내부 - NioEndpoint bind() 함수 호출 package org.apache.tomcat.util.net; public class NioEndpoint extends ... { @Override public void bind() throws Exception { **initServerSocket();** ... } } initServerSocket() 함수 호출 open과 bind를 주도하는 ServerSocketChannel 객체 (구현체는 ServerSocketChannelImpl) 추상적으로 느껴지는건 저 객체를 통해, 소켓을 생성하고 8080에 바인딩 하나? 싶다. 내부를 까보면서 구체적으로 알아보자. protected void initServerSocket() throws Exception { if (getUseInheritedChannel()) { ... } else { **serverSock = ServerSocketChannel.open();** socketProperties.setProperties(**serverSock.socket()**); InetSocketAddress addr = new InetSocketAddress(getAddress(), getPortWithOffset()); **serverSock.bind**(addr, getAcceptCount()); } serverSock.configureBlocking(true); } 3. JDK - ServerSocketChannel (참고) ServerSocketChannel은 리스닝 소켓을 추상화하는 클래스이다. package java.nio.channels; ServerSocketChannel 추상 클래스는 자바 표준 API(스펙)이다. (이 추상화를 구체적으로 구현한 구현체들이 있을 것이다.) 따라서 open bind accept 와 같은 중요 메서드들의 스펙을 보여주고 있다. ServerSocketChannel - open() open() 함수를 통해 소켓을 생성하고, ServerSocketChannel 객체를 통해 connection을 제어한다. 내부적으로는 소켓을 생성하는 시스템 콜로 이어질 것으로 보인다. (리눅스 커널이 소켓 자원 확보 → FD 반환) // ServerSocketChannel - open() public static ServerSocketChannel open() throws IOException { return SelectorProvider.provider().openServerSocketChannel(); } 4. ServerSocketChannelImpl package sun.nio.ch; 자바 표준 API를 구현한 구현체 클래스이다. 위에서 호출했던 openServerSocketChannel() 함수가 구현되어 있다. @Override public ServerSocketChannel openServerSocketChannel() throws IOException { return new ServerSocketChannelImpl(this); } 자신을 생성하는 생성자를 호출하고, 생성자를 거쳐 최종적으로 아래 코드가 호출된다. ```java ServerSocketChannelImpl(SelectorProvider sp, ProtocolFamily family) throws IOException { ... if (family == UNIX) { this.fd = UnixDomainSockets.socket(); } else { **this.fd = Net.serverSocket(family);** } this.fdVal = IOUtil.fdVal(fd); } ``` Net 클래스 안으로 진입해야, 그제서야 native 코드를 만날 수 있다. 5. Net serverSocket() 이 함수 내부에서 native함수인 socket0이 호출되고, 생성된 소켓에 대한 fd를 반환 받을 수 있다. static FileDescriptor serverSocket(ProtocolFamily family) { boolean preferIPv6 = isIPv6Available() && (family != StandardProtocolFamily.INET); **return IOUtil.newFD(socket0(preferIPv6, true, true, FAST_LOOPBACK));** } private static **native** int socket0(boolean preferIPv6, boolean stream, boolean reuse, boolean fastLoopback);
What RADAR observed and classified to build this opportunity. It is what the source published, not a verification that the offer is still active.
시스템 콜(System Call)이 커널(Kernel)에 이르기까지..(feat. Java). 시작하기에 앞서.. 여기서는 Tomcat이 리스닝 소켓을 생성하는 예시로 과정을 작성한다. 소켓 생성을 트리거 하는 주체(Tomcat) → 리눅스 커널까지 1. Tomcat → 트리거 Spring Boot가 실행되기 위해 톰캣도 실행되고 톰캣 내부적으로 Connector라는 주체가 소켓을 생성하기 위한 함수를 트리거 한다. 단계 Tomcat 부팅 (Spring Boot면 내장 톰캣 시작) Connector 생성/초기화 Connector start 과정에서 포트 바인드(bind) 수행 Acceptor thread 시작(accept loop) 이제부터 연결을 받기 시작 2. 톰캣 내부 - NioEndpoint…
Open source