日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

apr---接口篇

發布時間:2024/2/28 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 apr---接口篇 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

apr : Apache Portable Runtime

apr 接口詳見:?http://apr.apache.org/docs/apr/2.0/group__apr__thread__proc.html#ga1426acc5bdd96385769e7b42bfa6ebbd

Library initialization and termination :?

1.?apr_status_t??apr_initialize?(void)

//?Setup any APR internal data structures. This MUST be the first function called for any APR library.

初始化APR內部數據結構, apr_initialize()函數必須是第一個被調用的APR庫函數

2.?void??apr_terminate?(void)

//?Tear down any APR internal data structures which aren't torn down automatically.

結束APR庫的使用, 銷毀apr 不能自動回收的數據結構。

Memory Pool Functions

1.?apr_status_t??apr_pool_create?(apr_pool_t?**newpool,?apr_pool_t?*parent)

? ? //創建一個內存池

? ?//Create a new pool.?

? ?//parent:The parent pool. If this is NULL, the new pool is a root pool.?

創建一個內存池,這個內存池將一直存活,直到你調用?apr_pool_destroy()?函數以后被銷毀

2.?void?*?apr_palloc(apr_pool_t*p,?apr_size_t?size);??

? ? //在內存池上分配指定內存大小的內存塊

? ? //Allocate a block of memory from a pool

3. void?apr_pool_destroy(apr_pool_t?*p);??

? ?//銷毀一個內存池

? //Destroy the pool.??

? //Remarks:? ? ?This will actually free the memory

4.?void *??apr_pcalloc?(apr_pool_t?*p, apr_size_t size)

?在內存池上分配指定內存大小的內存塊, 并將所有內存置為0

Thread Pool routines

1.?apr_status_t?apr_thread_pool_create( apr_thread_pool_t?**?me,?apr_size_t??init_threads,??apr_size_t?? max_threads,? apr_pool_t?*?pool? )

創建線程地址池

2.?apr_status_t?apr_thread_pool_destroy(apr_thread_pool_t?*?me)

Destroy the thread pool and stop all the threads

String routines :?

1.?apr_status_t? ?apr_tokenize_to_argv?(const char *arg_str, char ***argv_out,?apr_pool_t?*token_context)

//?Convert the arguments to a program from one string to an array of strings terminated by a NULL pointer

2.?


?

File I/O Handling Functions:

1.?apr_status_t??apr_file_open?(apr_file_t?**newf, const char *fname, apr_int32_t flag,?apr_fileperms_t?perm,?apr_pool_t?*pool)

//?Open the specified file.
2.? ?apr_status_t??apr_file_close?(apr_file_t?*file)

// Close the specified file.
3.??apr_status_t??apr_file_read?(apr_file_t?*thefile, void *buf, apr_size_t *nbytes)
// Read data from the specified file.

4.??apr_status_t??apr_file_write?(apr_file_t?*thefile, const void *buf, apr_size_t *nbytes)

//Write data to the specified file.

5.?apr_status_t??apr_file_write_full?(apr_file_t?*thefile, const void *buf, apr_size_t nbytes, apr_size_t *bytes_written)

// Write data to the specified file, ensuring that all of the data is written before returning.

6.?apr_status_t??apr_file_info_get?(apr_finfo_t?*finfo, apr_int32_t wanted,?apr_file_t?*thefile)

//?get the specified file's stats.

7.?apr_status_t??apr_file_trunc?(apr_file_t?*fp, apr_off_t offset)

//?Truncate the file's length to the specified offset

8.??int??apr_file_printf?(apr_file_t?*fptr, const char *format,...)

//Write a string to a file using a printf format.

9.?apr_status_t??apr_file_rename?(const char *from_path, const char *to_path,?apr_pool_t?*pool)

//?Rename the specified file.



?


5.??apr_status_t? ?apr_file_eof?(apr_file_t?*fptr)
?

//?Are we at the end of the file

6.?

Directory Manipulation Functions :?

1.?apr_status_t??apr_dir_open?(apr_dir_t?**new_dir, const char *dirname,?apr_pool_t?*pool)

//?Open the specified directory.

2.?apr_status_t??apr_dir_close?(apr_dir_t?*thedir)

//?close the specified directory.

3.?apr_status_t??apr_dir_make_recursive?(const char *path,?apr_fileperms_t?perm,?apr_pool_t?*pool)

//?Creates a new directory on the file system, but behaves like 'mkdir -p'. Creates intermediate directories as required. No error will be reported if PATH already exists.

4.?

?


Time Routines :?

1.?apr_time_t? ?apr_time_now?(void)

// the current time

2.?void??apr_sleep?(apr_interval_time_t?t)

// Sleep for the specified number of micro-seconds.

