Blame src/socket/ntapi_sc_send.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
4256e2
/*  Copyright (C) 2013--2016  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
eb53e6
eb53e6
typedef struct _nt_afd_send_udp_info {
eb53e6
	nt_afd_send_info	afd_send;
eb53e6
	uint32_t		afd_reserved[8];
eb53e6
	void *			pmeta;
eb53e6
	uint32_t		afd_unknown[4];
eb53e6
	uint32_t		extlen;
eb53e6
	uint32_t		unknown;
eb53e6
	uint32_t		addrlen;
eb53e6
	uint32_t		reserved;
eb53e6
	const nt_sockaddr *	addr;
eb53e6
} nt_afd_send_udp_info;
eb53e6
eb53e6
dd89bb
int32_t __cdecl __ntapi_sc_send(
dd89bb
	__in		nt_socket *		hssocket,
dd89bb
	__in		const void *		buffer,
dd89bb
	__in		size_t			len,
dd89bb
	__out		ssize_t *		bytes_sent	__optional,
eb53e6
	__in		const nt_sockaddr *	addr		__optional,
eb53e6
	__in		size_t			addrlen		__optional,
dd89bb
	__in		uintptr_t		afdflags	__optional,
dd89bb
	__in		uintptr_t		tdiflags	__optional,
dd89bb
	__out		nt_io_status_block *	iosb		__optional)
dd89bb
{
dd89bb
	nt_afd_buffer		afd_buffer;
eb53e6
	nt_afd_send_udp_info	afd_send;
dd89bb
	nt_io_status_block	siosb;
dd89bb
eb53e6
	if (addrlen && (addrlen != sizeof(nt_sockaddr_in4))
eb53e6
		    && (addrlen != sizeof(nt_sockaddr_in6)))
eb53e6
		return NT_STATUS_INVALID_PARAMETER_6;
eb53e6
dd89bb
	iosb = iosb ? iosb : &siosb;
dd89bb
eb53e6
	/* conditional connect */
eb53e6
	if (addrlen) {
eb53e6
		__ntapi->tt_aligned_block_memset(
eb53e6
			&afd_send,
eb53e6
			0,sizeof(afd_send));
eb53e6
eb53e6
		afd_send.pmeta    = &afd_send.extlen;
3e609e
		afd_send.addrlen  = (uint32_t)addrlen;
eb53e6
		afd_send.addr     = addr;
eb53e6
	}
eb53e6
dd89bb
	/* afd_buffer */
dd89bb
	afd_buffer.length = len;
dd89bb
	afd_buffer.buffer = (char *)buffer;
dd89bb
eb53e6
	/* afd_send.afd_send */
eb53e6
	afd_send.afd_send.afd_buffer_array = &afd_buffer;
eb53e6
	afd_send.afd_send.buffer_count     = 1;
dd89bb
eb53e6
	afd_send.afd_send.afd_flags = (uint32_t)afdflags;
eb53e6
	afd_send.afd_send.tdi_flags = (uint32_t)tdiflags;
dd89bb
dd89bb
	hssocket->iostatus = __ntapi->zw_device_io_control_file(
dd89bb
			hssocket->hsocket,
dd89bb
			hssocket->hevent,
dd89bb
			0,
dd89bb
			0,
dd89bb
			iosb,
eb53e6
			addrlen ? NT_AFD_IOCTL_UDP_SEND : NT_AFD_IOCTL_SEND,
dd89bb
			&afd_send,
eb53e6
			addrlen ? sizeof(afd_send) : sizeof(afd_send.afd_send),
dd89bb
			0,
dd89bb
			0);
dd89bb
dd89bb
	if (hssocket->iostatus && (hssocket->ntflags & __NT_FILE_SYNC_IO))
dd89bb
		__ntapi->sc_wait(hssocket,iosb,&hssocket->timeout);
dd89bb
dd89bb
	if (!hssocket->iostatus && bytes_sent)
dd89bb
		*bytes_sent = iosb->info;
dd89bb
dd89bb
	return hssocket->iostatus;
dd89bb
}