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 

Async Functions in SDK HELP

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



Joined: 24 Mar 2008
Posts: 25

PostPosted: Sun Oct 26, 2008 5:01 pm    Post subject: Async Functions in SDK HELP Reply with quote

Hey all,
would some one be able to give an example of the sceIoReadAsync() function from the sdk. I have been looking all over the forums and even in PPA source code. But i can't seem to get it to work.

Regards
Homemister
Back to top
View user's profile Send private message
Onii



Joined: 05 Oct 2008
Posts: 40

PostPosted: Sun Oct 26, 2008 5:30 pm    Post subject: Reply with quote

First, a disclaimer, I haven't played with async io, just relaying what I found in the docs with the hope that it'll help.

If I understand the docs correctly, first you register a callback with sceIoSetAsyncCallback(), then you call sceIoReadAsync() which will return immediately, and when it has done its work will fire your callback.

OR

Call sceIoReadAsync() and at a later time you can call sceIoPollAsync() to see if it's done and/or call sceIoWaitAsync() to wait for it to complete.
Back to top
View user's profile Send private message
homemister



Joined: 24 Mar 2008
Posts: 25

PostPosted: Sun Oct 26, 2008 6:49 pm    Post subject: Reply with quote

Thx,
Got it working now.
Code:
int main(void)
{
   SetupCallbacks();
   pspDebugScreenInit();
   printf("ms0:/test.txt\n");
   SceUID fd = sceIoOpen("ms0:/test.txt", PSP_O_RDONLY, 0777);
   char data[256];
   sceIoChangeAsyncPriority(fd, 0x10);
   sceIoReadAsync(fd, data, 100);
   SceInt64 res;
   sceIoWaitAsync(fd, &res);
   sceIoClose(fd);
   printf(data);
   printf("\nDONE");
   return 0;
}
Back to top
View user's profile Send private message
Onii



Joined: 05 Oct 2008
Posts: 40

PostPosted: Mon Oct 27, 2008 2:18 am    Post subject: Reply with quote

I know this is just an example, but I think its worth mentioning (for other readers of the thread) that if you're using it that directly in your actual code you gain no benefit from using the async calls. I'd use the non async equivalents, they're much more direct in usage:

Just sceIoRead(fd, data, 100); and you've got 100 bytes, right away.
Back to top
View user's profile Send private message
homemister



Joined: 24 Mar 2008
Posts: 25

PostPosted: Mon Oct 27, 2008 5:45 pm    Post subject: Reply with quote

but if you are doing lots of reading from the memorystick use the Async.
I am using it for my Mp3 decoder and **Video Loader**. Because i am constantly streaming data from the memory stick.
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