索引目录:https://blog.csdn.net/knowledgebao/article/details/84776754
http://docs.libuv.org/en/v1.x/timer.html
http://docs.libuv.org/en/v1.x/errors.html
http://docs.libuv.org/en/v1.x/misc.html
这一章包含一些通用的工具类接口以及一些不适合单独列出来作为一章的东东。
DNS:
int uv_getaddrinfo(uv_loop_t* loop,
uv_getaddrinfo_t* req,
uv_getaddrinfo_cb getaddrinfo_cb,
const char* node,
const char* service,
const struct addrinfo* hints);
void uv_freeaddrinfo(struct addrinfo* ai);
typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
int status,
struct addrinfo* res);
int uv_getnameinfo(uv_loop_t* loop,
uv_getnameinfo_t* req,
uv_getnameinfo_cb getnameinfo_cb,
const struct sockaddr* addr,
int flags);
typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req,
int status,
const char* hostname,
const char* service);
https://linux.die.net/man/3/getaddrinfo
uv_getaddrinfo_t:地址结构体,具体详见头文件
uv_getaddrinfo:获取地址
Either node or service may be NULL but not both.
Returns 0 on success or an error code < 0 on failure. If successful, the callback will get called sometime in the future with the lookup result, which is either:
status == 0, the res argument points to a valid struct addrinfo, or
status < 0, the res argument is NULL. See the UV_EAI_* constants.
Call uv_freeaddrinfo() to free the addrinfo structure.
Changed in version 1.3.0: the callback parameter is now allowed to be NULL, in which case the request will run synchronously.
uv_freeaddrinfo:释放地址
uv_getaddrinfo_cb: 回调,Callback which will be called with the getaddrinfo request result once complete. In case it was cancelled, status will have a value of UV_ECANCELED.
http://docs.libuv.org/en/v1.x/dns.html
https://baike.baidu.com/item/getaddrinfo/9021771
uv_getnameinfo:获取名称
定时器:
int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
int uv_timer_start(uv_timer_t* handle,
uv_timer_cb cb,
uint64_t timeout,
uint64_t repeat);
int uv_timer_stop(uv_timer_t* handle);
int uv_timer_again(uv_timer_t* handle);
void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat);
uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
uv_timer_init
Initialize the handle.
初始化定时器,最后需要调用uv_close((uv_handle_t*)&timer_handle, NULL);释放只句柄;
uv_timer_start
开始计时器,timeout:首次触发时间,repeat:重复间隔时长(milliseconds)
如果连续调用二次start,第二次覆盖第一次。
如果两个定时间触发时间点相同,按照start执行的先后顺序触发。
cb不可以为空,否则失败
uv_timer_stop:停止计时器,可以使用uv_close(uv_handle_t*, NULL)代替。
uv_timer_again:
Stop the timer, and if it is repeating restart it using the repeat value as the timeout.
If the timer has never been started before it returns UV_EINVAL.
重新开始,受限停止timer,如果当前timer的repeat不为0,timeout使用repeat代替,如果timer还没有uv_run,则执行失败,返回UV_EINVAL
uv_timer_set_repeat:
Set the repeat interval value in milliseconds. The timer will be scheduled to run on the given interval, regardless of the callback execution duration, and will follow normal timer semantics in the case of a time-slice overrun.
For example, if a 50ms repeating timer first runs for 17ms, it will be scheduled to run again 33ms later. If other tasks consume more than the 33ms following the first timer callback, then the callback will run as soon as possible.
Note:
If the repeat value is set from a timer callback it does not immediately take effect. If the timer was non-repeating before, it will have been stopped. If it was repeating, then the old repeat value will have been used to schedule the next timeout.
设置重复, 单位:milliseconds
uv_timer_get_repeat:
Get the timer repeat value.
获取重复
uv_timer_cb:
回调函数,定时时间到,触发
系统错误:
int uv_translate_sys_error(int sys_errno);
const char* uv_strerror(int err);
char* uv_strerror_r(int err, char* buf, size_t buflen);
const char* uv_err_name(int err);
char* uv_err_name_r(int err, char* buf, size_t buflen);
uv_translate_sys_error:转换为系统错误码
uv_strerror:返回错误描述信息,比如:operation canceled
uv_strerror_r:修改错误描述信息
uv_err_name:返回错误编码,比如:ECANCELED
uv_err_name_r:修改错误名称
程序相关
char** uv_setup_args(int argc, char** argv);
int uv_get_process_title(char* buffer, size_t size);
int uv_set_process_title(const char* title);
int uv_resident_set_memory(size_t* rss);
int uv_uptime(double* uptime);
uv_os_fd_t uv_get_osfhandle(int fd);
uv_setup_args:Store the program arguments. Required for uv_get_process_title/uv_set_process_title.
uv_get_process_title:Gets the title of the current process. You must call uv_setup_args before calling this function.
uv_set_process_title:Sets the current process title. You must call uv_setup_args before calling this function.
uv_resident_set_memory:Gets the resident set size (RSS) for the current process.
uv_uptime:Gets the current system uptime.获取系统运行时间
uv_get_osfhandle:For a file descriptor in the C runtime, get the OS-dependent handle. On UNIX, returns the fd intact. On Windows, this calls _get_osfhandle. Note that the return value is still owned by the C runtime, any attempts to close it or to use it after closing the fd may lead to malfunction.获取系统剩余可用句柄
VSS- Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS- Resident Set Size 实际使用物理内存(包含共享库占用的内存)
PSS- Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
USS- Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
内存相关:
int uv_replace_allocator(uv_malloc_func malloc_func,
uv_realloc_func realloc_func,
uv_calloc_func calloc_func,
uv_free_func free_func);
uv_replace_allocator:
Override the use of the standard library’s malloc(3), calloc(3), realloc(3), free(3), memory allocation functions.
This function must be called before any other libuv function is called or after all resources have been freed and thus libuv doesn’t reference any allocated memory chunk.
On success, it returns 0, if any of the function pointers is NULL it returns UV_EINVAL.
重载系统的malloc, calloc, realloc, free函数
共享库相关
UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
UV_EXTERN void uv_dlclose(uv_lib_t* lib);
UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
http://docs.libuv.org/en/v1.x/dll.html
int uv_dlopen
(const char* filename, uv_lib_t* lib)
Opens a shared library. The filename is in utf-8. Returns 0 on success and -1 on error. Call uv_dlerror()
to get the error message.
void uv_dlclose
(uv_lib_t* lib)
Close the shared library.
int uv_dlsym
(uv_lib_t* lib, const char* name, void** ptr)
Retrieves a data pointer from a dynamic library. It is legal for a symbol to map to NULL. Returns 0 on success and -1 if the symbol was not found.
const char* uv_dlerror
(const uv_lib_t* lib)
Returns the last uv_dlopen() or uv_dlsym() error message.
其它
UV_EXTERN int uv_exepath(char* buffer, size_t* size);
UV_EXTERN int uv_cwd(char* buffer, size_t* size);
UV_EXTERN int uv_chdir(const char* dir);
UV_EXTERN uint64_t uv_get_free_memory(void);
UV_EXTERN uint64_t uv_get_total_memory(void);
UV_EXTERN uint64_t uv_hrtime(void);
int uv_exepath
(char* buffer, size_t* size)
Gets the executable path.
int uv_cwd
(char* buffer, size_t* size)
Gets the current working directory, and stores it in buffer. If the current working directory is too large to fit in buffer, this function returns UV_ENOBUFS, and sets size to the required length, including the null terminator.
Changed in version 1.1.0: On Unix the path no longer ends in a slash.
Changed in version 1.9.0: the returned length includes the terminating null byte on UV_ENOBUFS, and the buffer is null terminated on success.
int uv_chdir
(const char* dir)
Changes the current working directory.
uint64_t uv_get_total_memory
(void)
Gets memory information (in bytes).
uint64_t uv_hrtime
(void)
Returns the current high-resolution real time. This is expressed in nanoseconds. It is relative to an arbitrary time in the past. It is not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals.
Note:Not every platform can support nanosecond resolution; however, this value will always be in nanoseconds.
int uv_cpu_info
(uv_cpu_info_t** cpu_infos, int* count)
Gets information about the CPUs on the system. The cpu_infos array will have count elements and needs to be freed with uv_free_cpu_info()
.
void uv_free_cpu_info
(uv_cpu_info_t* cpu_infos, int count)
Frees the cpu_infos array previously allocated with uv_cpu_info()
.
详细参考http://docs.libuv.org/en/v1.x/misc.html
提供了CPU、内存、系统时间、IP格式转换、程序名称、进程IP、interface_address、执行路径、打印loop、优先级等通用API。