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.

2. void  apr_terminate (void)

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

 


 

 


 

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. 

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

 

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:

os The options structure created for apr_getopt()
cont The pool to operate on
argc The number of arguments to parse
argv The 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().

 

 

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.