Skip to content

Instantly share code, notes, and snippets.

@JeOam
Last active December 28, 2015 05:20
Show Gist options
  • Save JeOam/2c7e4db4e29187f8e656 to your computer and use it in GitHub Desktop.
Save JeOam/2c7e4db4e29187f8e656 to your computer and use it in GitHub Desktop.
C Common Fuction

The GNU C Library


The table below shows the section numbers of the manual followed by the types of pages they contain.

1   Executable programs or shell commands
2   System calls (functions provided by the kernel)
3   Library calls (functions within program libraries)
4   Special files (usually found in /dev)
5   File formats and conventions eg /etc/passwd
6   Games
7   Miscellaneous  (including  macro  packages  and  conventions), e.g.
    man(7), groff(7)
8   System administration commands (usually only for root)
9   Kernel routines [Non standard]
@JeOam
Copy link
Author

JeOam commented Dec 27, 2015

#include <stdio.h>
void perror(const char *s);
perror(str);

is equivalent to

if (str)
    fprintf(stderr, "%s: %s\n", str, strerror(errno));
else
    fprintf(stderr, "%s\n", strerror(errno));

@JeOam
Copy link
Author

JeOam commented Dec 27, 2015

include <bits/socket.h>
// Maximum queue length specifiable by listen.
SOMAXCONN

Find the SOMAXCONN definition:

find /usr/include -name \*.h -exec grep SOMAXCONN {} /dev/null \;

@JeOam
Copy link
Author

JeOam commented Dec 28, 2015

#include <sys/epoll.h> 
/*
 * 函数功能:操作某个epoll文件描述符;
 *
 * 参数:
 * epfd:由epoll_create创建的epoll文件描述符;
 * op:是操作方式,有以下三种操作方式:
 *      EPOLL_CTL_ADD   将fd注册到epfd中;
 *      EPOLL_CTL_MOD   修改已在epfd中注册的fd事件;
 *      EPOLL_CTL_DEL   将fd从epfd中删除;
 * fd:是关联的文件描述符;
 * event:指向struct epoll_event 结构,表示需要监听fd的某种事件;
 *
 * 返回值:若成功则返回0,否则出错返回-1;
 */
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event);
/*

 */
/* struct epoll_event 结构体定义如下 */
typedef union epoll_data {
void        *ptr;
int          fd;
uint32_t     u32;
uint64_t     u64;
} epoll_data_t;

struct epoll_event {
uint32_t     events;      /* Epoll events */
epoll_data_t data;        /* User data variable */
};
/*
 * 其中events有如下的取值:
 *  EPOLLIN         表示对应的文件描述符可读;
 *  EPOLLOUT        表示对应的文件描述符可写;
 *  EPOLLPRI        表示对应的文件描述符有紧急数据可读;
 *  EPOLLERR        表示对应的文件描述符发生错误;
 *  EPOLLHUP        表示对应的文件描述符被挂载;
 *  EPOLLET         表示将EPOLL设置为边缘触发模式(Edge Triggered);
 *  EPOLLONESHOT    表示只监听一次事件,当监听此次事件完成,若想继续监听,则需再次把该套接字描述符加入到EPOLL队列中;
 */
/*
 * 函数功能:收集在epoll监听事件中已发生的事件;
 *
 * 参数:
 * epfd:由epoll_create创建的epoll文件描述符;
 * events:指向epoll_event结构体,用于保存已发生的事件;
 * maxevents:每次能处理的最大事件数;
 * timeout:等待IO 事件发生的超时时间:-1相当于阻塞,即不会立即返回;0相当于非阻塞,即立即返回;
 *
 * 返回值:若成功则返回所发生的事件数,否则出错返回-1;
 */
int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout);

via epoll 解析

@JeOam
Copy link
Author

JeOam commented Dec 28, 2015

#include <netdb.h>
NI_MAXHOST
NI_MAXSERV

via getnameinfo(3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment