project_files/Android-build/SDL-android-project/jni/sdl_net/SDLnetUDP.c
author Xeli
Thu, 23 Jun 2011 14:30:04 +0200
branchhedgeroid
changeset 5317 86984c1034a5
permissions -rw-r--r--
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5317
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     1
/*
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     2
    SDL_net:  An example cross-platform network library for use with SDL
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     3
    Copyright (C) 1997-2004 Sam Lantinga
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     4
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
     9
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    13
    Library General Public License for more details.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    14
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    18
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    19
    Sam Lantinga
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    20
    slouken@libsdl.org
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    21
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    22
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    23
/* $Id: SDLnetUDP.c 1192 2004-01-04 17:41:55Z slouken $ */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    24
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    25
#include "SDLnetsys.h"
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    26
#include "SDL_net.h"
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    27
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    28
#include <Events.h>
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    29
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    30
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    31
struct _UDPsocket {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    32
	int ready;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    33
	SOCKET channel;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    34
	IPaddress address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    35
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    36
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    37
	OTEventCode newEvent;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    38
	OTEventCode event;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    39
	OTEventCode curEvent;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    40
	OTEventCode newCompletion;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    41
	OTEventCode completion;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    42
	OTEventCode curCompletion;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    43
	TEndpointInfo info;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    44
	Boolean		readShutdown;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    45
	Boolean		writeShutdown;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    46
	OSStatus	error;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    47
	OTConfigurationRef	config;		// Master configuration. you can clone this.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    48
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    49
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    50
	struct UDP_channel {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    51
		int numbound;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    52
		IPaddress address[SDLNET_MAX_UDPADDRESSES];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    53
	} binding[SDLNET_MAX_UDPCHANNELS];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    54
};
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    55
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    56
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    57
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    58
/* A helper function for Mac OpenTransport support*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    59
// This function is a complete copy from GUSI
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    60
// ( masahiro minami<elsur@aaa.letter.co.jp> )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    61
// ( 01/02/19 )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    62
//
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    63
// I guess this function should be put in SDLnet.c
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    64
// ( 010315 masahiro minami<elsur@aaa.letter.co.jp>)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    65
// (TODO)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    66
static __inline__ Uint32 CompleteMask(OTEventCode code)	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    67
{ 	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    68
	return 1 << (code & 0x1F); 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    69
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    70
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    71
/* Notifier for async OT calls */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    72
// This function is completely same as AsyncTCPNotifier,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    73
// except for the argument, UDPsocket / TCPsocket
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    74
// ( 010315 masahiro minami<elsur@aaa.letter.co.jp>)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    75
static pascal void AsyncUDPNotifier( UDPsocket sock, OTEventCode code,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    76
					OTResult result, void* cookie )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    77
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    78
	switch( code & 0x7f000000L)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    79
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    80
		case 0:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    81
			sock->newEvent |= code;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    82
			result = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    83
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    84
		case kCOMPLETEEVENT:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    85
			if(!(code & 0x00FFFFE0 ))
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    86
				sock->newCompletion |= CompleteMask( code );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    87
			if( code == T_OPENCOMPLETE )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    88
				sock->channel = (SOCKET)(cookie);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    89
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    90
		default:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    91
			if( code != kOTProviderWillClose )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    92
				result = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    93
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    94
	// Do we need these ???? TODO
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    95
	// sock->SetAsyncMacError( result );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    96
	// sock->Wakeup();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    97
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    98
	// Do we need to ?
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
    99
	//YieldToAnyThread();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   100
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   101
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   102
/* Retrieve OT event */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   103
// This function is completely same as AsyncTCPPopEvent,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   104
// except for the argument, UDPsocket / TCPsocket
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   105
// ( 010315 masahiro minami<elsur@aaa.letter.co.jp>)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   106
static void AsyncUDPPopEvent( UDPsocket sock )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   107
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   108
	// Make sure OT calls are not interrupted
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   109
	// Not sure if we really need this.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   110
	OTEnterNotifier( sock->channel );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   111
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   112
	sock->event |= (sock->curEvent = sock->newEvent );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   113
	sock->completion |= ( sock->curCompletion = sock->newCompletion );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   114
	sock->newEvent = sock->newCompletion = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   115
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   116
	OTLeaveNotifier( sock->channel );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   117
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   118
	if( sock->curEvent & T_UDERR)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   119
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   120
		// We just clear the error.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   121
		// Should we feed this back to users ?
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   122
		// (TODO )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   123
		OTRcvUDErr( sock->channel, NULL );	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   124
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   125
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   126
	// Remote is disconnecting...
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   127
	if( sock->curEvent & ( T_DISCONNECT | T_ORDREL ))
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   128
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   129
		sock->readShutdown = true;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   130
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   131
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   132
	if( sock->curEvent &T_CONNECT)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   133
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   134
		// Ignore the info of remote (second parameter).
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   135
		// Shoule we care ?
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   136
		// (TODO)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   137
		OTRcvConnect( sock->channel, NULL );	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   138
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   139
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   140
	if( sock->curEvent & T_ORDREL )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   141
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   142
		OTRcvOrderlyDisconnect( sock->channel );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   143
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   144
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   145
	if( sock->curEvent & T_DISCONNECT )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   146
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   147
		OTRcvDisconnect( sock->channel, NULL );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   148
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   149
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   150
	// Should we ??
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   151
	// (010318 masahiro minami<elsur@aaa.letter.co.jp>
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   152
	//YieldToAnyThread();
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   153
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   154
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   155
/* Create a new UDPsocket */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   156
// Because TCPsocket structure gets bigger and bigger,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   157
// I think we'd better have a constructor function and delete function.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   158
// ( 01/02/25 masahiro minami<elsur@aaa.letter.co.jp> )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   159
/*static*/ UDPsocket AsyncUDPNewSocket()
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   160
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   161
	UDPsocket sock;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   162
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   163
	sock = (UDPsocket)malloc(sizeof(*sock));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   164
	if ( sock == NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   165
		SDLNet_SetError("Out of memory");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   166
		return NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   167
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   168
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   169
	sock->newEvent = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   170
	sock->event = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   171
	sock->curEvent = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   172
	sock->newCompletion = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   173
	sock->completion = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   174
	sock->curCompletion = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   175
	//sock->info = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   176
	sock->readShutdown = sock->writeShutdown = false;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   177
	sock->error = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   178
	sock->config = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   179
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   180
	return sock;	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   181
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   182
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   183
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   184
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   185
/* Allocate/free a single UDP packet 'size' bytes long.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   186
   The new packet is returned, or NULL if the function ran out of memory.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   187
 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   188
extern UDPpacket *SDLNet_AllocPacket(int size)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   189
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   190
	UDPpacket *packet;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   191
	int error;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   192
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   193
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   194
	error = 1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   195
	packet = (UDPpacket *)malloc(sizeof(*packet));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   196
	if ( packet != NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   197
		packet->maxlen = size;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   198
		packet->data = (Uint8 *)malloc(size);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   199
		if ( packet->data != NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   200
			error = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   201
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   202
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   203
	if ( error ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   204
		SDLNet_FreePacket(packet);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   205
		packet = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   206
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   207
	return(packet);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   208
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   209
int SDLNet_ResizePacket(UDPpacket *packet, int newsize)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   210
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   211
	Uint8 *newdata;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   212
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   213
	newdata = (Uint8 *)malloc(newsize);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   214
	if ( newdata != NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   215
		free(packet->data);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   216
		packet->data = newdata;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   217
		packet->maxlen = newsize;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   218
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   219
	return(packet->maxlen);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   220
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   221
extern void SDLNet_FreePacket(UDPpacket *packet)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   222
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   223
	if ( packet ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   224
		if ( packet->data )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   225
			free(packet->data);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   226
		free(packet);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   227
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   228
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   229
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   230
/* Allocate/Free a UDP packet vector (array of packets) of 'howmany' packets,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   231
   each 'size' bytes long.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   232
   A pointer to the packet array is returned, or NULL if the function ran out
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   233
   of memory.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   234
 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   235
UDPpacket **SDLNet_AllocPacketV(int howmany, int size)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   236
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   237
	UDPpacket **packetV;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   238
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   239
	packetV = (UDPpacket **)malloc((howmany+1)*sizeof(*packetV));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   240
	if ( packetV != NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   241
		int i;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   242
		for ( i=0; i<howmany; ++i ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   243
			packetV[i] = SDLNet_AllocPacket(size);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   244
			if ( packetV[i] == NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   245
				break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   246
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   247
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   248
		packetV[i] = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   249
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   250
		if ( i != howmany ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   251
			SDLNet_FreePacketV(packetV);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   252
			packetV = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   253
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   254
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   255
	return(packetV);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   256
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   257
void SDLNet_FreePacketV(UDPpacket **packetV)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   258
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   259
	if ( packetV ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   260
		int i;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   261
		for ( i=0; packetV[i]; ++i ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   262
			SDLNet_FreePacket(packetV[i]);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   263
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   264
		free(packetV);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   265
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   266
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   267
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   268
/* Since the UNIX/Win32/BeOS code is so different from MacOS,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   269
   we'll just have two completely different sections here.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   270
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   271
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   272
/* Open a UDP network socket
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   273
   If 'port' is non-zero, the UDP socket is bound to a fixed local port.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   274
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   275
extern UDPsocket SDLNet_UDP_Open(Uint16 port)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   276
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   277
	UDPsocket sock;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   278
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   279
	EndpointRef dummy = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   280
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   281
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   282
	/* Allocate a UDP socket structure */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   283
	sock = (UDPsocket)malloc(sizeof(*sock));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   284
	if ( sock == NULL ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   285
		SDLNet_SetError("Out of memory");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   286
		goto error_return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   287
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   288
	memset(sock, 0, sizeof(*sock));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   289
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   290
	/* Open the socket */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   291
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   292
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   293
		sock->error = OTAsyncOpenEndpoint(
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   294
			OTCreateConfiguration(kUDPName),0, &(sock->info),
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   295
			(OTNotifyProcPtr)AsyncUDPNotifier, sock );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   296
		AsyncUDPPopEvent( sock );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   297
		while( !sock->error && !( sock->completion & CompleteMask(T_OPENCOMPLETE)))
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   298
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   299
			AsyncUDPPopEvent( sock );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   300
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   301
		if( sock->error )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   302
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   303
			SDLNet_SetError("Could not open UDP socket");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   304
			goto error_return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   305
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   306
		// Should we ??
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   307
		// (01/05/03 minami<elsur@aaa.letter.co.jp>
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   308
		OTSetBlocking( sock->channel );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   309
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   310
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   311
	sock->channel = socket(AF_INET, SOCK_DGRAM, 0);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   312
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   313
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   314
	if ( sock->channel == INVALID_SOCKET ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   315
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   316
		SDLNet_SetError("Couldn't create socket");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   317
		goto error_return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   318
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   319
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   320
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   321
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   322
	InetAddress required, assigned;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   323
	TBind req_addr, assigned_addr;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   324
	OSStatus status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   325
	InetInterfaceInfo info;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   326
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   327
		memset(&assigned_addr, 0, sizeof(assigned_addr));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   328
		assigned_addr.addr.maxlen = sizeof(assigned);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   329
		assigned_addr.addr.len = sizeof(assigned);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   330
		assigned_addr.addr.buf = (UInt8 *) &assigned;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   331
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   332
		if ( port ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   333
			status = OTInetGetInterfaceInfo( &info, kDefaultInetInterface );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   334
			if( status != kOTNoError )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   335
				goto error_return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   336
			OTInitInetAddress(&required, port, info.fAddress );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   337
			req_addr.addr.maxlen = sizeof( required );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   338
			req_addr.addr.len = sizeof( required );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   339
			req_addr.addr.buf = (UInt8 *) &required;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   340
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   341
			sock->error = OTBind(sock->channel, &req_addr, &assigned_addr);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   342
		} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   343
			sock->error = OTBind(sock->channel, nil, &assigned_addr );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   344
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   345
		AsyncUDPPopEvent(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   346
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   347
		while( !sock->error && !(sock->completion & CompleteMask(T_BINDCOMPLETE)))
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   348
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   349
			AsyncUDPPopEvent(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   350
		}	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   351
		if (sock->error != noErr)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   352
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   353
			SDLNet_SetError("Couldn't bind to local port, OTBind() = %d",(int) status);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   354
			goto error_return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   355
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   356
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   357
		sock->address.host = assigned.fHost;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   358
		sock->address.port = assigned.fPort;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   359
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   360
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   361
		printf("UDP open host = %d, port = %d\n", assigned.fHost, assigned.fPort );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   362
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   363
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   364
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   365
	/* Bind locally, if appropriate */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   366
	if ( port )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   367
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   368
		struct sockaddr_in sock_addr;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   369
		memset(&sock_addr, 0, sizeof(sock_addr));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   370
		sock_addr.sin_family = AF_INET;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   371
		sock_addr.sin_addr.s_addr = INADDR_ANY;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   372
		sock_addr.sin_port = SDL_SwapBE16(port);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   373
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   374
		/* Bind the socket for listening */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   375
		if ( bind(sock->channel, (struct sockaddr *)&sock_addr,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   376
				sizeof(sock_addr)) == SOCKET_ERROR ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   377
			SDLNet_SetError("Couldn't bind to local port");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   378
			goto error_return;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   379
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   380
		/* Fill in the channel host address */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   381
		sock->address.host = sock_addr.sin_addr.s_addr;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   382
		sock->address.port = sock_addr.sin_port;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   383
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   384
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   385
#ifdef SO_BROADCAST
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   386
	/* Allow LAN broadcasts with the socket */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   387
	{ int yes = 1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   388
		setsockopt(sock->channel, SOL_SOCKET, SO_BROADCAST, (char*)&yes, sizeof(yes));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   389
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   390
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   391
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   392
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   393
	/* The socket is ready */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   394
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   395
	return(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   396
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   397
error_return:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   398
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   399
	if( dummy )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   400
		OTCloseProvider( dummy );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   401
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   402
	SDLNet_UDP_Close(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   403
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   404
	return(NULL);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   405
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   406
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   407
/* Verify that the channel is in the valid range */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   408
static int ValidChannel(int channel)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   409
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   410
	if ( (channel < 0) || (channel >= SDLNET_MAX_UDPCHANNELS) ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   411
		SDLNet_SetError("Invalid channel");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   412
		return(0);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   413
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   414
	return(1);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   415
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   416
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   417
/* Bind the address 'address' to the requested channel on the UDP socket.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   418
   If the channel is -1, then the first unbound channel will be bound with
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   419
   the given address as it's primary address.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   420
   If the channel is already bound, this new address will be added to the
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   421
   list of valid source addresses for packets arriving on the channel.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   422
   If the channel is not already bound, then the address becomes the primary
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   423
   address, to which all outbound packets on the channel are sent.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   424
   This function returns the channel which was bound, or -1 on error.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   425
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   426
int SDLNet_UDP_Bind(UDPsocket sock, int channel, IPaddress *address)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   427
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   428
	struct UDP_channel *binding;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   429
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   430
	if ( channel == -1 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   431
		for ( channel=0; channel < SDLNET_MAX_UDPCHANNELS; ++channel ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   432
			binding = &sock->binding[channel];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   433
			if ( binding->numbound < SDLNET_MAX_UDPADDRESSES ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   434
				break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   435
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   436
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   437
	} else {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   438
		if ( ! ValidChannel(channel) ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   439
			return(-1);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   440
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   441
		binding = &sock->binding[channel];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   442
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   443
	if ( binding->numbound == SDLNET_MAX_UDPADDRESSES ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   444
		SDLNet_SetError("No room for new addresses");
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   445
		return(-1);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   446
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   447
	binding->address[binding->numbound++] = *address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   448
	return(channel);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   449
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   450
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   451
/* Unbind all addresses from the given channel */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   452
void SDLNet_UDP_Unbind(UDPsocket sock, int channel)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   453
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   454
	if ( (channel >= 0) && (channel < SDLNET_MAX_UDPCHANNELS) ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   455
		sock->binding[channel].numbound = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   456
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   457
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   458
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   459
/* Get the primary IP address of the remote system associated with the
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   460
   socket and channel.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   461
   If the channel is not bound, this function returns NULL.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   462
 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   463
IPaddress *SDLNet_UDP_GetPeerAddress(UDPsocket sock, int channel)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   464
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   465
	IPaddress *address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   466
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   467
	address = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   468
	switch (channel) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   469
		case -1:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   470
			/* Return the actual address of the socket */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   471
			address = &sock->address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   472
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   473
		default:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   474
			/* Return the address of the bound channel */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   475
			if ( ValidChannel(channel) &&
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   476
				(sock->binding[channel].numbound > 0) ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   477
				address = &sock->binding[channel].address[0];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   478
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   479
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   480
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   481
	return(address);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   482
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   483
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   484
/* Send a vector of packets to the the channels specified within the packet.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   485
   If the channel specified in the packet is -1, the packet will be sent to
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   486
   the address in the 'src' member of the packet.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   487
   Each packet will be updated with the status of the packet after it has 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   488
   been sent, -1 if the packet send failed.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   489
   This function returns the number of packets sent.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   490
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   491
int SDLNet_UDP_SendV(UDPsocket sock, UDPpacket **packets, int npackets)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   492
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   493
	int numsent, i, j;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   494
	struct UDP_channel *binding;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   495
	int status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   496
#ifndef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   497
	int sock_len;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   498
	struct sockaddr_in sock_addr;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   499
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   500
	/* Set up the variables to send packets */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   501
	sock_len = sizeof(sock_addr);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   502
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   503
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   504
	numsent = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   505
	for ( i=0; i<npackets; ++i ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   506
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   507
		/* if channel is < 0, then use channel specified in sock */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   508
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   509
		if ( packets[i]->channel < 0 ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   510
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   511
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   512
		TUnitData OTpacket;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   513
		InetAddress address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   514
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   515
			memset(&OTpacket, 0, sizeof(OTpacket));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   516
			OTpacket.addr.buf = (Uint8 *)&address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   517
			OTpacket.addr.len = (sizeof address);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   518
			OTpacket.udata.buf = packets[i]->data;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   519
			OTpacket.udata.len = packets[i]->len;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   520
			OTInitInetAddress(&address, packets[i]->address.port, packets[i]->address.host);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   521
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   522
			printf("Packet send address: 0x%8.8x:%d, length = %d\n", packets[i]->address.host, packets[i]->address.port, packets[i]->len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   523
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   524
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   525
			status = OTSndUData(sock->channel, &OTpacket);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   526
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   527
			printf("SDLNet_UDP_SendV   OTSndUData return value is ;%d\n", status );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   528
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   529
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   530
			AsyncUDPPopEvent( sock );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   531
			packets[i]->status = status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   532
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   533
			if (status == noErr)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   534
			{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   535
				++numsent;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   536
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   537
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   538
			sock_addr.sin_addr.s_addr = packets[i]->address.host;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   539
			sock_addr.sin_port = packets[i]->address.port;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   540
			sock_addr.sin_family = AF_INET;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   541
			status = sendto(sock->channel, 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   542
					packets[i]->data, packets[i]->len, 0,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   543
					(struct sockaddr *)&sock_addr,sock_len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   544
			if ( status >= 0 )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   545
			{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   546
				packets[i]->status = status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   547
				++numsent;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   548
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   549
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   550
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   551
		else 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   552
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   553
			/* Send to each of the bound addresses on the channel */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   554
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   555
			printf("SDLNet_UDP_SendV sending packet to channel = %d\n", packets[i]->channel );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   556
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   557
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   558
			binding = &sock->binding[packets[i]->channel];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   559
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   560
			for ( j=binding->numbound-1; j>=0; --j ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   561
			{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   562
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   563
			TUnitData OTpacket;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   564
			InetAddress address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   565
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   566
				OTInitInetAddress(&address, binding->address[j].port,binding->address[j].host);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   567
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   568
				printf("Packet send address: 0x%8.8x:%d, length = %d\n", binding->address[j].host, binding->address[j].port, packets[i]->len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   569
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   570
				memset(&OTpacket, 0, sizeof(OTpacket));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   571
				OTpacket.addr.buf = (Uint8 *)&address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   572
				OTpacket.addr.len = (sizeof address);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   573
				OTpacket.udata.buf = packets[i]->data;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   574
				OTpacket.udata.len = packets[i]->len;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   575
			                              
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   576
				status = OTSndUData(sock->channel, &OTpacket);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   577
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   578
				printf("SDLNet_UDP_SendV   OTSndUData returne value is;%d\n", status );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   579
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   580
				AsyncUDPPopEvent(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   581
				packets[i]->status = status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   582
				
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   583
				if (status == noErr)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   584
				{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   585
					++numsent;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   586
				}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   587
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   588
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   589
				sock_addr.sin_addr.s_addr = binding->address[j].host;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   590
				sock_addr.sin_port = binding->address[j].port;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   591
				sock_addr.sin_family = AF_INET;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   592
				status = sendto(sock->channel, 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   593
						packets[i]->data, packets[i]->len, 0,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   594
						(struct sockaddr *)&sock_addr,sock_len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   595
				if ( status >= 0 )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   596
				{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   597
					packets[i]->status = status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   598
					++numsent;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   599
				}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   600
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   601
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   602
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   603
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   604
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   605
	return(numsent);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   606
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   607
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   608
int SDLNet_UDP_Send(UDPsocket sock, int channel, UDPpacket *packet)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   609
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   610
	/* This is silly, but... */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   611
	packet->channel = channel;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   612
	return(SDLNet_UDP_SendV(sock, &packet, 1));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   613
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   614
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   615
/* Returns true if a socket is has data available for reading right now */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   616
static int SocketReady(SOCKET sock)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   617
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   618
	int retval = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   619
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   620
	OTResult status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   621
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   622
	struct timeval tv;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   623
	fd_set mask;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   624
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   625
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   626
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   627
	//status = OTGetEndpointState(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   628
	status = OTLook(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   629
	if( status > 0 )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   630
		retval = 1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   631
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   632
/*	switch( status )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   633
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   634
//		case T_IDLE:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   635
		case T_DATAXFER:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   636
//		case T_INREL:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   637
			retval = 1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   638
			break;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   639
		default:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   640
			OTCountDataBytes( sock, &numBytes );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   641
			if( numBytes )
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   642
				retval = 1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   643
	}*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   644
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   645
	/* Check the file descriptors for available data */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   646
	do {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   647
		errno = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   648
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   649
		/* Set up the mask of file descriptors */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   650
		FD_ZERO(&mask);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   651
		FD_SET(sock, &mask);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   652
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   653
		/* Set up the timeout */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   654
		tv.tv_sec = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   655
		tv.tv_usec = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   656
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   657
		/* Look! */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   658
		retval = select(sock+1, &mask, NULL, NULL, &tv);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   659
	} while ( errno == EINTR );
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   660
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   661
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   662
	return(retval == 1);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   663
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   664
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   665
/* Receive a vector of pending packets from the UDP socket.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   666
   The returned packets contain the source address and the channel they arrived
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   667
   on.  If they did not arrive on a bound channel, the the channel will be set
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   668
   to -1.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   669
   This function returns the number of packets read from the network, or -1
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   670
   on error.  This function does not block, so can return 0 packets pending.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   671
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   672
extern int SDLNet_UDP_RecvV(UDPsocket sock, UDPpacket **packets)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   673
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   674
	int numrecv, i, j;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   675
	struct UDP_channel *binding;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   676
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   677
	TUnitData OTpacket;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   678
	OTFlags flags;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   679
	InetAddress address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   680
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   681
	int sock_len;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   682
	struct sockaddr_in sock_addr;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   683
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   684
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   685
	numrecv = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   686
	while ( packets[numrecv] && SocketReady(sock->channel) ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   687
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   688
	UDPpacket *packet;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   689
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   690
		packet = packets[numrecv];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   691
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   692
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   693
		memset(&OTpacket, 0, sizeof(OTpacket));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   694
		OTpacket.addr.buf = (Uint8 *)&address;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   695
		OTpacket.addr.maxlen = (sizeof address);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   696
		OTpacket.udata.buf = packet->data;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   697
		OTpacket.udata.maxlen = packet->maxlen;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   698
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   699
		packet->status = OTRcvUData(sock->channel, &OTpacket, &flags);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   700
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   701
		printf("Packet status: %d\n", packet->status);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   702
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   703
		AsyncUDPPopEvent(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   704
		if (packet->status == noErr)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   705
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   706
			packet->len = OTpacket.udata.len;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   707
			packet->address.host = address.fHost;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   708
			packet->address.port = address.fPort;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   709
#ifdef DEBUG_NET
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   710
			printf("Packet address: 0x%8.8x:%d, length = %d\n", packet->address.host, packet->address.port, packet->len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   711
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   712
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   713
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   714
		sock_len = sizeof(sock_addr);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   715
		packet->status = recvfrom(sock->channel,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   716
				packet->data, packet->maxlen, 0,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   717
				(struct sockaddr *)&sock_addr,
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   718
#ifdef USE_GUSI_SOCKETS
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   719
				(unsigned int *)&sock_len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   720
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   721
						&sock_len);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   722
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   723
		if ( packet->status >= 0 ) {
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   724
			packet->len = packet->status;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   725
			packet->address.host = sock_addr.sin_addr.s_addr;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   726
			packet->address.port = sock_addr.sin_port;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   727
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   728
#endif
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   729
		if (packet->status >= 0)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   730
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   731
			packet->channel = -1;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   732
			
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   733
			for (i=(SDLNET_MAX_UDPCHANNELS-1); i>=0; --i ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   734
			{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   735
				binding = &sock->binding[i];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   736
				
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   737
				for ( j=binding->numbound-1; j>=0; --j ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   738
				{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   739
					if ( (packet->address.host == binding->address[j].host) &&
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   740
					     (packet->address.port == binding->address[j].port) ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   741
					{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   742
						packet->channel = i;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   743
						goto foundit; /* break twice */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   744
					}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   745
				}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   746
			}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   747
foundit:
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   748
			++numrecv;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   749
		} 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   750
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   751
		else 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   752
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   753
			packet->len = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   754
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   755
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   756
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   757
	sock->ready = 0;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   758
	
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   759
	return(numrecv);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   760
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   761
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   762
/* Receive a single packet from the UDP socket.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   763
   The returned packet contains the source address and the channel it arrived
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   764
   on.  If it did not arrive on a bound channel, the the channel will be set
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   765
   to -1.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   766
   This function returns the number of packets read from the network, or -1
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   767
   on error.  This function does not block, so can return 0 packets pending.
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   768
*/
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   769
int SDLNet_UDP_Recv(UDPsocket sock, UDPpacket *packet)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   770
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   771
	UDPpacket *packets[2];
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   772
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   773
	/* Receive a packet array of 1 */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   774
	packets[0] = packet;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   775
	packets[1] = NULL;
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   776
	return(SDLNet_UDP_RecvV(sock, packets));
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   777
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   778
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   779
/* Close a UDP network socket */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   780
extern void SDLNet_UDP_Close(UDPsocket sock)
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   781
{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   782
	if ( sock != NULL ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   783
	{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   784
		if ( sock->channel != INVALID_SOCKET ) 
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   785
		{
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   786
#ifdef MACOS_OPENTRANSPORT
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   787
			OTUnbind(sock->channel);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   788
			OTCloseProvider(sock->channel);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   789
#else
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   790
			closesocket(sock->channel);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   791
#endif /* MACOS_OPENTRANSPORT */
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   792
		}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   793
		
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   794
		free(sock);
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   795
	}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   796
}
86984c1034a5 Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff changeset
   797