summaryrefslogtreecommitdiffhomepage
path: root/src/socket/ntapi_sc_wait.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-07-27 04:01:18 -0400
committermidipix <writeonce@midipix.org>2015-07-27 04:01:18 -0400
commitdd89bb8ad4fe184a34b5dbdda237e640fc82121b (patch)
tree5e80d2da35f5892f92be29f57982b2708e6bd99b /src/socket/ntapi_sc_wait.c
parentdcdadc2702712fa750ed255ed1dfa354522797a0 (diff)
downloadntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.bz2
ntapi-dd89bb8ad4fe184a34b5dbdda237e640fc82121b.tar.xz
entered advanced internal development stage.
Diffstat (limited to 'src/socket/ntapi_sc_wait.c')
-rw-r--r--src/socket/ntapi_sc_wait.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/socket/ntapi_sc_wait.c b/src/socket/ntapi_sc_wait.c
new file mode 100644
index 0000000..3bfad28
--- /dev/null
+++ b/src/socket/ntapi_sc_wait.c
@@ -0,0 +1,42 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013,2014,2015 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
+/********************************************************/
+
+#include <psxtypes/psxtypes.h>
+#include <ntapi/nt_sync.h>
+#include <ntapi/nt_socket.h>
+#include <ntapi/ntapi.h>
+#include "ntapi_impl.h"
+
+int32_t __cdecl __ntapi_sc_wait(nt_socket * hssocket, nt_iosb * iosb, nt_timeout * timeout)
+{
+ nt_iosb cancel;
+
+ timeout = (timeout && timeout->quad)
+ ? timeout
+ : 0;
+
+ if (hssocket->hevent && (hssocket->iostatus == NT_STATUS_PENDING)) {
+ hssocket->waitstatus = __ntapi->zw_wait_for_single_object(
+ hssocket->hevent,
+ !!(hssocket->ntflags & NT_FILE_SYNCHRONOUS_IO_ALERT),
+ timeout);
+
+ switch (hssocket->waitstatus) {
+ case NT_STATUS_SUCCESS:
+ hssocket->iostatus = NT_STATUS_SUCCESS;
+ break;
+
+ case NT_STATUS_ALERTED:
+ hssocket->iostatus = NT_STATUS_ALERTED;
+ __ntapi->zw_cancel_io_file(
+ hssocket->hsocket,
+ &cancel);
+ break;
+ }
+ }
+
+ return hssocket->iostatus;
+}