Code: Select all
int capacity = 1024000;
int len = 0;
u8* buffer = (u8*) malloc(capacity);
while (1) {
// read data
int count = sceNetInetRecv(sockListen, (u8*) &buffer[len], capacity - len, 0);
// in blocking mode it has to return something, otherwise it is closed
// (which is the default for HTTP/1.0 connections)
if (count == 0) break;
if (count < 0) {
pspDebugScreenPrintf("read error: %i\n", err);
break;
}
// adjust buffer, if needed
len += count;
if (len + 1024000 > capacity) {
capacity *= 2;
buffer = realloc(buffer, capacity);
if (!buffer) break;
}
}
// now "len" bytes data are in buffer, add a 0 at end for printing and search for header end
if (buffer) {
buffer[len] = 0;
u8* page = strstr((char*) buffer, "\r\n\r\n");
if (page) {
page += 4;
pspDebugScreenPrintf("\n\n%s", page);
SceUID file;
file = sceIoOpen("ms0:/PSP/MUSIC/test.mp3", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
sceIoWrite(file, page, len);
sceIoClose(file);
}
free(buffer);
}
If the MP3 is, say, 8mb, then it will start downloading it and just eventually stop. It slows way down and the WiFi light doesn't blink as much as while it is downloading.
Anyone have any clue why?