3.?#define??apr_time_from_sec(sec)???((apr_time_t)(sec) * APR_USEC_PER_SEC)

// return? seconds as an apr_time_t

4.?apr_status_t??apr_time_exp_lt?(apr_time_exp_t?*result,?apr_time_t?input)

//?convert a time to its human readable components in local timezone




?

Threads and Process Functions

1. apr_status_t?apr_procattr_create?(apr_procattr_t?**new_attr,?apr_pool_t?*cont)//創建并初始化新進程的屬性, new_attr 是返回的結果, cont是要使用的內存池//Create and initialize a new procattr variable 2. typedef enum {APR_SHELLCMD, /**< use the shell to invoke the program */APR_PROGRAM, /**< invoke the program directly, no copied env */APR_PROGRAM_ENV, /**< invoke the program, replicating our environment */APR_PROGRAM_PATH, /**< find program on PATH, use our environment */APR_SHELLCMD_ENV /**< use the shell to invoke the program,* replicating our environment*/ } apr_cmdtype_e;


apr_status_t? apr_procattr_cmdtype_set(apr_procattr_t*attr, apr_cmdtype_e? cmd);?

? //?Set what type of command the child process will call.

3.?apr_status_t?apr_procattr_error_check_set(apr_procattr_t?*?attr, apr_int32_t?chk?)

? ?//Specify that?apr_proc_create()?should do whatever it can to report failures to the caller of?apr_proc_create(), rather than find out in the child.

4.?apr_status_t?apr_procattr_user_set( apr_procattr_t?*?attr,? const char *? username, const char *? password?)

//?Set the username used for running process

5.?apr_status_t??apr_procattr_group_set?(apr_procattr_t?*attr, const char *groupname)

//Set the group used for running process

6.?apr_status_t??apr_procattr_dir_set?(apr_procattr_t?*attr, const char *dir)

//Set which directory the child process should start executing in.

7.?apr_status_t??apr_proc_create?(apr_proc_t?*new_proc, const char *progname, const char *const *args, const char *const *env,?apr_procattr_t?*attr,?apr_pool_t?*pool)

//Create a new process and execute a new program within that process.

8.?apr_status_t??apr_proc_detach?(int daemonize)

//Detach the process from the controlling terminal.

9.?apr_status_t??apr_proc_kill?(apr_proc_t?*proc, int sig)

//Terminate a process.

10.?apr_status_t??apr_proc_wait?(apr_proc_t?*proc, int *exitcode,?apr_exit_why_e?*exitwhy,?apr_wait_how_e?waithow)

//Wait for a child process to die

1.?apr_status_t??apr_threadattr_create?(apr_threadattr_t?**new_attr,?apr_pool_t?*cont)

//?Create and initialize a new threadattr variable

2.?apr_status_t??apr_threadattr_stacksize_set?(apr_threadattr_t?*attr, apr_size_t stacksize)

//?Set the stack size of newly created threads.

3.?apr_status_t??apr_thread_detach?(apr_thread_t?*thd)

//?detach a thread

4.?apr_status_t??apr_thread_join?(apr_status_t?*retval,?apr_thread_t?*thd)

//?block until the desired thread stops executing.

5.?




?

pipe 接口:

詳見:http://dev.ariel-networks.com/apr/apr-tutorial/html/apr-tutorial-15.html

1.?APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t in, apr_int32_t out, apr_int32_t err);

? ? //設置進程屬性的 標準intput/output/error 屬性

Functions for manipulating the environment :

1.?apr_status_t? apr_env_get?(char **value, const char *envvar,?apr_pool_t?*pool)

//Get the value of an environment variable

2.?

Network Routines :

1. apr_status_t? apr_socket_create?(apr_socket_t?**new_sock, int family, int type, int protocol,?apr_pool_t?*cont)

//??Create a socket.

2.?apr_status_t? apr_socket_connect?(apr_socket_t?*sock,?apr_sockaddr_t?*sa)

Issue a connection request to a socket either on the same machine or a different one.

3.?apr_status_t? apr_socket_bind?(apr_socket_t?*sock,?apr_sockaddr_t?*sa)

//?Bind the socket to its associated port

4.?apr_status_t? apr_socket_listen?(apr_socket_t?*sock, apr_int32_t backlog)

// Listen to a bound socket for connections.

5.?apr_status_t? apr_socket_accept?(apr_socket_t?**new_sock,?apr_socket_t?*sock,?apr_pool_t?*connection_pool)

//?Accept a new connection request

6.?apr_status_t? apr_socket_send?(apr_socket_t?*sock, const char *buf, apr_size_t *len)

//Send data over a network.

7.?apr_status_t? apr_socket_recv?(apr_socket_t?*sock, char *buf, apr_size_t *len)

