Libuvライブラリ(検討)---第8節:その他


インデックスディレクトリ: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
この章には、いくつかの汎用的なツールクラスインタフェースと、1章として単独で列挙するのに適していないものが含まれています.
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)
2回目のstartを連続的に呼び出すと、2回目は1回目を上書きします.
2つの定時間トリガポイントが同じ場合、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.