ZOld Assignment: 2. 3‐way Handshake - ANLAB-KAIST/KENSv3 GitHub Wiki
As we have covered in the lectures, TCP connection setup is done via 3-way handshake. When the client side initiates the connection setup by calling connect()
,
case CONNECT:
// this->syscall_connect(syscallUUID, pid, param.param1_int,
// static_cast<struct sockaddr*>(param.param2_ptr),
// (socklen_t)param.param3_int);
break;
The connect()
call receives 3 parameters from the application layer. It connects the file descriptor to the address specified by addr
. More details about the socket call are described https://man7.org/linux/man-pages/man2/connect.2.html and https://man7.org/linux/man-pages/man3/connect.3p.html.
case LISTEN:
// this->syscall_listen(syscallUUID, pid, param.param1_int,
// param.param2_int);
break;
The listen()
call receives 2 parameters from the application layer. It marks the socket as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept. KENS requires you to implement the backlog parameter. It defines the maximum length to which the queue of pending connections for sockfd
may grow. More details about the socket call are described https://man7.org/linux/man-pages/man2/listen.2.html and https://man7.org/linux/man-pages/man3/listen.3p.html .
*Caution
In KENS, the
listen()
’s backlog specifies the queue length for incomplete connection requests as before Linux 2.2. See NOTES section of listen(2).
case ACCEPT:
// this->syscall_accept(syscallUUID, pid, param.param1_int,
// static_cast<struct sockaddr*>(param.param2_ptr),
// static_cast<socklen_t*>(param.param3_ptr));
break;
The accept()
call receives 3 parameters from the application layer. It extracts the first connection on the queue of pending connections. It creates and returns a new file descriptor for the connection. It also fills the address parameter with connecting client’s information. More details about the socket call are described https://man7.org/linux/man-pages/man2/accept.2.html and https://man7.org/linux/man-pages/man3/accept.3p.html .
case CLOSE:
// this->syscall_close(syscallUUID, pid, param.param1_int);
break;
The close()
call receives a parameter from the application layer. It closes the file descriptor’s connection and deallocates the file descriptor. More details about the socket call are described https://man7.org/linux/man-pages/man2/close.2.html and https://man7.org/linux/man-pages/man3/close.3p.html .