Blame src/socket/ntapi_sc_shutdown.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_object.h>
dd89bb
#include <ntapi/nt_file.h>
dd89bb
#include <ntapi/nt_socket.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
int32_t __cdecl __ntapi_sc_shutdown(
dd89bb
	__in	nt_socket *		hssocket,
dd89bb
	__in	uintptr_t		psxhow,
dd89bb
	__in	uintptr_t		afdhow,
dd89bb
	__out	nt_io_status_block *	iosb	__optional)
dd89bb
{
dd89bb
	nt_afd_disconnect_info	afd_disconnect;
dd89bb
	nt_io_status_block	siosb;
dd89bb
dd89bb
	iosb = iosb ? iosb : &siosb;
dd89bb
dd89bb
	if (afdhow == 0) {
dd89bb
		switch (psxhow) {
dd89bb
			case NT_SHUT_RD:
dd89bb
				afdhow = NT_AFD_DISCONNECT_RD;
dd89bb
				break;
dd89bb
dd89bb
			case NT_SHUT_WR:
dd89bb
				afdhow = NT_AFD_DISCONNECT_WR;
dd89bb
				break;
dd89bb
dd89bb
			case NT_SHUT_RDWR:
dd89bb
				afdhow = NT_AFD_DISCONNECT_RD | NT_AFD_DISCONNECT_WR;
dd89bb
				break;
dd89bb
dd89bb
			default:
dd89bb
				return NT_STATUS_INVALID_PARAMETER_2;
dd89bb
				break;
dd89bb
		}
dd89bb
	}
dd89bb
dd89bb
	afd_disconnect.shutdown_flags = (uint32_t)afdhow;
dd89bb
	afd_disconnect.unknown[0] = 0xff;
dd89bb
	afd_disconnect.unknown[1] = 0xff;
dd89bb
	afd_disconnect.unknown[2] = 0xff;
dd89bb
dd89bb
	hssocket->iostatus = __ntapi->zw_device_io_control_file(
dd89bb
			hssocket->hsocket,
dd89bb
			hssocket->hevent,
dd89bb
			0,
dd89bb
			0,
dd89bb
			iosb,
dd89bb
			NT_AFD_IOCTL_DISCONNECT,
dd89bb
			&afd_disconnect,
dd89bb
			sizeof(afd_disconnect),
dd89bb
			0,
dd89bb
			0);
dd89bb
dd89bb
	return hssocket->iostatus
dd89bb
		? __ntapi->sc_wait(hssocket,iosb,0)
dd89bb
		: NT_STATUS_SUCCESS;
dd89bb
}