C++11/C++14 7. Threads with Shared Memory and Mutex - 2017
[IPC:Shared Memory]
int shmget(key_t key, size_t size, int shmflg);
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
void *shmat(int shmid, const void *shmaddr, int shmflg);
int shmdt(const void *shmaddr);
getsockopt, setsockopt
int getsockopt(int sockfd, int level, int optname,
void *optval, socklen_t *optlen);
int setsockopt(int sockfd, int level, int optname,
const void *optval, socklen_t optlen);
TCP option SO_LINGER (zero) - when it’s required
The typical reason to set a
SO_LINGER
timeout of zero is to avoid large numbers of connections sitting in theTIME_WAIT
state, tying up all the available resources on a server.2、若設置了SO_LINGER並確定了非零的超時間隔,則closesocket()調用阻塞進程,直到所剩數據發送完畢或超時。這種關閉稱爲“優雅”或“從容”關閉。請注意如果套接口置爲非阻塞且SO_LINGER設爲非零超時,則closesocket()調用將以WSAEWOULDBLOCK錯誤返回。
epoll_wait()
epoll_wait, epoll_pwait - wait for an I/O event on an epoll file descriptor.
#include <sys/epoll.h>
int epoll_wait(int epfd, struct epoll_event *events,
int maxevents, int timeout);
int epoll_pwait(int epfd, struct epoll_event *events,
int maxevents, int timeout,
const sigset_t *sigmask);
epoll
provides both edge-triggered and level-triggered modes. In edge-triggered mode, a call toepoll_wait
will return only when a new event is enqueued with theepoll
object, while in level-triggered mode,epoll_wait
will return as long as the condition holds.For instance, if a pipe registered with
epoll
has received data, a call toepoll_wait
will return, signaling the presence of data to be read. Suppose the reader only consumed part of data from the buffer. In level-triggered mode, further calls toepoll_wait
will return immediately, as long as the pipe’s buffer contains data to be read. In edge-triggered mode, however,epoll_wait
will return only once new data is written to the pipe.
epoll_ctl
epoll_ctl - control interface for an epoll file descriptor
#include <sys/epoll.h>
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);