소켓 옵션

- 소켓의 특성을 변경시킬 때 사용하는 옵션 정보
프로토콜 레벨들
IPPROTO_IP : IP 프로토콜과 관련된 사항
IPPROTO_TCP : TCP 프로토콜과 관련된 사항
SOL_SOCKET : 소켓에 대한 가장 일반적인 옵션
옵션정보 참조하기
#include <sys/socket.h>
int getsockopt(int sock, int level, int optname, void* optival, socklen_t* optlen);
성공시 0, 실패시 -1을 반환한다.
- sock : 옵션확인을 위한 소켓의 파일 디스크립터 전달
- level : 확인할 옵션의 프로토콜 레벨 전달
- optname : 확인할 옵션의 이름 전달
- optval : 확인 결과의 저장을 위한 버퍼의 주소 값 전달
- optlen : 함수호출이 완료시, 이 변수에는 네번째 인자를 통해 반환된 옵션 정보의 크기가 바이트 단위로 계산되어 저장.
- 사이즈를 받아와야 하기에 socklen_t 변수를 따로 선언하고 포인터로 줘야 한다.

옵션정보 설정하기
#include <sys/socket.h>
int setsockopt(int sock, int level, int optname, void* optival, sock_t optlen);
성공시 0, 실패시 -1반환
- sock : 옵션 변경을 위한 소켓의 파일 디스크립터 전달
- level : 변경할 옵션의 프로토콜 레벨 전달
- optname : 변경할 옵션의 이름전달
- optval : 변경할 옵션 정보를 저장할 버퍼의 주소 값 전달
- optlen : 네번째 매개변수 optval으로 전달된 바이트 단위 크기 전달
- 여기선 포인터가 아니라 optval 자체의 크기를 전달하면 된다.
SO_REUSEADDR
주소 할당 에러의 원인 time-wait
Time-wait

- 마지막 ACK가 소멸될수 있는 상태에 대비하기 위해 FIN을 새로 받기 위해 어느정도 기다린다. ( time-wait )
- time wait 동안은 그 포트는 사용할수 없다, 소켓이 사라진것이 아니기 때문이다.

- time-wait 무시하고 할당이 가능하도록 한다.
TCP_NODELAY
- Nagle 알고리즘은 기본적으로 켜져 있다.

