- JGE bug fixes (network)
- increased the size of kernel ram. 2048 might bee too much though, let's see if we can go with 1024
This commit is contained in:
wagic.the.homebrew@gmail.com
2009-11-29 04:44:38 +00:00
parent 3f21dad546
commit b275b6f758
5 changed files with 268 additions and 239 deletions

View File

@@ -1,10 +1,7 @@
#ifndef _JNETWORK_H_ #ifndef _JNETWORK_H_
#define _JNETWORK_H_ #define _JNETWORK_H_
#ifdef WIN32
#elif defined (LINUX)
#else
#endif
#include "JGE.h" #include "JGE.h"
#include <string> #include <string>
@@ -14,7 +11,9 @@ class JNetwork{
private: private:
static JNetwork * mInstance; static JNetwork * mInstance;
static int connected_to_ap; static int connected_to_ap;
public: public:
static string error;
JNetwork(); JNetwork();
static JNetwork * GetInstance(); static JNetwork * GetInstance();
static void EndInstance(); static void EndInstance();
@@ -28,7 +27,6 @@ public:
#elif defined (LINUX) #elif defined (LINUX)
static void* net_thread(void* param); static void* net_thread(void* param);
#else #else
static int net_thread(SceSize args, void *argp);
static int connect_to_apctl(int config); static int connect_to_apctl(int config);
#endif #endif
@@ -39,9 +37,15 @@ private:
#elif defined (LINUX) #elif defined (LINUX)
static pthread_t netthread; static pthread_t netthread;
#else #else
static int netthread; static int netthread;
#endif #endif
}; };
#if defined (WIN32)
#elif defined (LINUX)
#else
static int net_thread(SceSize args, void *argp);
#endif
#endif #endif

View File

