forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

sceHttpSendRequest in exit_callback doesn't work

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
vista200



Joined: 19 Mar 2008
Posts: 13

PostPosted: Mon Jan 26, 2009 1:07 pm    Post subject: sceHttpSendRequest in exit_callback doesn't work Reply with quote

Hi there!

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:
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;
}


Everything works fine here, except the failing download() in the logout():

Code:
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;
}


timestring() gives the date/time in a format like yyyy-MM-dd-hh-mm-ss and saves it into timebuffer. The message_thread checks every five seconds for a file on a server and downloads it.

Code:
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;
}


The download-code... working fine, except in the exit_callback.

I appreciate your help!

Yours sincerely,
vista200
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Mon Jan 26, 2009 5:53 pm    Post subject: Reply with quote

It starts shutting down stuff for kernel reboot when you select Yes in the exit screen. You're only meant to sceKernelExitGame();

I had a similar problem in the past with writing a large file that took a few seconds to complete.

Alternatively, you could not register the exit callback in the beginning. Detect the Home key from a kernel module, and write the file first. Then register the exit callback (If the writing completes fast enough and the user is still holding the Home key, the exit screen will show as soon as the callback is registered, otherwise you'll have to invoke it manually. I do this in Lockdown In-Game, except I find and unregister the game's callback.).
Back to top
View user's profile Send private message
vista200



Joined: 19 Mar 2008
Posts: 13

PostPosted: Mon Jan 26, 2009 9:41 pm    Post subject: Reply with quote

Just a quick thought:

Wouldn't it be possible to register no callbacks at all and if home is pressed to ShowMessageDialog(). This is the same, isn't it? If the user selects "Yes" the PSP will do the logout, terminate the net and unload the modules.

Another question: What about the error? Can anyone reproduce the error? What type of error is it?

Thanks for the help! I'll try ASAP

vista200
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Mon Jan 26, 2009 9:51 pm    Post subject: Reply with quote

vista200 wrote:
Just a quick thought:

Wouldn't it be possible to register no callbacks at all and if home is pressed to ShowMessageDialog(). This is the same, isn't it? If the user selects "Yes" the PSP will do the logout, terminate the net and unload the modules.


Yes you can do that. It didn't strike me, because all official games use the exit callback and I had to use that in Lockdown :)

I guess it would be more efficient to run a kernel module that exports a kernel-user sceCtrlReadBufferPositive and call that from your main module, instead of having a separate thread running in the kernel module just to check the home button.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group