lcrzo_process(3)

NAME
lcrzo_process - lcrzo library : process

CONTENTS
/*    Laurent Constantin's network library (lcrzo)
                 lcrzo_process module
  Process(unix) and thread(Windows) functions.
*/
/*-------------------------------------------------------------*/
/***************************************************************
 * Note about processes and threads :                          *
 *  - Under Unix, a process is created (fork).                 *
 *  - Under Windows, it's not possible to use a process, so a  *
 *    thread is created. In this case, we have to take care    *
 *    about global variables and static variables.             *
 ***************************************************************/
/*-------------------------------------------------------------*/
/* definition of a lcrzo_process. You should not use its
   fields directly. */
typedef struct
{ lcrzo_uint32 processid;
  lcrzo_uint32 threadid;
  void *threadhandle;
  lcrzo_data pfuncinfos;
  lcrzo_bool hasended;
  int returnedvalue;
  int (*punixreturn_uint82int)(lcrzo_uint8 ret);
} lcrzo_process;
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_current_init
   Description :
     Initialize a lcrzo_process to contain the current process.
   Input parameter(s) :
   Input/output parameter(s) :
   Output parameter(s) :
     *pprocess : lcrzo_process containing the current process
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_current_init(lcrzo_process *pprocess);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_current_exit
   Description :
     Leave the current process.
     Warning : under Unix, returnvalue is truncated to 8 bits.
               Functions lcrzo_process_other_init2 and
	       lcrzo_process_int2uint8_std might be
               of interest if this a problem for your code.
   Input parameter(s) :
     returnvalue : value returned by the process
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_current_exit(int returnvalue);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_current_priority_set
   Description :
     Change the priority level of the current process.
   Input parameter(s) :
     priority : priority to set :
                    -127 = low priority
                      0  = normal priority
                    +127 = high priority (need to be admin)
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_current_priority_set(lcrzo_int8 priority);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_current_priority_get
   Description :
     Obtain the priority level of the current process.
   Input parameter(s) :
   Input/output parameter(s) :
   Output parameter(s) :
     *ppriority : priority
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_current_priority_get(lcrzo_int8 *ppriority);
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_other_init
   Description :
     Create a new process, which will execute *pfunc and exit.
     Under Unix, value returned by pfunc is truncated to 8
     bits : use lcrzo_process_other_init2 instead.
   Input parameter(s) :
     *pfunc : function executed by the new process :
                infos : set with infos
		infossize : set with infosize
		*pparentprocess : inform who is the father process
     infos : data to pass to the child process (infos is a void*
             because of Wcast-align on Sparc, which cause a sigbus)
     infossize : size of infos
     *pchidprocess : process created
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_other_init(int (*pfunc)(void *infos,
					  lcrzo_int32 infossize,
					  lcrzo_process *pparentprocess),
			     void *infos,
                             lcrzo_int32 infossize,
			     lcrzo_process *pchildprocess);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_other_init2
   Description :
     Create a new process, which will execute *pfunc and exit.
     Under Unix, value returned by pfunc is truncated to 8
     bits. So, functions punixreturn_int2uint8 and
     punixreturn_uint82int can be used to compress integer and
     then expand them. You can for example use
     lcrzo_process_int2uint8_std or create your own conversion
     function.
   Input parameter(s) :
     *pfunc : function executed by the new process :
                infos : set with infos
		infossize : set with infosize
		*pparentprocess : inform who is the father process
     infos : data which can be passed to the child process
     infossize : size of infos
     *punixreturn_int2uint8 : function used to convert the returned
                              value to 8 bits
     *punixreturn_uint82int : function used to convert an 8bitvalue
                              to an integer
     *pchidprocess : process created
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_other_init2(int (*pfunc)(void *infos,
					   lcrzo_int32 infossize,
					   lcrzo_process *pparentprocess),
			      void *infos,
			      lcrzo_int32 infossize,
			      lcrzo_uint8 (*punixreturn_int2uint8)(int ret),
			      int (*punixreturn_uint82int)(lcrzo_uint8 ret),
			      lcrzo_process *pchildprocess);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_other_exit
   Description :
     Terminate abruptly a process : use it only if you do not
     need to close things before ending.
   Input parameter(s) :
     *pprocess : process to terminate
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_other_exit(lcrzo_process *pprocess);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_other_wait_end
   Description :
     Wait for the end of the process.
   Input parameter(s) :
     *pprocess : process to wait for
     *pmaxwaitingtime : maximum waiting time (can be a lcrzo_time,
                        LCRZO_WAIT_NODELAY or LCRZO_WAIT_INFINITE)
   Input/output parameter(s) :
   Output parameter(s) :
     *phasended : true if the process has ended
     *preturnvalue : value returned by the process
   Normal return values :
     LCRZO_ERR_OK : ok
     LCRZO_ERR_OKTEMPDATAEND : the function received nothing
                               before pmaxwaitingtime