@@ -4,6 +4,7 @@
*/ */
#if defined (WIN32) || defined (LINUX) #if defined (WIN32) || defined (LINUX)
#else #else
#include <pspkernel.h> #include <pspkernel.h>
@@ -12,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <psputility.h>
#include <pspnet.h> #include <pspnet.h>
#include <pspnet_inet.h> #include <pspnet_inet.h>
#include <pspnet_apctl.h> #include <pspnet_apctl.h>
@@ -22,11 +24,13 @@
#include <errno.h> #include <errno.h>
#endif #endif
#include "../include/JNetwork.h" #include "../include/JNetwork.h"
#include "../include/JSocket.h" #include "../include/JSocket.h"
JNetwork* JNetwork::mInstance = NULL; JNetwork* JNetwork::mInstance = NULL;
string JNetwork::serverIP = ""; string JNetwork::serverIP = "";
string JNetwork::error = "";
JNetwork * JNetwork::GetInstance(){ JNetwork * JNetwork::GetInstance(){
if (!mInstance) mInstance = new JNetwork(); if (!mInstance) mInstance = new JNetwork();
@@ -157,9 +161,17 @@ int net_thread(SceSize args, void *argp)
int JNetwork::connect(string serverIP){ int JNetwork::connect(string serverIP){
int err; int err;
char buffer[4096];
if(netthread) return 0; if(netthread) return 0;
sceUtilityLoadNetModule(1);
sceUtilityLoadNetModule(3);
if((err = pspSdkInetInit())){ if((err = pspSdkInetInit())){
printf("JGE Error, could not initialise the network %08X\n", err); sprintf(buffer, "JGE Error, could not initialise the network %08X", err);
printf(buffer); printf("\n");
error = buffer;
return err; return err;
} }
@@ -187,28 +199,37 @@ int JNetwork::connect_to_apctl(int config)
{ {
int err; int err;
int stateLast = -1; int stateLast = -1;
char buffer[4096];
/* Connect using the first profile */ /* Connect using the first profile */
err = sceNetApctlConnect(config); err = sceNetApctlConnect(config);
if (err != 0) if (err != 0)
{ {
printf("JGE: sceNetApctlConnect returns %08X\n", err); sprintf(buffer, "JGE: sceNetApctlConnect returns %08X", err);
printf(buffer);printf("\n");
error = buffer;
return 0; return 0;
} }
printf("JGE: Connecting...\n"); sprintf(buffer,"JGE: Connecting...");
printf(buffer);printf("\n");
error = buffer;
while (1) while (1)
{ {
int state; int state;
err = sceNetApctlGetState(&state); err = sceNetApctlGetState(&state);
if (err != 0) if (err != 0)
{ {
printf("JGE: sceNetApctlGetState returns $%x\n", err); sprintf(buffer,"JGE: sceNetApctlGetState returns $%x", err);
printf(buffer);printf("\n");
error = buffer;
break; break;
} }
if (state > stateLast) if (state > stateLast)
{ {
printf(" connection state %d of 4\n", state); sprintf(buffer, " connection state %d of 4", state);
printf(buffer);printf("\n");
error = buffer;
stateLast = state; stateLast = state;
} }
if (state == 4){ if (state == 4){

View File

@@ -22,6 +22,8 @@ JSocket * JSocket::mInstance = NULL;
#define SERVER_PORT 20666 #define SERVER_PORT 20666
int JSocket::connected = 0;
void JSocket::init(){ void JSocket::init(){
sceUtilityLoadNetModule(1); sceUtilityLoadNetModule(1);
sceUtilityLoadNetModule(3); sceUtilityLoadNetModule(3);
@@ -119,6 +121,8 @@ int JSocket::start_client(const char *szIpAddr){
return err; return err;
} }
connected = 1;
while(1){ while(1){
readWrite(sock); readWrite(sock);
} }

View File

@@ -29,7 +29,7 @@
#ifdef DEVHOOK #ifdef DEVHOOK
PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1); PSP_MODULE_INFO(JGEApp_Title, 0, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER); PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(-256); PSP_HEAP_SIZE_KB(-2048);
#else #else

View File

@@ -1,230 +1,230 @@
#pragma comment(lib,"WSOCK32.LIB") #pragma comment(lib,"WSOCK32.LIB")
#include <stdio.h> #include <stdio.h>
#include <conio.h> #include <conio.h>
#include <winsock.h> #include <winsock.h>
#include <errno.h> #include <errno.h>
#include <winsock.h> #include <winsock.h>
#include "../../include/JSocket.h" #include "../../include/JSocket.h"
JSocket * JSocket::mInstance = NULL; JSocket * JSocket::mInstance = NULL;
#define SERVER_PORT 20666 #define SERVER_PORT 20666
unsigned char ADRESSE_IP_SERVEUR [4] = {127,0,0,1}; unsigned char ADRESSE_IP_SERVEUR [4] = {127,0,0,1};
int JSocket::connected = 0; int JSocket::connected = 0;
void JSocket::init(){ void JSocket::init(){
//TODO ? //TODO ?
} }
JSocket::JSocket(){ JSocket::JSocket(){
init(); init();
} }
JSocket::~JSocket(){ JSocket::~JSocket(){
//TODO ? //TODO ?
} }
void JSocket::readWrite(int val){ void JSocket::readWrite(int val){
char data[1024]; char data[1024];
fd_set set; fd_set set;
FD_ZERO(&set); FD_ZERO(&set);
FD_SET(val, &set); FD_SET(val, &set);
struct timeval tv; struct timeval tv;
int result = select(0, &set, NULL, NULL, &tv); int result = select(0, &set, NULL, NULL, &tv);
if( result< 0) if( result< 0)
{ {
printf("Socket %d closed\n", val); printf("Socket %d closed\n", val);
closesocket(val); closesocket(val);
connected= 0; connected= 0;
printf("select error\n"); printf("select error\n");
return; return;
} }
if (result > 0){ if (result > 0){
OutputDebugString("Receiving!\n"); OutputDebugString("Receiving!\n");
int readbytes = recv(val, data, sizeof(data),0); int readbytes = recv(val, data, sizeof(data),0);
if(readbytes < 0) if(readbytes < 0)
{ {
int error = WSAGetLastError(); int error = WSAGetLastError();
if (error != WSAEWOULDBLOCK){ if (error != WSAEWOULDBLOCK){
printf("Socket %d closed\n", val); printf("Socket %d closed\n", val);
closesocket(val); closesocket(val);
connected= 0; connected= 0;
} }
} }
else else
{ {
OutputDebugString("received Data!!!\n"); OutputDebugString("received Data!!!\n");
for (int i = 0; i < readbytes; i++){ for (int i = 0; i < readbytes; i++){
received_data.push(data[i]); received_data.push(data[i]);
OutputDebugString("getting byte\n"); OutputDebugString("getting byte\n");
} }
} }
} }
//Write //Write
int size = 0; int size = 0;
while(!tosend_data.empty()){ while(!tosend_data.empty()){
size++; size++;
if (size > sizeof(data)){ if (size > sizeof(data)){
send(val,data,sizeof(data),0); send(val,data,sizeof(data),0);
size = 0; size = 0;
} }
data[size-1] = tosend_data.front(); data[size-1] = tosend_data.front();
tosend_data.pop(); tosend_data.pop();
} }
if (size) { if (size) {
send(val,data,size-1,0); send(val,data,size-1,0);
OutputDebugString("sending Data\n"); OutputDebugString("sending Data\n");
} }
} }
/* Start a client */ /* Start a client */
int JSocket::start_client(const char *szIpAddr){ int JSocket::start_client(const char *szIpAddr){
SOCKET Desc_Socket_Cliente; SOCKET Desc_Socket_Cliente;
SOCKADDR_IN Adresse_Socket_Serveur; SOCKADDR_IN Adresse_Socket_Serveur;
WORD wVersionRequested; WORD wVersionRequested;
WSADATA wsaData; WSADATA wsaData;
struct hostent *hostentptr; struct hostent *hostentptr;
wVersionRequested=MAKEWORD(1,1); wVersionRequested=MAKEWORD(1,1);
WSAStartup(wVersionRequested,&wsaData); WSAStartup(wVersionRequested,&wsaData);
Desc_Socket_Cliente=socket(AF_INET,SOCK_STREAM,0); Desc_Socket_Cliente=socket(AF_INET,SOCK_STREAM,0);
unsigned int addr_dest = inet_addr(szIpAddr); unsigned int addr_dest = inet_addr(szIpAddr);
hostentptr=gethostbyaddr((char*) &addr_dest,4,AF_INET); hostentptr=gethostbyaddr((char*) &addr_dest,4,AF_INET);
ZeroMemory(&Adresse_Socket_Serveur,sizeof(Adresse_Socket_Serveur)); ZeroMemory(&Adresse_Socket_Serveur,sizeof(Adresse_Socket_Serveur));
Adresse_Socket_Serveur.sin_family=(*hostentptr).h_addrtype; Adresse_Socket_Serveur.sin_family=(*hostentptr).h_addrtype;
Adresse_Socket_Serveur.sin_port=htons(SERVER_PORT); Adresse_Socket_Serveur.sin_port=htons(SERVER_PORT);
Adresse_Socket_Serveur.sin_addr=*((struct in_addr*)(*hostentptr).h_addr); Adresse_Socket_Serveur.sin_addr=*((struct in_addr*)(*hostentptr).h_addr);
int result = connect( int result = connect(
Desc_Socket_Cliente, Desc_Socket_Cliente,
(const struct sockaddr*)&Adresse_Socket_Serveur, (const struct sockaddr*)&Adresse_Socket_Serveur,
sizeof(Adresse_Socket_Serveur)); sizeof(Adresse_Socket_Serveur));
OutputDebugString("client state 0\n"); OutputDebugString("client state 0\n");
if (result != 0){ if (result != 0){
connected = 0; connected = 0;
return 0; return 0;
} }
OutputDebugString("client state 1\n"); OutputDebugString("client state 1\n");
connected = 1; connected = 1;
while(1){ while(1){
readWrite(Desc_Socket_Cliente); readWrite(Desc_Socket_Cliente);
/* Nb_Caracteres_Recus=recv(Desc_Socket_Cliente,Message_Recu,sizeof(Message_Recu),0); /* Nb_Caracteres_Recus=recv(Desc_Socket_Cliente,Message_Recu,sizeof(Message_Recu),0);
if(Nb_Caracteres_Recus<=0){ if(Nb_Caracteres_Recus<=0){
//continuer=FALSE; //continuer=FALSE;
}else{ }else{
strcpy(message,Message_Recu); strcpy(message,Message_Recu);
len=strlen(message); len=strlen(message);
} }
*/ */
} }
# #
closesocket(Desc_Socket_Cliente); closesocket(Desc_Socket_Cliente);
WSACleanup(); WSACleanup();
return 0; return 0;
} }
/* Start a server */ /* Start a server */
int JSocket::start_server(const char *szIpAddr){ int JSocket::start_server(const char *szIpAddr){
OutputDebugString("server state 0\n"); OutputDebugString("server state 0\n");
connected= 0; connected= 0;
int Code_Retour; int Code_Retour;
SOCKET Desc_Socket_Connection; SOCKET Desc_Socket_Connection;
SOCKADDR_IN Adresse_Socket_Connection; SOCKADDR_IN Adresse_Socket_Connection;
WORD wVersionRequested; WORD wVersionRequested;
WSADATA wsaData; WSADATA wsaData;
wVersionRequested=MAKEWORD(1,1); wVersionRequested=MAKEWORD(1,1);
Code_Retour=WSAStartup(wVersionRequested,&wsaData); Code_Retour=WSAStartup(wVersionRequested,&wsaData);
if(Code_Retour!=0){ if(Code_Retour!=0){
perror("WSAStartup\t"); perror("WSAStartup\t");
_getch(); _getch();
WSACleanup(); WSACleanup();
return Code_Retour; return Code_Retour;
} }
OutputDebugString("server state 1\n"); OutputDebugString("server state 1\n");
/* printf("la version supportee est : %d.%d\n", /* printf("la version supportee est : %d.%d\n",
LOBYTE(wsaData.wHighVersion), LOBYTE(wsaData.wHighVersion),
HIBYTE(wsaData.wHighVersion) HIBYTE(wsaData.wHighVersion)
);*/ );*/
Desc_Socket_Connection=socket( AF_INET, SOCK_STREAM,0); Desc_Socket_Connection=socket( AF_INET, SOCK_STREAM,0);
//printf("valeur de la socket = %d\n",Desc_Socket_Connection); //printf("valeur de la socket = %d\n",Desc_Socket_Connection);
ZeroMemory(&Adresse_Socket_Connection,sizeof(Adresse_Socket_Connection)); ZeroMemory(&Adresse_Socket_Connection,sizeof(Adresse_Socket_Connection));
Adresse_Socket_Connection.sin_family=AF_INET; Adresse_Socket_Connection.sin_family=AF_INET;
Adresse_Socket_Connection.sin_port=htons(SERVER_PORT); Adresse_Socket_Connection.sin_port=htons(SERVER_PORT);
Code_Retour=bind(Desc_Socket_Connection, Code_Retour=bind(Desc_Socket_Connection,
(struct sockaddr*)&Adresse_Socket_Connection, (struct sockaddr*)&Adresse_Socket_Connection,
sizeof(Adresse_Socket_Connection)); sizeof(Adresse_Socket_Connection));
if(Code_Retour!=0){ if(Code_Retour!=0){
perror("bind\t"); perror("bind\t");
_getch(); _getch();
closesocket(Desc_Socket_Connection); closesocket(Desc_Socket_Connection);
WSACleanup(); WSACleanup();
return Code_Retour; return Code_Retour;
} }
OutputDebugString("server state 3\n"); OutputDebugString("server state 3\n");
Code_Retour=listen(Desc_Socket_Connection,1); Code_Retour=listen(Desc_Socket_Connection,1);
if(Code_Retour!=0){ if(Code_Retour!=0){
perror("listen\n"); perror("listen\n");
WSACleanup(); WSACleanup();
return Code_Retour; return Code_Retour;
} }
OutputDebugString("server state 4\n"); OutputDebugString("server state 4\n");
printf("serveur en attente d'une connection\n\n"); printf("serveur en attente d'une connection\n\n");
printf("***************arret du serveur par<CTRL><C>**************\n\n"); printf("***************arret du serveur par<CTRL><C>**************\n\n");
connected = 1; connected = 1;
while(1){ while(1){
SOCKET * pt_Nouveau_Socket_Serveur; SOCKET * pt_Nouveau_Socket_Serveur;
SOCKADDR_IN Adresse_Socket_Cliente; SOCKADDR_IN Adresse_Socket_Cliente;
int Longueur_Adresse; int Longueur_Adresse;
pt_Nouveau_Socket_Serveur = new SOCKET; pt_Nouveau_Socket_Serveur = new SOCKET;
Longueur_Adresse = sizeof(Adresse_Socket_Cliente); Longueur_Adresse = sizeof(Adresse_Socket_Cliente);
int val=accept( int val=accept(
Desc_Socket_Connection, Desc_Socket_Connection,
(struct sockaddr*)&Adresse_Socket_Cliente, (struct sockaddr*)&Adresse_Socket_Cliente,
&Longueur_Adresse); &Longueur_Adresse);
printf("connection accepte depuis le port client %d\n", ntohs(Adresse_Socket_Cliente.sin_port)); printf("connection accepte depuis le port client %d\n", ntohs(Adresse_Socket_Cliente.sin_port));
OutputDebugString("connection accepte depuis le port client\n"); OutputDebugString("connection accepte depuis le port client\n");
while(1) while(1)
{ {
readWrite(val); readWrite(val);
} }
closesocket(*pt_Nouveau_Socket_Serveur); closesocket(*pt_Nouveau_Socket_Serveur);
return 0; return 0;
} }
} }