summaryrefslogtreecommitdiffhomepage
path: root/src/socket/ntapi_sc_shutdown.c
blob: 115214cfcb4f8b5c1df6031244e325a364ee4b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/********************************************************/
/*  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_object.h>
#include <ntapi/nt_file.h>
#include <ntapi/nt_socket.h>
#include <ntapi/ntapi.h>
#include "ntapi_impl.h"

int32_t __cdecl __ntapi_sc_shutdown(
	__in	nt_socket *		hssocket,
	__in	uintptr_t		psxhow,
	__in	uintptr_t		afdhow,
	__out	nt_io_status_block *	iosb	__optional)
{
	nt_afd_disconnect_info	afd_disconnect;
	nt_io_status_block	siosb;

	iosb = iosb ? iosb : &siosb;

	if (afdhow == 0) {
		switch (psxhow) {
			case NT_SHUT_RD:
				afdhow = NT_AFD_DISCONNECT_RD;
				break;

			case NT_SHUT_WR:
				afdhow = NT_AFD_DISCONNECT_WR;
				break;

			case NT_SHUT_RDWR:
				afdhow = NT_AFD_DISCONNECT_RD | NT_AFD_DISCONNECT_WR;
				break;

			default:
				return NT_STATUS_INVALID_PARAMETER_2;
				break;
		}
	}

	afd_disconnect.shutdown_flags = (uint32_t)afdhow;
	afd_disconnect.unknown[0] = 0xff;
	afd_disconnect.unknown[1] = 0xff;
	afd_disconnect.unknown[2] = 0xff;

	hssocket->iostatus = __ntapi->zw_device_io_control_file(
			hssocket->hsocket,
			hssocket->hevent,
			0,
			0,
			iosb,
			NT_AFD_IOCTL_DISCONNECT,
			&afd_disconnect,
			sizeof(afd_disconnect),
			0,
			0);

	return hssocket->iostatus
		? __ntapi->sc_wait(hssocket,iosb,0)
		: NT_STATUS_SUCCESS;
}