*/
int lcrzo_process_other_wait_end(lcrzo_process *pprocess,
                                 lcrzo_time *pmaxwaitingtime,
                                 lcrzo_bool *phasended,
                                 int *preturnvalue);
/*-------------------------------------------------------------*/
/* Name : lcrzo_process_close
   Description :
     Free memory allocated by a lcrzo_process.
     Note : this function does not teminate the processus.
   Input parameter(s) :
     *pprocess : process to free
   Input/output parameter(s) :
   Output parameter(s) :
   Normal return values :
     LCRZO_ERR_OK : ok
*/
int lcrzo_process_close(lcrzo_process *pprocess);
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/*
  Those functions have the same usage as previous ones, except :
   - they deal with several sub-processes
   - each sub-process is referred by its index
*/
typedef struct
{ lcrzo_list waitlist;
  lcrzo_list processlist;
} lcrzo_multiprocess;
int lcrzo_multiprocess_init(lcrzo_multiprocess *pmultiprocess);
int lcrzo_multiprocess_close(lcrzo_multiprocess *pmultiprocess);
int lcrzo_multiprocess_process_init(lcrzo_multiprocess *pmultiprocess,
                                    lcrzo_int32 processindex,
                                    int (*pfunc)(void *infos,
						 lcrzo_int32 infossize,
						lcrzo_process *pparentprocess),
			            void *infos,
                                    lcrzo_int32 infossize);
int lcrzo_multiprocess_process_init2(lcrzo_multiprocess *pmultiprocess,
				     lcrzo_int32 processindex,
				     int (*pfunc)(void *infos,
						  lcrzo_int32 infossize,
						lcrzo_process *pparentprocess),
				     void *infos,
				     lcrzo_int32 infossize,
			      lcrzo_uint8 (*punixreturn_int2uint8)(int ret),
			      int (*punixreturn_uint82int)(lcrzo_uint8 ret));
int lcrzo_multiprocess_process_count(lcrzo_multiprocess *pmultiprocess,
                                     lcrzo_int32 *pnumberofprocesses);
int lcrzo_multiprocess_process_exit(lcrzo_multiprocess *pmultiprocess,
                                    lcrzo_int32 processindex);
int lcrzo_multiprocess_process_wait_end(lcrzo_multiprocess *pmultiprocess,
                                        lcrzo_time *pmaxwaitingtime,
                                        lcrzo_bool *paprocesshasended,
                                        lcrzo_int32 *pindexoftheendedprocess,
                                        int *preturnedvalue);
/*-------------------------------------------------------------*/
/* Under Unix, the value returned by a process is truncated
   to 8 bits. Theses functions are used by lcrzo_process_other_init2.
     lcrzo_process_int2uint8_std : convert from 32 bits to 8 bits
     lcrzo_process_uint82int_std : convert from 8 bits to 32 bits
*/
lcrzo_uint8 lcrzo_process_int2uint8_std(int ret);
int lcrzo_process_uint82int_std(lcrzo_uint8 ret);
/*-------------------------------------------------------------*/
/* Idem, but deals differently with truncation */
lcrzo_uint8 lcrzo_process_int2uint8_socktcp(int ret);
int lcrzo_process_uint82int_socktcp(lcrzo_uint8 ret);

SEE ALSO
lcrzo(3), lcrzo_types(3), lcrzo_data(3), lcrzo_string(3), lcrzo_time(3), lcrzo_file(3), lcrzo_address(3), lcrzo_device(3), lcrzo_list(3), lcrzo_process(3), lcrzo_ipc(3), lcrzo_header(3), lcrzo_ipopt(3), lcrzo_tcpopt(3), lcrzo_packet(3), lcrzo_icmp(3), lcrzo_print(3), lcrzo_record(3), lcrzo_conf(3), lcrzo_spoof(3), lcrzo_sniff(3), lcrzo_sock(3), lcrzo_wait(3), lcrzo_global(3), lcrzo_error(3) lcrzo_misc(3), lcrzo_obso(3),