added the errnum field to qse_pio_t
This commit is contained in:
		| @ -13,7 +13,7 @@ | ||||
|    distributed under the License is distributed on an "AS IS" BASIS, | ||||
|    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|    See the License for the specific language governing permissions and | ||||
|    limitations under the License. | ||||
|    limitapions under the License. | ||||
|  */ | ||||
|  | ||||
| #ifndef _QSE_CMN_PIO_H_ | ||||
| @ -40,12 +40,15 @@ enum qse_pio_open_flag_t | ||||
| 	QSE_PIO_DROPERR    = (1 << 10), | ||||
|  | ||||
| 	/* invoke the command through a default system shell */ | ||||
| 	QSE_PIO_SHELL      = (1 << 11) | ||||
| 	QSE_PIO_SHELL      = (1 << 11), | ||||
|  | ||||
| 	/* enable ase_char_t based IO */ | ||||
| 	QSE_PIO_TEXT       = (1 << 12) | ||||
| }; | ||||
|  | ||||
| enum qse_pio_wait_flag_t | ||||
| { | ||||
| 	QSE_PIO_NOWAIT     = (1 << 0), | ||||
| 	QSE_PIO_NOHANG     = (1 << 0), | ||||
| 	QSE_PIO_IGNINTR    = (1 << 1) | ||||
| }; | ||||
|  | ||||
| @ -56,7 +59,15 @@ enum qse_pio_hid_t | ||||
| 	QSE_PIO_ERR = 2 | ||||
| }; | ||||
|  | ||||
| enum qse_pio_err_t | ||||
| { | ||||
| 	QSE_PIO_ENOERR = 0, | ||||
| 	QSE_PIO_ENOMEM,     /* out of memory */ | ||||
| 	QSE_PIO_ECHILD      /* the child is not valid */ | ||||
| }; | ||||
|  | ||||
| typedef enum qse_pio_hid_t qse_pio_hid_t; | ||||
| typedef enum qse_pio_err_t qse_pio_err_t; | ||||
|  | ||||
| #ifdef _WIN32 | ||||
| 	/* <winnt.h> => typedef PVOID HANDLE; */ | ||||
| @ -78,9 +89,11 @@ struct qse_pio_t | ||||
| 	qse_mmgr_t*   mmgr; | ||||
| 	qse_pio_pid_t child; | ||||
| 	qse_pio_hnd_t handle[3]; | ||||
| 	qse_pio_err_t errnum; | ||||
| }; | ||||
|  | ||||
| #define QSE_PIO_MMGR(pio)       ((pio)->mmgr) | ||||
| #define QSE_PIO_XTN(pio)        ((void*)(((qse_pio_t*)pio) + 1)) | ||||
| #define QSE_PIO_HANDLE(pio,hid) ((pio)->handle[hid]) | ||||
| #define QSE_PIO_CHILD(pio)      ((pio)->child) | ||||
|  | ||||
| @ -93,7 +106,7 @@ extern "C" { | ||||
|  *  qse_pio_open - open pipes to a child process | ||||
|  * | ||||
|  * DESCRIPTION | ||||
|  *  QSE_PIO_SHELL drives the function to execute the command via /bin/sh. | ||||
|  *  QSE_PIO_SHELL drives the funcpion to execute the command via /bin/sh. | ||||
|  *  If flags is clear of QSE_PIO_SHELL, you should pass the full program path. | ||||
|  * | ||||
|  * SYNOPSIS | ||||
| @ -142,6 +155,49 @@ void qse_pio_fini ( | ||||
| ); | ||||
| /******/ | ||||
|  | ||||
|  | ||||
| void* qse_pio_getxtn ( | ||||
| 	qse_pio_t* pio | ||||
| ); | ||||
|  | ||||
| qse_mmgr_t* qse_pio_getmmgr ( | ||||
| 	qse_pio_t* pio | ||||
| ); | ||||
|  | ||||
| void qse_pio_setmmgr ( | ||||
| 	qse_pio_t* pio, | ||||
| 	qse_mmgr_t* mmgr | ||||
| ); | ||||
|  | ||||
| /* TODO: | ||||
| QSE_OBJECT_DEFINE_BASIC_MACROS(pio) | ||||
| QSE_OBJEcT_DEFINE_BASIC_FIELDS(pio) | ||||
| QSE_OBJECT_DEFINE_BASIC_FUNCTION(pio) | ||||
| QSE_OBJECT_IMPLEMENT_BASIC_FUNCTION(pio) | ||||
| */ | ||||
|  | ||||
| /****f* qse.cmn.pio/qse_pio_geterrnum | ||||
|  * NAME | ||||
|  *  qse_pio_geterrnum - get an error code | ||||
|  * | ||||
|  * SYNOPSIS | ||||
|  */ | ||||
| qse_pio_err_t qse_pio_geterrnum (qse_pio_t* pio); | ||||
| /******/ | ||||
|  | ||||
| /****f* qse.cmn.pio/qse_pio_geterrstr | ||||
|  * NAME | ||||
|  *  qse_pio_geterrstr - transllate an error code to a string | ||||
|  * | ||||
|  * DESCRIPTION | ||||
|  *  The qse_pio_geterrstr() funcpion returns the pointer to a constant string  | ||||
|  *  describing the last error occurred. | ||||
|  * | ||||
|  * SYNOPSIS | ||||
|  */ | ||||
| const qse_char_t* qse_pio_geterrstr (qse_pio_t* pio); | ||||
| /******/ | ||||
|  | ||||
| /****f* qse.cmn.pio/qse_pio_gethandle | ||||
|  * NAME | ||||
|  *  qse_pio_gethandle - get native handle | ||||
|  | ||||
| @ -23,7 +23,7 @@ | ||||
| #include <qse/macros.h> | ||||
| #include <qse/cmn/str.h> | ||||
|  | ||||
| enum | ||||
| enum qse_tio_err_t | ||||
| { | ||||
| 	QSE_TIO_ENOERR = 0, | ||||
| 	QSE_TIO_ENOMEM, /* out of memory */ | ||||
| @ -41,6 +41,8 @@ enum | ||||
| 	QSE_TIO_EOUTCL  /* output function failed to close */ | ||||
| }; | ||||
|  | ||||
| typedef enum qse_tio_err_t qse_tio_err_t; | ||||
|  | ||||
| enum | ||||
| { | ||||
|         /* the size of input buffer should be at least equal to or greater | ||||
| @ -84,7 +86,7 @@ typedef qse_ssize_t (*qse_tio_io_t) ( | ||||
| struct qse_tio_t | ||||
| { | ||||
| 	qse_mmgr_t* mmgr; | ||||
| 	int errnum; | ||||
| 	qse_tio_err_t errnum; | ||||
|  | ||||
| 	/* io functions */ | ||||
| 	qse_tio_io_t input_func; | ||||
| @ -143,17 +145,14 @@ void qse_tio_setmmgr ( | ||||
| 	qse_mmgr_t* mmgr | ||||
| ); | ||||
|  | ||||
| /* | ||||
|  * FUNCTION: qse_tio_geterrnum | ||||
|  *   Returns an error code | ||||
| /****f* qse.cmn.tio/qse_tio_geterrnum | ||||
|  * NAME | ||||
|  *  qse_tio_geterrnum - get an error code | ||||
|  * | ||||
|  * PARAMETERS: | ||||
|  *   grep - a grep object | ||||
|  * | ||||
|  * RETURNS: | ||||
|  *   Error code set by the last tio function called | ||||
|  * SYNOPSIS | ||||
|  */ | ||||
| int qse_tio_geterrnum (qse_tio_t* tio); | ||||
| qse_tio_err_t qse_tio_geterrnum (qse_tio_t* tio); | ||||
| /******/ | ||||
|  | ||||
| /* | ||||
|  * FUNCTION: qse_tio_geterrstr | ||||
|  | ||||
| @ -449,23 +449,25 @@ int qse_pio_wait (qse_pio_t* pio, int flags) | ||||
|  | ||||
| 	if (pio->child == QSE_PIO_PID_NIL) return -1; | ||||
|  | ||||
| 	if (flags & QSE_PIO_NOWAIT) opt |= WNOHANG; | ||||
| 	if (flags & QSE_PIO_NOHANG) opt |= WNOHANG; | ||||
|  | ||||
| 	while (1) | ||||
| 	{ | ||||
| 		int n = QSE_WAITPID (pio->child, &status, opt); | ||||
|  | ||||
| qse_printf (QSE_T("n=%d,pio->child=%d,errno=%d,ECHILD=%d\n"), n, pio->child, errno, ECHILD); | ||||
| 		if (n == -1) | ||||
| 		{ | ||||
| 			if (errno == ECHILD) | ||||
| 			{ | ||||
| 				/* most likely, the process has already been waitpid()ed on. */ | ||||
| 				/* most likely, the process has already been  | ||||
| 				 * waitpid()ed on. */ | ||||
|  | ||||
| 				/* TODO: what should we do... ? */ | ||||
| 				/* ??? TREAT AS NORMAL??? => cannot know exit code => TREAT AS ERROR but reset pio->child   */ | ||||
|  | ||||
| 				pio->child = QSE_PIO_PID_NIL; | ||||
| 				ret = -1; /* OR ECHILD / QSE_PIO_ECHILD */ | ||||
| 				pio->errnum = QSE_PIO_ECHILD; | ||||
| 				ret = -1;  | ||||
| 				break; | ||||
| 			} | ||||
|  | ||||
| @ -475,7 +477,7 @@ qse_printf (QSE_T("n=%d,pio->child=%d,errno=%d,ECHILD=%d\n"), n, pio->child, err | ||||
| 		if (n == 0)  | ||||
| 		{ | ||||
| 			/* when WNOHANG is not specified, 0 can't be returned */ | ||||
| 			QSE_ASSERT (flags & QSE_PIO_NOWAIT); | ||||
| 			QSE_ASSERT (flags & QSE_PIO_NOHANG); | ||||
|  | ||||
| 			ret = -2; | ||||
| 			/* the child process is still alive */ | ||||
|  | ||||
| @ -98,7 +98,7 @@ void qse_tio_setmmgr (qse_tio_t* tio, qse_mmgr_t* mmgr) | ||||
| 	tio->mmgr = mmgr; | ||||
| } | ||||
|  | ||||
| int qse_tio_geterrnum (qse_tio_t* tio) | ||||
| qse_tio_err_t qse_tio_geterrnum (qse_tio_t* tio) | ||||
| { | ||||
| 	return tio->errnum; | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user