changeset 5976:93a644e6044b draft

(svn r8674) [PSP] -Add: added network code for PSP, based on the work of Turulo -Add: added general header-inclusing for PSP
author truelight <truelight@openttd.org>
date Sun, 11 Feb 2007 13:57:35 +0000
parents 53e2c49cdaca
children 03f33d102c56
files src/network/core/os_abstraction.h src/network/network.cpp src/stdafx.h
diffstat 3 files changed, 59 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/network/core/os_abstraction.h
+++ b/src/network/core/os_abstraction.h
@@ -91,6 +91,29 @@
 	typedef int socklen_t;
 #endif
 
+#if defined(PSP)
+#	include <sys/socket.h>
+#	include <netinet/in.h>
+#	include <arpa/inet.h>
+#	include <pspnet.h>
+#	include <pspnet_inet.h>
+#	include <pspnet_apctl.h>
+#	include <pspnet_resolver.h>
+#	include <errno.h>
+#	include <unistd.h>
+#	include <sys/select.h>
+#	include <sys/time.h>
+#	include <sys/fd_set.h>
+
+#	define TCP_NODELAY 1
+#	define SO_NONBLOCK 0x1009
+#	define SOCKET int
+#	define INVALID_SOCKET -1
+#	define INADDR_NONE 0xffffffff
+#	define closesocket close
+#	define GET_LAST_ERROR() sceNetInetGetErrno()
+#endif /* PSP */
+
 /* OS/2 stuff */
 #if defined(__OS2__)
 #	define SOCKET int
@@ -160,7 +183,7 @@
 #else
 	int nonblocking = 1;
 #endif
-#if defined(__BEOS__) && defined(BEOS_NET_SERVER)
+#if (defined(__BEOS__) && defined(BEOS_NET_SERVER)) || defined(PSP)
 	return setsockopt(d, SOL_SOCKET, SO_NONBLOCK, &nonblocking, sizeof(nonblocking)) == 0;
 #else
 	return ioctlsocket(d, FIONBIO, &nonblocking) == 0;
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -339,6 +339,7 @@
 // Find all IP-aliases for this host
 static void NetworkFindIPs(void)
 {
+#if !defined(PSP)
 	int i;
 
 #if defined(BEOS_NET_SERVER) /* doesn't have neither getifaddrs or net/if.h */
@@ -506,6 +507,7 @@
 	for (i = 0; _broadcast_list[i] != 0; i++) {
 		DEBUG(net, 3, "%d) %s", i, inet_ntoa(*(struct in_addr *)&_broadcast_list[i]));//inet_ntoa(inaddr));
 	}
+#endif /* PSP */
 }
 
 // Resolve a hostname to a inet_addr
@@ -518,14 +520,35 @@
 
 	// If not try to resolve the name
 	if (ip == INADDR_NONE) {
+		struct in_addr addr;
+#if !defined(PSP)
 		struct hostent *he = gethostbyname(hostname);
 		if (he == NULL) {
 			DEBUG(net, 0, "Cannot resolve '%s'", hostname);
-		} else {
-			struct in_addr addr = *(struct in_addr *)he->h_addr_list[0];
-			DEBUG(net, 1, "Resolved '%s' to %s", hostname, inet_ntoa(addr));
-			ip = addr.s_addr;
+			return ip;
+		}
+		addr = *(struct in_addr *)he->h_addr_list[0];
+#else
+		int rid = -1;
+		char buf[1024];
+
+		/* Create a resolver */
+		if (sceNetResolverCreate(&rid, buf, sizeof(buf)) < 0) {
+			DEBUG(net, 0, "[NET] Error connecting resolver");
+			return ip;
 		}
+
+		/* Try to resolve the name */
+		if (sceNetResolverStartNtoA(rid, hostname, &addr, 2, 3) < 0) {
+			DEBUG(net, 0, "[NET] Cannot resolve %s", hostname);
+			sceNetResolverDelete(rid);
+			return ip;
+		}
+		sceNetResolverDelete(rid);
+#endif /* PSP */
+
+		DEBUG(net, 1, "[NET] Resolved %s to %s", hostname, inet_ntoa(addr));
+		ip = addr.s_addr;
 	}
 	return ip;
 }
--- a/src/stdafx.h
+++ b/src/stdafx.h
@@ -37,6 +37,12 @@
 # define strcasecmp stricmp
 #endif
 
+#if defined(PSP)
+# include <psptypes.h>
+# include <pspdebug.h>
+# include <pspthreadman.h>
+#endif /* PSP */
+
 #ifdef __BEOS__
 # include <SupportDefs.h>
 #endif
@@ -81,7 +87,8 @@
 /* PSP can only have 10 file-descriptors open at any given time, but this
  *  switch only limits reads via the Fio system. So keep 2 fds free for things
  *  like saving a game. */
-#define LIMITED_FDS 8
+# define LIMITED_FDS 8
+# define printf pspDebugScreenPrintf
 #endif /* PSP */
 
 /* by default we use [] var arrays */