Blame src/socket/ntapi_sc_wait.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dd89bb
/*  Copyright (C) 2013,2014,2015  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
dd89bb
int32_t __cdecl __ntapi_sc_wait(nt_socket * hssocket, nt_iosb * iosb, nt_timeout * timeout)
dd89bb
{
dd89bb
	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:
dd89bb
				hssocket->iostatus = NT_STATUS_SUCCESS;
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
}