author | Xeli |
Tue, 05 Jul 2011 23:30:35 +0200 | |
branch | hedgeroid |
changeset 5408 | 1c2f0dfbe759 |
parent 5317 | 86984c1034a5 |
permissions | -rw-r--r-- |
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: SDLnetTCP.c 3280 2007-07-15 05:55:42Z 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 |
|
86984c1034a5
Added 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 |
/* The network API for TCP 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
|
29 |
|
86984c1034a5
Added 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 |
/* 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
|
31 |
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
|
32 |
*/ |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
#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
|
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 |
#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
|
37 |
#include <Threads.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
|
38 |
#include <OpenTransport.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
|
39 |
#include <OpenTptInternet.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
|
40 |
#include <OTDebug.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
|
41 |
|
86984c1034a5
Added 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 |
struct _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
|
43 |
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
|
44 |
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
|
45 |
|
86984c1034a5
Added 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 |
// These are taken from GUSI interface. |
86984c1034a5
Added 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 |
// I'm not sure if it's really necessary here yet |
86984c1034a5
Added 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 |
// ( 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
|
49 |
// ( 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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
Boolean connected; |
86984c1034a5
Added 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 |
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
|
62 |
TCPsocket nextListener; |
86984c1034a5
Added 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 |
// ( end of new members --- 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
|
64 |
|
86984c1034a5
Added 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 |
IPaddress remoteAddress; |
86984c1034a5
Added 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 |
IPaddress localAddress; |
86984c1034a5
Added 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 |
int sflag; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// Maybe we don't need this---- it's from original SDL_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
|
70 |
// (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
|
71 |
// ( 01/02/20 ) |
86984c1034a5
Added 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 |
int rcvdPassConn; |
86984c1034a5
Added 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 |
}; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// To be used in WaitNextEvent() here and there.... |
86984c1034a5
Added 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 |
// (010311 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
|
77 |
EventRecord macEvent; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
#if TARGET_API_MAC_CARBON |
86984c1034a5
Added 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 |
/* for Carbon */ |
86984c1034a5
Added 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 |
OTNotifyUPP notifier; |
86984c1034a5
Added 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 |
#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
|
83 |
|
86984c1034a5
Added 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 |
/* Input: ep - endpointref on which to negotiate the option |
86984c1034a5
Added 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 |
enableReuseIPMode - desired option setting - true/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
|
86 |
Return: kOTNoError indicates that the option was successfully negotiated |
86984c1034a5
Added 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 |
OSStatus is an error if < 0, otherwise, the status field is |
86984c1034a5
Added 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 |
returned and is > 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
|
89 |
|
86984c1034a5
Added 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 |
IMPORTANT NOTE: The endpoint is assumed to be in synchronous more, otherwise |
86984c1034a5
Added 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 |
this code will not function as desired |
86984c1034a5
Added 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 |
*/ |
86984c1034a5
Added 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 |
/* |
86984c1034a5
Added 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 |
NOTE: As this version is written async way, we don't use this 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
|
96 |
(010526) 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
|
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 |
/* |
86984c1034a5
Added 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 |
OSStatus DoNegotiateIPReuseAddrOption(EndpointRef ep, Boolean enableReuseIPMode) |
86984c1034a5
Added 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 |
UInt8 buf[kOTFourByteOptionSize]; // define buffer for fourByte Option 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
|
103 |
TOption* opt; // option ptr to make items easier to access |
86984c1034a5
Added 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 |
TOptMgmt req; |
86984c1034a5
Added 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 |
TOptMgmt ret; |
86984c1034a5
Added 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 |
OSStatus err; |
86984c1034a5
Added 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 |
if (!OTIsSynchronous(ep)) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
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
|
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 |
opt = (TOption*)buf; // set option ptr to buffer |
86984c1034a5
Added 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 |
req.opt.buf = buf; |
86984c1034a5
Added 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 |
req.opt.len = sizeof(buf); |
86984c1034a5
Added 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 |
req.flags = T_NEGOTIATE; // negotiate for option |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
ret.opt.buf = buf; |
86984c1034a5
Added 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 |
ret.opt.maxlen = kOTFourByteOptionSize; |
86984c1034a5
Added 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 |
opt->level = INET_IP; // dealing with an IP Level 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
|
121 |
opt->name = IP_REUSEADDR; |
86984c1034a5
Added 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 |
opt->len = kOTFourByteOptionSize; |
86984c1034a5
Added 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 |
opt->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
|
124 |
*(UInt32*)opt->value = enableReuseIPMode; // set the desired option level, true or 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
|
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 |
err = OTOptionManagement(ep, &req, &ret); |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// if no error then return the option status value |
86984c1034a5
Added 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 |
if (err == 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
|
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 |
if (opt->status != T_SUCCESS) |
86984c1034a5
Added 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 |
err = opt->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
|
133 |
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
|
134 |
err = 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
|
135 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
return err; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* 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
|
142 |
// 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
|
143 |
// ( 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
|
144 |
// ( 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
|
145 |
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
|
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 |
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
|
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 |
/* 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
|
151 |
static pascal void AsyncTCPNotifier( TCPsocket 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
|
152 |
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
|
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 |
#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
|
156 |
printf("AsyncTCPNotifier got an event : 0x%8.8x\n", 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
|
157 |
#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
|
158 |
|
86984c1034a5
Added 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 |
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
|
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 |
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
|
162 |
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
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
} |
86984c1034a5
Added 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 |
// 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
|
176 |
// 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
|
177 |
// 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
|
178 |
} |
86984c1034a5
Added 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 |
/* 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
|
181 |
// This function is taken from GUSI interface. |
86984c1034a5
Added 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 |
// ( 01/02/19 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
|
183 |
static void AsyncTCPPopEvent( TCPsocket 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
|
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 |
// 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
|
186 |
// 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
|
187 |
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
|
188 |
|
86984c1034a5
Added 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 |
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
|
190 |
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
|
191 |
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
|
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 |
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
|
194 |
|
86984c1034a5
Added 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 |
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
|
196 |
{ |
86984c1034a5
Added 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 |
// 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
|
198 |
// 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
|
199 |
// (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
|
200 |
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
|
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 |
#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
|
203 |
printf("AsyncTCPPopEvent T_UDERR recognized"); |
86984c1034a5
Added 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 |
#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
|
205 |
} |
86984c1034a5
Added 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 |
// 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
|
208 |
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
|
209 |
{ |
86984c1034a5
Added 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 |
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
|
211 |
} |
86984c1034a5
Added 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 |
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
|
214 |
{ |
86984c1034a5
Added 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 |
// 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
|
216 |
// 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
|
217 |
// (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
|
218 |
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
|
219 |
sock->connected = 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
|
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 |
|
86984c1034a5
Added 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 |
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
|
223 |
{ |
86984c1034a5
Added 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 |
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
|
225 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
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
|
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 |
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
|
230 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// 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
|
233 |
// (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
|
234 |
//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
|
235 |
} |
86984c1034a5
Added 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 |
/* Create a new 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
|
238 |
// 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
|
239 |
// 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
|
240 |
// ( 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
|
241 |
static TCPsocket AsyncTCPNewSocket() |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
TCPsocket 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
|
244 |
|
86984c1034a5
Added 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 |
sock = (TCPsocket)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
|
246 |
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
|
247 |
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
|
248 |
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
|
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 |
|
86984c1034a5
Added 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 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
//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
|
258 |
sock->readShutdown = sock->writeShutdown = sock->connected = 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
|
259 |
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
|
260 |
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
|
261 |
sock->nextListener = 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
|
262 |
sock->sflag = 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
|
263 |
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
|
264 |
} |
86984c1034a5
Added 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 |
// hmmm.... do we 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
|
267 |
// ( 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
|
268 |
static void AsycnTCPDeleteSocket( TCPsocket 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
|
269 |
{ |
86984c1034a5
Added 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 |
SDLNet_TCP_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
|
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 TCP 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 'remote' is NULL, this creates a local server socket on the given 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 |
otherwise a TCP connection to the remote host and port is attempted. |
86984c1034a5
Added 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 |
The newly created socket is returned, or NULL if there was an 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
|
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 |
( re-written by 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
|
278 |
Now endpoint is created in Async mode. |
86984c1034a5
Added 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 |
01/02/20 ) |
86984c1034a5
Added 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 |
*/ |
86984c1034a5
Added 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 |
TCPsocket SDLNet_TCP_Open(IPaddress *ip) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
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
|
284 |
|
86984c1034a5
Added 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 |
TCPsocket sock = AsyncTCPNewSocket(); |
86984c1034a5
Added 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 |
if( ! 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
|
287 |
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
|
288 |
|
86984c1034a5
Added 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 |
// Determin whether bind locally, or connect to remote |
86984c1034a5
Added 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 |
if ( (ip->host != INADDR_NONE) && (ip->host != 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
|
291 |
{ |
86984c1034a5
Added 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 |
// ######## Connect to remote |
86984c1034a5
Added 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 |
OTResult stat; |
86984c1034a5
Added 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 |
InetAddress inAddr; |
86984c1034a5
Added 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 |
TBind bindReq; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// Open endpoint |
86984c1034a5
Added 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 |
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
|
299 |
OTCreateConfiguration(kTCPName), NULL, &(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
|
300 |
(OTNotifyProcPtr)(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
|
301 |
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
|
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 |
AsyncTCPPopEvent( 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
|
304 |
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
|
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 |
//SetThreadState( kCurrentThreadID, kReadyThreadState, kNoThreadID ); |
86984c1034a5
Added 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 |
//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
|
308 |
//WaitNextEvent(everyEvent, &macEvent, 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
|
309 |
AsyncTCPPopEvent( 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
|
310 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
if( !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
|
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 |
SDLNet_SetError("OTAsyncOpenEndpoint failed --- client socket could not be opened"); |
86984c1034a5
Added 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 |
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
|
316 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// Set blocking mode |
86984c1034a5
Added 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 |
// I'm not sure if this is a good solution.... |
86984c1034a5
Added 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 |
// Check out Apple's sample code, OT Virtual Server |
86984c1034a5
Added 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 |
// ( 010314 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
|
322 |
|
86984c1034a5
Added 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 |
sock->error = 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
|
324 |
if( sock->error != 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
|
325 |
{ |
86984c1034a5
Added 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 |
SDLNet_SetError("OTSetBlocking() returned an 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
|
327 |
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
|
328 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// Bind 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
|
331 |
OTInitInetAddress(&inAddr, 0, 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
|
332 |
bindReq.addr.len = sizeof( InetAddress ); |
86984c1034a5
Added 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 |
bindReq.addr.buf = (unsigned char*)&inAddr; |
86984c1034a5
Added 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 |
bindReq.qlen = 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
|
335 |
|
86984c1034a5
Added 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 |
sock->error = OTBind( sock->channel, &bindReq, 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
|
337 |
AsyncTCPPopEvent(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
|
338 |
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
|
339 |
{ |
86984c1034a5
Added 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 |
//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
|
341 |
//WaitNextEvent(everyEvent, &macEvent, 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
|
342 |
AsyncTCPPopEvent(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
|
343 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
switch( stat = OTGetEndpointState( 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
|
347 |
{ |
86984c1034a5
Added 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 |
InetAddress inAddr; |
86984c1034a5
Added 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 |
TCall sndCall; |
86984c1034a5
Added 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 |
OTResult res; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
case T_OUTCON: |
86984c1034a5
Added 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("SDLNet_Open() failed -- T_OUTCON"); |
86984c1034a5
Added 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 |
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
|
356 |
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
|
357 |
sock->readShutdown = 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
|
358 |
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
|
359 |
sock->event &=~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
|
360 |
|
86984c1034a5
Added 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 |
OTMemzero(&sndCall, sizeof(TCall)); |
86984c1034a5
Added 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 |
OTInitInetAddress(&inAddr, ip->port, ip->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
|
363 |
sndCall.addr.len = sizeof(InetAddress); |
86984c1034a5
Added 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 |
sndCall.addr.buf = (unsigned char*)&inAddr; |
86984c1034a5
Added 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 |
sock->connected = 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
|
366 |
res = OTConnect( sock->channel, &sndCall, 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
|
367 |
AsyncTCPPopEvent(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
|
368 |
while( sock->error == kOTNoDataErr || !sock->connected ) |
86984c1034a5
Added 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 |
AsyncTCPPopEvent(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
|
370 |
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
|
371 |
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
|
372 |
// What's to be done ? (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
|
373 |
SDLNet_SetError("SDLNet_TCP_Open() failed -- EndpointState not good"); |
86984c1034a5
Added 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 |
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
|
375 |
|
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
if( !(sock->event & (T_CONNECT|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
|
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 |
AsyncTCPPopEvent( 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
|
381 |
while( !(sock->event & (T_CONNECT|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
|
382 |
{ |
86984c1034a5
Added 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 |
AsyncTCPPopEvent( 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
|
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 |
// OTConnect successfull |
86984c1034a5
Added 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 |
if( sock->event & 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
|
387 |
{ |
86984c1034a5
Added 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 |
sock->remoteAddress.host = inAddr.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
|
389 |
sock->remoteAddress.port = inAddr.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
|
390 |
sock->sflag = 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
|
391 |
} |
86984c1034a5
Added 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 |
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
|
393 |
{ |
86984c1034a5
Added 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 |
// OTConnect 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
|
395 |
sock->event &= ~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
|
396 |
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
|
397 |
} |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
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
|
400 |
{ |
86984c1034a5
Added 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 |
// ######## Bind locally |
86984c1034a5
Added 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 |
TBind bindReq; |
86984c1034a5
Added 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 |
InetAddress inAddr; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// First, get InetInterfaceInfo. |
86984c1034a5
Added 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 |
// I don't search for all of them. |
86984c1034a5
Added 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 |
// Does that matter ? |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
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
|
410 |
OTCreateConfiguration("tilisten, tcp"), NULL, &(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
|
411 |
(OTNotifyProcPtr)(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
|
412 |
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
|
413 |
AsyncTCPPopEvent( 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
|
414 |
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
|
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 |
AsyncTCPPopEvent( 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
|
417 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
if( ! 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
|
420 |
{ |
86984c1034a5
Added 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 |
SDLNet_SetError("OTAsyncOpenEndpoint failed --- server socket could not be opened"); |
86984c1034a5
Added 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 |
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
|
423 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// Create a master OTConfiguration |
86984c1034a5
Added 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 |
sock->config = OTCreateConfiguration(kTCPName); |
86984c1034a5
Added 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 |
if( ! sock->config ) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
SDLNet_SetError("Could not create master OTConfiguration"); |
86984c1034a5
Added 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 |
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
|
431 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// Bind 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
|
434 |
OTInitInetAddress(&inAddr, ip->port, 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
|
435 |
inAddr.fAddressType = 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
|
436 |
bindReq.addr.len = sizeof( InetAddress ); |
86984c1034a5
Added 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 |
bindReq.addr.buf = (unsigned char*)&inAddr; |
86984c1034a5
Added 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 |
bindReq.qlen = 35; // This number is NOT well considered. (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
|
439 |
sock->localAddress.host = inAddr.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
|
440 |
sock->localAddress.port = inAddr.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
|
441 |
sock->sflag = 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
|
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 |
sock->error = OTBind( sock->channel, &bindReq, 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
|
444 |
AsyncTCPPopEvent(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
|
445 |
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
|
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 |
AsyncTCPPopEvent(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
|
448 |
} |
86984c1034a5
Added 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 |
if( sock->error != 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
|
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 |
SDLNet_SetError("Could not bind server 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
|
452 |
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
|
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 |
|
86984c1034a5
Added 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 |
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
|
456 |
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
|
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 |
|
86984c1034a5
Added 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 |
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
|
461 |
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
|
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 |
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
|
464 |
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
|
465 |
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
|
466 |
SDLNet_TCP_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
|
467 |
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
|
468 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Accept an incoming connection on the given server 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 |
The newly created socket is returned, or NULL if there was an 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
|
472 |
*/ |
86984c1034a5
Added 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 |
TCPsocket SDLNet_TCP_Accept(TCPsocket server) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Only server sockets can accept */ |
86984c1034a5
Added 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 |
if ( ! server->sflag ) { |
86984c1034a5
Added 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 |
SDLNet_SetError("Only server sockets can accept()"); |
86984c1034a5
Added 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 |
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
|
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 |
server->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
|
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 |
/* Accept a new TCP connection on a server 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
|
484 |
{ |
86984c1034a5
Added 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 |
InetAddress peer; |
86984c1034a5
Added 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 |
TCall peerinfo; |
86984c1034a5
Added 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 |
TCPsocket 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
|
488 |
Boolean mustListen = 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
|
489 |
OTResult err; |
86984c1034a5
Added 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 |
memset(&peerinfo, 0, (sizeof peerinfo )); |
86984c1034a5
Added 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 |
peerinfo.addr.buf = (Uint8 *) &peer; |
86984c1034a5
Added 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 |
peerinfo.addr.maxlen = sizeof(peer); |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
while( mustListen || !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
|
496 |
{ |
86984c1034a5
Added 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 |
// OTListen |
86984c1034a5
Added 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 |
// We do NOT block ---- right thing ? (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
|
499 |
err = OTListen( server->channel, &peerinfo ); |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
if( err ) |
86984c1034a5
Added 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 |
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
|
503 |
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
|
504 |
{ |
86984c1034a5
Added 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 |
mustListen = 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
|
506 |
sock = AsyncTCPNewSocket(); |
86984c1034a5
Added 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( ! 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 |
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
|
509 |
} |
86984c1034a5
Added 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 |
if( 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
|
512 |
{ |
86984c1034a5
Added 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 |
// 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
|
514 |
server->error = OTAsyncOpenEndpoint( OTCloneConfiguration( server->config ), |
86984c1034a5
Added 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 |
NULL, &(sock->info), (OTNotifyProcPtr)AsyncTCPNotifier, 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
|
516 |
AsyncTCPPopEvent( 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
|
517 |
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
|
518 |
{ |
86984c1034a5
Added 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 |
AsyncTCPPopEvent( 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
|
520 |
} |
86984c1034a5
Added 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 |
if( ! 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
|
522 |
{ |
86984c1034a5
Added 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 |
mustListen = 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
|
524 |
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
|
525 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
// OTAccept |
86984c1034a5
Added 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 |
server->completion &= ~(CompleteMask(T_ACCEPTCOMPLETE)); |
86984c1034a5
Added 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 |
server->error = OTAccept( server->channel, sock->channel, &peerinfo ); |
86984c1034a5
Added 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 |
AsyncTCPPopEvent( server ); |
86984c1034a5
Added 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 |
while( !(server->completion & CompleteMask(T_ACCEPTCOMPLETE))) |
86984c1034a5
Added 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 |
AsyncTCPPopEvent( server ); |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
switch( server->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
|
537 |
{ |
86984c1034a5
Added 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 |
case kOTLookErr: |
86984c1034a5
Added 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 |
switch( OTLook(server->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
|
540 |
{ |
86984c1034a5
Added 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 |
case T_LISTEN: |
86984c1034a5
Added 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 |
mustListen = 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
|
543 |
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
|
544 |
case 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
|
545 |
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
|
546 |
} |
86984c1034a5
Added 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 |
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
|
548 |
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
|
549 |
sock->nextListener = server->nextListener; |
86984c1034a5
Added 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 |
server->nextListener = 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
|
551 |
sock->remoteAddress.host = peer.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
|
552 |
sock->remoteAddress.port = peer.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
|
553 |
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
|
554 |
// accept successful |
86984c1034a5
Added 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 |
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
|
556 |
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
|
557 |
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
|
558 |
} |
86984c1034a5
Added 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 |
sock->remoteAddress.host = peer.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
|
561 |
sock->remoteAddress.port = peer.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
|
562 |
sock->sflag = 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
|
563 |
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
|
564 |
|
86984c1034a5
Added 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 |
/* 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
|
566 |
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
|
567 |
|
86984c1034a5
Added 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 |
// Error; close the socket and 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
|
569 |
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
|
570 |
SDLNet_TCP_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
|
571 |
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
|
572 |
} |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Get the IP address of the remote system associated 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
|
576 |
If the socket is a server socket, 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
|
577 |
*/ |
86984c1034a5
Added 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 |
IPaddress *SDLNet_TCP_GetPeerAddress(TCPsocket 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
|
579 |
{ |
86984c1034a5
Added 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 |
if ( sock->sflag ) { |
86984c1034a5
Added 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 |
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
|
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 |
return(&sock->remoteAddress); |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Send 'len' bytes of 'data' over the non-server 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
|
587 |
This function returns the actual amount of data sent. If the return value |
86984c1034a5
Added 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 |
is less than the amount of data sent, then either the remote connection was |
86984c1034a5
Added 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 |
closed, or an unknown socket error occurred. |
86984c1034a5
Added 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 |
*/ |
86984c1034a5
Added 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 |
int SDLNet_TCP_Send(TCPsocket sock, const void *datap, int 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
|
592 |
{ |
86984c1034a5
Added 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 |
const Uint8 *data = (const Uint8 *)datap; /* For pointer arithmetic */ |
86984c1034a5
Added 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 |
int sent, left; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Server sockets are for accepting connections only */ |
86984c1034a5
Added 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 |
if ( sock->sflag ) { |
86984c1034a5
Added 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 |
SDLNet_SetError("Server sockets cannot send"); |
86984c1034a5
Added 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 |
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
|
600 |
} |
86984c1034a5
Added 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 |
/* Keep sending data until it's sent or an error occurs */ |
86984c1034a5
Added 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 |
left = 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
|
604 |
sent = 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
|
605 |
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
|
606 |
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
|
607 |
len = OTSnd(sock->channel, (void *)data, left, 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
|
608 |
if (len == kOTFlowErr) |
86984c1034a5
Added 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 |
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
|
610 |
if ( 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
|
611 |
sent += 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
|
612 |
left -= 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
|
613 |
data += 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
|
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 |
// 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
|
616 |
// ( 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
|
617 |
// (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
|
618 |
//WaitNextEvent(everyEvent, &macEvent, 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
|
619 |
//AsyncTCPPopEvent(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
|
620 |
} while ( (left > 0) && (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
|
621 |
|
86984c1034a5
Added 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 |
return(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
|
623 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Receive up to 'maxlen' bytes of data over the non-server 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
|
626 |
and store them in the buffer pointed to by '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
|
627 |
This function returns the actual amount of data received. If the 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
|
628 |
value is less than or equal to zero, then either the remote connection was |
86984c1034a5
Added 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 |
closed, or an unknown socket error occurred. |
86984c1034a5
Added 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 |
*/ |
86984c1034a5
Added 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 |
int SDLNet_TCP_Recv(TCPsocket sock, void *data, int 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
|
632 |
{ |
86984c1034a5
Added 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 |
int 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
|
634 |
OSStatus res; |
86984c1034a5
Added 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 |
/* Server sockets are for accepting connections only */ |
86984c1034a5
Added 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 |
if ( sock->sflag ) { |
86984c1034a5
Added 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 |
SDLNet_SetError("Server sockets cannot receive"); |
86984c1034a5
Added 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 |
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
|
639 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
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
|
642 |
{ |
86984c1034a5
Added 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 |
res = OTRcv(sock->channel, data, maxlen-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
|
644 |
if (res > 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
|
645 |
len = res; |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
#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
|
649 |
if ( res != kOTNoDataErr ) |
86984c1034a5
Added 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 |
printf("SDLNet_TCP_Recv received ; %d\n", res ); |
86984c1034a5
Added 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 |
#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
|
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 |
AsyncTCPPopEvent(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
|
654 |
if( res == kOTLookErr ) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
res = OTLook(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
|
657 |
continue; |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 ( (len == 0) && (res == kOTNoDataErr) ); |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
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
|
662 |
if ( len == 0 ) { /* Open Transport 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
|
663 |
#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
|
664 |
printf("Open Transport error: %d\n", res); |
86984c1034a5
Added 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 |
#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
|
666 |
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
|
667 |
} |
86984c1034a5
Added 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 |
return(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
|
669 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Close a TCP 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
|
672 |
void SDLNet_TCP_Close(TCPsocket 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
|
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 |
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
|
675 |
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
|
676 |
//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
|
677 |
OTSndOrderlyDisconnect( 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
|
678 |
} |
86984c1034a5
Added 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 |
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
|
680 |
} |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
#else /* !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
|
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 |
struct _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
|
686 |
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
|
687 |
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
|
688 |
IPaddress remoteAddress; |
86984c1034a5
Added 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 |
IPaddress localAddress; |
86984c1034a5
Added 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 |
int sflag; |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Open a TCP 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
|
694 |
If 'remote' is NULL, this creates a local server socket on the given 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
|
695 |
otherwise a TCP connection to the remote host and port is attempted. |
86984c1034a5
Added 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 |
The newly created socket is returned, or NULL if there was an 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
|
697 |
*/ |
86984c1034a5
Added 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 |
TCPsocket SDLNet_TCP_Open(IPaddress *ip) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
TCPsocket 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
|
701 |
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
|
702 |
|
86984c1034a5
Added 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 |
/* Allocate a TCP 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
|
704 |
sock = (TCPsocket)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
|
705 |
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
|
706 |
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
|
707 |
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
|
708 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* 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
|
711 |
sock->channel = socket(AF_INET, SOCK_STREAM, 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
|
712 |
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
|
713 |
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
|
714 |
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
|
715 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Connect to remote, or bind locally, as 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
|
718 |
if ( (ip->host != INADDR_NONE) && (ip->host != 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
|
719 |
|
86984c1034a5
Added 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 |
// ######### Connecting to remote |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
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
|
723 |
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
|
724 |
sock_addr.sin_addr.s_addr = ip->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
|
725 |
sock_addr.sin_port = ip->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
|
726 |
|
86984c1034a5
Added 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 |
/* Connect to the remote 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
|
728 |
if ( connect(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
|
729 |
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
|
730 |
SDLNet_SetError("Couldn't connect to remote 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
|
731 |
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
|
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 |
sock->sflag = 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
|
734 |
} 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
|
735 |
|
86984c1034a5
Added 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 |
// ########## Binding locally |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
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
|
739 |
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
|
740 |
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
|
741 |
sock_addr.sin_port = ip->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
|
742 |
|
86984c1034a5
Added 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 |
/* |
86984c1034a5
Added 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 |
* Windows gets bad mojo with SO_REUSEADDR: |
86984c1034a5
Added 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 |
* http://www.devolution.com/pipermail/sdl/2005-September/070491.html |
86984c1034a5
Added 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 |
* --ryan. |
86984c1034a5
Added 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 |
*/ |
86984c1034a5
Added 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 |
#ifndef WIN32 |
86984c1034a5
Added 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 |
/* allow local address reuse */ |
86984c1034a5
Added 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 |
{ 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
|
751 |
setsockopt(sock->channel, SOL_SOCKET, SO_REUSEADDR, (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
|
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 |
#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
|
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 |
/* 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
|
756 |
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
|
757 |
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
|
758 |
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
|
759 |
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
|
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 |
if ( listen(sock->channel, 5) == 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
|
762 |
SDLNet_SetError("Couldn't listen 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
|
763 |
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
|
764 |
} |
86984c1034a5
Added 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 |
|
86984c1034a5
Added 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 |
/* Set the socket to non-blocking mode for accept() */ |
86984c1034a5
Added 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 |
#if defined(__BEOS__) && defined(SO_NONBLOCK) |
86984c1034a5
Added 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 |
/* On BeOS r5 there is O_NONBLOCK but it's for files only */ |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
long b = 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
|
771 |
setsockopt(sock->channel, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); |
86984c1034a5
Added 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 |
#elif defined(O_NONBLOCK) |
86984c1034a5
Added 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 |
{ |
86984c1034a5
Added 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 |
fcntl(sock->channel, F_SETFL, O_NONBLOCK); |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
#elif defined(WIN32) |
86984c1034a5
Added 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 |
unsigned long mode = 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
|
780 |
ioctlsocket (sock->channel, FIONBIO, &mode); |
86984c1034a5
Added 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 |
#elif defined(__OS2__) |
86984c1034a5
Added 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 |
int dontblock = 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
|
785 |
ioctl(sock->channel, FIONBIO, &dontblock); |
86984c1034a5
Added 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 |
} |
86984c1034a5
Added 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 |
#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
|
788 |
#warning How do we set non-blocking mode on other operating systems? |
86984c1034a5
Added 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 |
#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
|
790 |
sock->sflag = 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
|
791 |
} |
86984c1034a5
Added 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 |
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
|
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 |
#ifdef TCP_NODELAY |
86984c1034a5
Added 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 |
/* Set the nodelay TCP option for real-time games */ |
86984c1034a5
Added 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 |
{ 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
|
797 |
setsockopt(sock->channel, IPPROTO_TCP, TCP_NODELAY, (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
|
798 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
799 |
#endif /* TCP_NODELAY */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
800 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
801 |
/* 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
|
802 |
sock->remoteAddress.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
|
803 |
sock->remoteAddress.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
|
804 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
805 |
/* 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
|
806 |
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
|
807 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
808 |
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
|
809 |
SDLNet_TCP_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
|
810 |
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
|
811 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
812 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
813 |
/* Accept an incoming connection on the given server 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
|
814 |
The newly created socket is returned, or NULL if there was an 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
|
815 |
*/ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
816 |
TCPsocket SDLNet_TCP_Accept(TCPsocket server) |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
817 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
818 |
TCPsocket 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
|
819 |
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
|
820 |
int sock_alen; |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
821 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
822 |
/* Only server sockets can accept */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
823 |
if ( ! server->sflag ) { |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
824 |
SDLNet_SetError("Only server sockets can accept()"); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
825 |
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
|
826 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
827 |
server->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
|
828 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
829 |
/* Allocate a TCP 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
|
830 |
sock = (TCPsocket)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
|
831 |
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
|
832 |
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
|
833 |
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
|
834 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
835 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
836 |
/* Accept a new TCP connection on a server 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
|
837 |
sock_alen = 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
|
838 |
sock->channel = accept(server->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
|
839 |
#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
|
840 |
(unsigned int *)&sock_alen); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
841 |
#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
|
842 |
&sock_alen); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
843 |
#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
|
844 |
if ( sock->channel == 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
|
845 |
SDLNet_SetError("accept() 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
|
846 |
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
|
847 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
848 |
#ifdef WIN32 |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
849 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
850 |
/* passing a zero value, socket mode set to block on */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
851 |
unsigned long mode = 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
|
852 |
ioctlsocket (sock->channel, FIONBIO, &mode); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
853 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
854 |
#elif defined(O_NONBLOCK) |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
855 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
856 |
int flags = fcntl(sock->channel, F_GETFL, 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
|
857 |
fcntl(sock->channel, F_SETFL, flags & ~O_NONBLOCK); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
858 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
859 |
#endif /* WIN32 */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
860 |
sock->remoteAddress.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
|
861 |
sock->remoteAddress.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
|
862 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
863 |
sock->sflag = 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
|
864 |
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
|
865 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
866 |
/* 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
|
867 |
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
|
868 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
869 |
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
|
870 |
SDLNet_TCP_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
|
871 |
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
|
872 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
873 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
874 |
/* Get the IP address of the remote system associated 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
|
875 |
If the socket is a server socket, 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
|
876 |
*/ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
877 |
IPaddress *SDLNet_TCP_GetPeerAddress(TCPsocket 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
|
878 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
879 |
if ( sock->sflag ) { |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
880 |
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
|
881 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
882 |
return(&sock->remoteAddress); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
883 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
884 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
885 |
/* Send 'len' bytes of 'data' over the non-server 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
|
886 |
This function returns the actual amount of data sent. If the return value |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
887 |
is less than the amount of data sent, then either the remote connection was |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
888 |
closed, or an unknown socket error occurred. |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
889 |
*/ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
890 |
int SDLNet_TCP_Send(TCPsocket sock, const void *datap, int 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
|
891 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
892 |
const Uint8 *data = (const Uint8 *)datap; /* For pointer arithmetic */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
893 |
int sent, left; |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
894 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
895 |
/* Server sockets are for accepting connections only */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
896 |
if ( sock->sflag ) { |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
897 |
SDLNet_SetError("Server sockets cannot send"); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
898 |
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
|
899 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
900 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
901 |
/* Keep sending data until it's sent or an error occurs */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
902 |
left = 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
|
903 |
sent = 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
|
904 |
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
|
905 |
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
|
906 |
len = send(sock->channel, (const char *) data, left, 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
|
907 |
if ( 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
|
908 |
sent += 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
|
909 |
left -= 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
|
910 |
data += 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
|
911 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
912 |
} while ( (left > 0) && ((len > 0) || (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
|
913 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
914 |
return(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
|
915 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
916 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
917 |
/* Receive up to 'maxlen' bytes of data over the non-server 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
|
918 |
and store them in the buffer pointed to by '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
|
919 |
This function returns the actual amount of data received. If the 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
|
920 |
value is less than or equal to zero, then either the remote connection was |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
921 |
closed, or an unknown socket error occurred. |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
922 |
*/ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
923 |
int SDLNet_TCP_Recv(TCPsocket sock, void *data, int 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
|
924 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
925 |
int 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
|
926 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
927 |
/* Server sockets are for accepting connections only */ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
928 |
if ( sock->sflag ) { |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
929 |
SDLNet_SetError("Server sockets cannot receive"); |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
930 |
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
|
931 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
932 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
933 |
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
|
934 |
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
|
935 |
len = recv(sock->channel, (char *) data, 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
|
936 |
} 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
|
937 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
938 |
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
|
939 |
return(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
|
940 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
941 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
942 |
/* Close a TCP 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
|
943 |
void SDLNet_TCP_Close(TCPsocket 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
|
944 |
{ |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
945 |
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
|
946 |
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
|
947 |
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
|
948 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
949 |
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
|
950 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
951 |
} |
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
952 |
|
86984c1034a5
Added sdl_net from the unofficial android port: http://www.anddev.org/sdl_port_for_android_sdk-ndk_16-t9218.html
Xeli
parents:
diff
changeset
|
953 |
#endif /* MACOS_OPENTRANSPORT */ |