Skip to content
This repository has been archived by the owner on Oct 29, 2022. It is now read-only.

Commit

Permalink
Improved connection stability.
Browse files Browse the repository at this point in the history
Improved connection stability.
  • Loading branch information
Rinnegatamante committed Apr 26, 2015
1 parent 69de013 commit 5c1d205
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions source/luaNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ static int lua_download(lua_State *L){
Result ret = httpcOpenContext(&context, (char*)url , 0);
if(ret==0){
httpcBeginRequest(&context);
/*httpcReqStatus loading; <-- Seems to freeze on CIA build
httpcReqStatus loading;
httpcGetRequestState(&context, &loading);
while (loading != 0x7){
while (loading == 0x5){
httpcGetRequestState(&context, &loading);
}*/
}
u32 statuscode=0;
u32 contentsize=0;
httpcGetResponseStatusCode(&context, &statuscode, 0);
Expand Down Expand Up @@ -155,15 +155,17 @@ static int lua_downstring(lua_State *L){
Result ret = httpcOpenContext(&context, (char*)url , 0);
if(ret==0){
httpcBeginRequest(&context);
/*httpcReqStatus loading; <-- Seems to freeze on CIA build
httpcReqStatus loading;
httpcGetRequestState(&context, &loading);
while (loading != 0x7){
while (loading == 0x5){
httpcGetRequestState(&context, &loading);
}*/
}
u32 statuscode=0;
u32 contentsize=0;
httpcGetResponseStatusCode(&context, &statuscode, 0);
if (statuscode != 200) luaL_error(L, "request error");
char text[128];
sprintf(text,"%i",statuscode);
if (statuscode != 200) luaL_error(L, text);
httpcGetDownloadSizeState(&context, NULL, &contentsize);
unsigned char *buffer = (unsigned char*)malloc(contentsize+1);
httpcDownloadData(&context, buffer, contentsize, NULL);
Expand Down Expand Up @@ -232,7 +234,7 @@ static int lua_sendmail(lua_State *L){ //BETA func
httpcBeginRequest(&context);
httpcReqStatus loading;
httpcGetRequestState(&context, &loading);
while (loading != 0x7){
while (loading == 0x5){
httpcGetRequestState(&context, &loading);
}
u32 statuscode=0;
Expand All @@ -249,8 +251,46 @@ static int lua_sendmail(lua_State *L){ //BETA func
return 1;
}

static int lua_initIRDA(lua_State *L){
int argc = lua_gettop(L);
if (argc != 0) return luaL_error(L, "wrong number of arguments");
u32* iru_mem = (u32*)linearAlloc(2048);
IRU_Initialize(iru_mem, 2048);
return 0;
}

static int lua_receive(lua_State *L){
int argc = lua_gettop(L);
if (argc != 0) return luaL_error(L, "wrong number of arguments");
char result[2048];
u32 received_bytes = 0;
while (received_bytes == 0){
IRU_RecvData((u8*)&result, 2048, 0x00, &received_bytes, 1);
}
u32 confirm = 0xDEAD;
IRU_SendData((u8*)confirm, 4, 1);
lua_pushlstring(L,result,received_bytes);
return 1;
}

static int lua_send(lua_State *L){
int argc = lua_gettop(L);
if (argc != 1) return luaL_error(L, "wrong number of arguments");
const char *data = luaL_checkstring(L, 1);
u32 result = 0x0000;
u32 received_bytes;
while (result != 0xDEAD){
IRU_SendData((u8*)data, strlen(data), 1);
IRU_RecvData((u8*)&result, 4, 0x00, &received_bytes, 1);
}
return 0;
}

//Register our Network Functions
static const luaL_Reg Network_functions[] = {
{"initIRDA", lua_initIRDA},
{"recvIRDA", lua_receive},
{"sendIRDA", lua_send},
{"initFTP", lua_initFTP},
{"termFTP", lua_termFTP},
{"updateFTP", lua_checkFTPcommand},
Expand Down

0 comments on commit 5c1d205

Please sign in to comment.