Async Functions in SDK HELP

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
homemister
Posts: 25
Joined: Mon Mar 24, 2008 12:16 pm

Async Functions in SDK HELP

Post by homemister »

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
Onii
Posts: 40
Joined: Sun Oct 05, 2008 1:07 pm

Post by Onii »

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.
homemister
Posts: 25
Joined: Mon Mar 24, 2008 12:16 pm

Post by homemister »

Thx,
Got it working now.

Code: Select all

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;
}
Onii
Posts: 40
Joined: Sun Oct 05, 2008 1:07 pm

Post by Onii »

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.
homemister
Posts: 25
Joined: Mon Mar 24, 2008 12:16 pm

Post by homemister »

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.
Post Reply