책에 나와있는 socket 관련 C api 들이다. 생략하려고 했지만 간략히 정리했다.
뒷 챕터에 나오는 The ACE Socket Wrapper Facades 를 위한 챕터이니 별 내용없다.
Contents
socket
C 함수를 이용해서 통신의 endpoint 인 socket 을 만들수 있다. 이 socket 은 handle 을 통해 제어 되는데, 이 handle 은 unix 와 윈도가 다르다.
- 유닉스
- socket 의 handle 은 file, pipe 등 다른 I/O handle 과 완전히 호환된다.
- 윈도
- socket handle 을 다른 I/O handle 처럼 쓸수 없다.
The Socket API
Local context management
Socket() |
A factory function that allocates a socket handle and returns it to the caller. |
bind() |
Associates a socket handle with a local or remote address. |
getsockname() |
Returns the local address to which a socket is bound. |
getpeername() |
Returns the remote address to which a socket is bound. |
close() |
Deallocates a socket handle, making it available for reuse. |
Connection establishment and connection termination
connect() |
Establishes a connection actively on a socket handle. |
listen() |
Indicates its willingness to listen passively for incoming client connection requests. |
Accept() |
A factory function that creates a new communication endpoint to service client requests |
shutdown() |
Selectively terminates the read-side and/or write-side stream of a bidirectional connection |
Data transfer mechanisms
send(),recv() |
Transmit and receive buffers of data via a particular I/O handle. |
sendto(), recvfrom() |
Exchanges connectionless datagrams, where each sendto() call provides the networking address of the recipient. |
유닉스에선 다음도 가능...
read()write() |
Receive and transmit buffers of data via a particular handle. |
readv()writev() |
Supports scatter-read and gather-write semantics, respectively, to optimize mode switching and simplify memory management. |
sendmsg()recvmsg() |
General-purpose functions that subsume the behavior of the other data transfer functions. |
Options management
setsockopt() |
Modifies options in different protocol stack layers |
setsockopt() |
Queries options in different protocol stack layers |
Network addressing
gethostbyname() |
Handle network address mapping between hostnames and IPv4 addresses. |
getipnodebyname() |
Handle network address mapping between hostnames and IPv4/IPv6 addresses. |
get servbyname() |
Identifies services by their humanly readable names |
protocol family
for example, UNIX-domain (PF_UNIX), Internet-domain IPv4 (PF_INET) and IPv6 (PF_INET6), ATM (PF_ATMSVC), X.25 (PF_x25), Appletalk (PF_APPLETALK), and so on
address family
An address family defines an address format that characterizes the size of an address in bytes, as well as the number, type, and order of its fields. In addition, an address family defines a set of functions that interpret the address format, for example, to determine the subnet where an IP datagram is destined. Address families correspond closely to protocol families, for example, the IPv4 address family AF_INET works only with the IPv4 protocol family PF_INET.
limitations if socket api
native socket api 의 단점은, 에러처리가 약하고, 복잡하고, 이식성이 떨어진다는것.
