Blame src/socket/ntapi_sc_wait.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dde53a
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_sync.h>
dd89bb
#include <ntapi/nt_socket.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
2e04e9
int32_t __cdecl __ntapi_sc_wait(
2e04e9
	nt_socket *		hssocket,
2e04e9
	nt_iosb volatile *	iosb,
2e04e9
	nt_timeout *		timeout)
dd89bb
{
2e04e9
	nt_iosb cancel;
dd89bb
dd89bb
	timeout = (timeout && timeout->quad)
dd89bb
		? timeout
dd89bb
		: 0;
dd89bb
dd89bb
	if (hssocket->hevent && (hssocket->iostatus == NT_STATUS_PENDING)) {
dd89bb
		hssocket->waitstatus = __ntapi->zw_wait_for_single_object(
dd89bb
				hssocket->hevent,
dd89bb
				!!(hssocket->ntflags & NT_FILE_SYNCHRONOUS_IO_ALERT),
dd89bb
				timeout);
dd89bb
dd89bb
		switch (hssocket->waitstatus) {
dd89bb
			case NT_STATUS_SUCCESS:
af4a59
				hssocket->iostatus = iosb->status;
dd89bb
				break;
dd89bb
dd89bb
			case NT_STATUS_ALERTED:
dd89bb
				hssocket->iostatus = NT_STATUS_ALERTED;
dd89bb
				__ntapi->zw_cancel_io_file(
dd89bb
					hssocket->hsocket,
dd89bb
					&cancel);
dd89bb
				break;
dd89bb
		}
dd89bb
	}
dd89bb
dd89bb
	return hssocket->iostatus;
dd89bb
}