I ran into some trouble again when I tried to do something trivial: I try to port a XML-based chat to the PSP. Therefore I need to download the responses at least into the RAM. Everything works great, but when I'm going to "kill" the program with the HOME-Buttons and I answer the question for quitting with yes, the PSP comes to the XMB normally, without having downloaded the given file as set in the exit_callback.
Some debug info gave me the impression of sceHttpSendRequest has failed with an error code of 80431076. All this happens in the exit_callback, even if I put it in a new function or starting a new thread with the given "logout"-function.
Code: Select all
int exit_callback() {
logout();
if (message_thread >= 0) {
logfile_write("Deleting message_thread\n");
sceKernelSuspendThread(message_thread);
sceKernelTerminateDeleteThread(message_thread);
}
if (netinit) {
logfile_write("Terminating Net\n");
netTerm();
}
if (modules) {
logfile_write("Unloading Modules\n");
sceUtilityUnloadNetModule(PSP_NET_MODULE_HTTP);
sceUtilityUnloadNetModule(PSP_NET_MODULE_PARSEHTTP);
sceUtilityUnloadNetModule(PSP_NET_MODULE_PARSEURI);
sceUtilityUnloadNetModule(PSP_NET_MODULE_INET);
sceUtilityUnloadNetModule(PSP_NET_MODULE_COMMON);
}
logfile_write("Exiting (callback)...\n");
sceKernelExitGame();
return 0;
}
Code: Select all
int logout() {
timestring();
sprintf(tempbuffer, "http://www.pspfreak.de/forum/chat/dologout.php?id=%s", id);
sprintf(file, "ms0:/PSP/GAME/flashchat/%s-logout.xml", timebuffer);
sceKernelDelayThread(50000);
sceKernelSuspendThread(message_thread);
sceKernelTerminateDeleteThread(message_thread);
sceKernelDelayThread(50000);
download(tempbuffer, file);
return 0;
}
Code: Select all
int download(char *the_url, char *save_as) {
u64 filesize;
int nbytes;
int templ;
int connection;
int request;
int status;
int err = 0;
if ((err = sceHttpInit(20000)) < 0){
sceHttpEnd();
return err;
} else {
templ = sceHttpCreateTemplate("FCatPSP", 1, 0);
if (templ < 0){
sceHttpDeleteTemplate(templ);
return templ;
} else {
if ((err = sceHttpSetResolveTimeOut(templ, 3000000)) < 0){
return err;
} else {
if ((err = sceHttpSetRecvTimeOut(templ, 60000000)) < 0){
return err;
} else {
if ((err = sceHttpSetSendTimeOut(templ, 60000000)) < 0){
return err;
} else {
connection = sceHttpCreateConnectionWithURL(templ, the_url, 0);
if (connection < 0){
sceHttpDeleteConnection(connection);
return connection;
} else {
request = sceHttpCreateRequestWithURL(connection,PSP_HTTP_METHOD_GET, the_url, 0);
if (request < 0){
sceHttpDeleteRequest(request);
return request;
} else {
if ((err = sceHttpSendRequest(request, NULL, 0)) < 0){
return err;
} else {
sceHttpGetStatusCode(request, &status);
if (status != 200){
return status;
} else {
sceHttpGetContentLength(request,&filesize);
int file;
if((file = sceIoOpen(save_as, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777))) {
while ((nbytes = sceHttpReadData(request, filebuffer, sizeof(filebuffer))) > 0)
{
sceIoWrite(file, filebuffer, nbytes);
}
sceIoClose(file);
sceHttpEnd();
sceHttpDeleteTemplate(templ);
sceHttpDeleteConnection(connection);
sceHttpDeleteRequest(request);
return 0;
}
}
}
}
}
}
}
}
}
}
return 0;
}
I appreciate your help!
Yours sincerely,
vista200