//?Read data from a network.

8.?apr_status_t??apr_socket_opt_set?(apr_socket_t?*sock, apr_int32_t opt, apr_int32_t on)

//Setup socket options for the specified socket

9.?apr_status_t? ?apr_socket_timeout_set?(apr_socket_t?*sock,?apr_interval_time_t?t)

//?Setup socket timeout for the specified socket

10.?apr_status_t? ?apr_sockaddr_info_get?(apr_sockaddr_t?**sa, const char *hostname, apr_int32_t family,?apr_port_t?port, apr_int32_t flags,?apr_pool_t?*p)

//?Create?apr_sockaddr_t?from hostname, address family, and port.

11.?apr_status_t??apr_socket_addr_get?(apr_sockaddr_t?**sa,?apr_interface_e?which,?apr_socket_t?*sock)

//Return an address associated with a socket; either the address to which the socket is bound locally or the the address of the peer to which the socket is connected.

12.?apr_status_t? ?apr_sockaddr_ip_get?(char **addr,?apr_sockaddr_t?*sockaddr)

//?Return the IP address (in numeric address string format) in an APR socket address. APR will allocate storage for the IP address string from the pool of the?apr_sockaddr_t.

13.?apr_status_t? apr_socket_close?(apr_socket_t?*thesocket)

//?Close a socket.

14.?apr_status_t??apr_socket_shutdown?(apr_socket_t?*thesocket,?apr_shutdown_how_e?how)

//?Shutdown either reading, writing, or both sides of a socket.


?

Command Argument Parsing :?

1.?apr_status_t??apr_getopt_init?(apr_getopt_t?**os,?apr_pool_t?*cont, int argc, const char *const *argv)

// Initialize the arguments for parsing by?apr_getopt().

Parameters:

osThe options structure created for?apr_getopt()
contThe pool to operate on
argcThe number of arguments to parse
argvThe array of arguments to parse

2.?apr_status_t??apr_getopt?(apr_getopt_t?*os, const char *opts, char *option_ch, const char **option_arg)

//?Parse the options initialized by?apr_getopt_init().

3.?apr_status_t?apr_getopt_long?(apr_getopt_t?*os, const?apr_getopt_option_t?*opts, int *option_ch, const char **option_arg)

處理長參數, 以--開頭, 短參數以- 開頭的參數選項

Error Codes?:?

1.?char *??apr_strerror?(apr_status_t?statcode, char *buf, apr_size_t bufsize)

//?Return a human readable string describing the specified error.

2.?

User and Group ID Services :?

1.?apr_status_t??apr_uid_get?(apr_uid_t?*userid,?apr_gid_t?*groupid, const char *username,?apr_pool_t?*p)

//?Get the userid (and groupid) for the specified username

2.?

Atomic Operations

1.?apr_status_t??apr_atomic_init?(apr_pool_t?*p)

初始化原子操作

2.?

Hash Tables

1.?typedef struct?apr_hash_t?apr_hash_t

apr hash table 的類型定義

2.?apr_hash_t?*?apr_hash_make?(apr_pool_t?*pool)

?創建一個hash table, 參數pool 是 給這個hash table 內配內存的地址池

對于apr_hash_make而言,它的主要的工作就是創建apr_hash_t結構,并對其中的成員進行初始化,其中哈希元素的個數被初始化為16個,同時使用默認的哈希算法apr_hashfunc_default,而apr_hash_make_custom則使用自定義的哈希函數hash_func。

3.?apr_hash_index_t?*??apr_hash_first?(apr_pool_t?*p,?apr_hash_t?*ht)

開始迭代哈希表中的條目。

4.?apr_hash_index_t?*?apr_hash_next?(apr_hash_index_t?*hi)

Continue iterating over the entries in a hash table.

5.?void *?apr_hash_this_val?(apr_hash_index_t?*hi)

Get the current entry's value from the iteration state.

6.?void?apr_hash_set?(apr_hash_t?*ht, const void *key, apr_ssize_t klen, const void *val)

設置hash table 中key 對應的value,?

如果val = null , 則刪除該hash , 但是hash key 會一直存在,直到這個hash table 的地址池被回收

7.?void *?apr_hash_get?(apr_hash_t?*ht, const void *key, apr_ssize_t klen)

在哈希表中查找與鍵關聯的值


?

Signal Handling

1.?apr_sigfunc_t?*??apr_signal?(int signo,?apr_sigfunc_t?*func)

Set the signal handler function for a given signal

2.?

String routines

1.? char*?apr_pstrdup?(apr_pool_t?*p, const char *s)

將字符串復制到從池中分配的內存中

2.?

總結

以上是生活随笔為你收集整理的apr---接口篇的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。