// External functs.
malloc, free, write, open, read, close, mkdir,
rmdir, unlink, fork, wait, waitpid, wait3, wait4,
signal, kill, exit, htons, htonl, ntohs, ntohl,
getcwd, chdir, stat, lstat, fstat, lseek, opendir,
readdir, closedir, execve, dup, dup2, pipe,
strerror, errno, gettimeofday, strptime, strftime,
usleep, select, socket, accept, listen, send, recv,
bind, connect, inet_addr, setsockopt, getsockname,
fcntl
select
#include <sys/select.h>
int select(int nfds, fd_set *restrict readfds,
fd_set *restrict writefds,
fd_set *restrict exceptfds,
struct timeval *restrict timeout);
소켓 프로그래밍 관련 함수들
소켓 프로그래밍. (Socket Programming)
socket
#include <sys/socket.h>
int socket(int domain, int type, int protocol);
/**
* @brief: create socket.
*
* @param domain: 어떤 영역에서 통신?
* ex) AF_UNIX, AF_INET, AF_INET6 ...
* @param type: 어떤 서비스 타입의 소켓을 생성?
* ex) SOCK_STREAM(TCP), SOCK_DGRAM(UDP), SOCK_RAW(RAW)
* @param protocol: 소켓에서 사용할 프로토콜
* ex) IPPROTO_TCP:TCP, IPPROTO_UDP:UDP
*
* @return value: -1:fail, 0 or above: socket discruptor.
*/
//TCP, ipv4 domain
serv_socket=socket(PF_INET, SOCK_STREAM, 0);
if (serv_socket == -1)
printf("socket error\\n");
//protocol, address
bind
int bind(int sockfd, struct sockaddr *myaddr, socklen_t addrlen);
/**
* @brief: bind socket to server.
*
* @param sockfd: socket file discruptor, (socket() return value);
* @param myaddr: server ip address
* @param addrlen: server ip address length.
*
* @return value : 0:success, -1: fail.
*/
if (bind(serv_socket, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) == -1)
printf("bind error");
listen
int listen(int sockfd, int backlog);
/**
* @brief: 대기 상태;
*
* @param sockfd : socket fd
* @param backlog : 연결 대기열의 크기 지정.
* 연결요청 소켓이 대기하는 연결 대기열을 생성하는 함수.
*
* @return value : 0, -1(fail);
*/
accept
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
/**
* @brief: link socket to client
*
* @param sockfd: server socket fd
* @param addr : client address
* @param addrlen: client address length;
*/
send
recv