2009-11-23 8 views
0

나는 웹 페이지를 얻는 것과 같은 오랜 작업을 수행하는 루아 스크립트를 가지고 있으므로 C 코드 핸들은 페이지 작업 비동기를 얻는다. 따라서 다른 작업을 할 수있는 스레드가 자유 롭다. 스크립트가 다시 시작되면 get 페이지 작업이 완료되었는지 확인하십시오. 문제는 스레드가 비동기 대기 후에 작업을 다시 시작할 수 없다는 것입니다. 여기 내 코드는 내가 지금 좀 지저분 죄송async_wait 후에 lua_resume을 할 수 없습니까?


////script: 
function Loginmegaupload_com(hp, user, pass, cookie) 
    setURL(hp, "http://megaupload.com/?c=login") 
    importPost(hp, "login=1&redir=1") 
    addPost(hp, "username", user) 
    addPost(hp, "password", pass) 
    GetPage() 
    if isHeaderContain(hp, "user=") ~= nil then 
     SetFileLink(cookie, GetAllCookie(hp)) 
     return 1 
    else 
     return 0 
    end 
end 
////c code 
int FileSharingService::GetPage(lua_State *ls) 
{ 
    return lua_yield(ls, 0); 
} 

void FileSharingService::AsyncWait(Http_RequestEx *Http, lua_State *LS, boost::asio::deadline_timer* Timer) 
{ 
    if((Http->status_code == Http_RequestEx::ERROR) || (Http->status_code == Http_RequestEx::FISNISHED)) 
    { 
     if(Http->status_code == Http_RequestEx::FISNISHED) 
     { 
      int result = lua_resume(LS, 0); // here I got result == 2 mean error ? 
      if(result == 0)//lua script exit normal, resume success 
      { 
       delete Http; 
       delete Timer; 
      } 
     } 
     else 
      return; 
    } 
    else 
    { 
     Timer->expires_from_now(boost::posix_time::milliseconds(200)); 
     Timer->async_wait(boost::bind(&FileSharingService::AsyncWait, this, Http, LS, Timer)); 
    } 
} 



bool FileSharingService::Login(string URL, string User, string Pass, string &Cookie) 
{ 
    Http_RequestEx *http = new Http_RequestEx; 
    http->url = URL; 
    LuaWarper* Lua = Lua_map[boost::this_thread::get_id()]; //one main luaState per ioservice thread 
    lua_State *thread = lua_newthread(Lua->GetState()); 

    boost::asio::deadline_timer *timer = new boost::asio::deadline_timer(*HClient.ioservice); 

    string functioname = "Login" + GetServicename(URL); 
    if(Lua->isFunctionAvaliable(functioname.c_str()) == false) 
    { 
     throw(FileSharingService::SERVICE_NOT_AVALIABLE); 
    } 
    else 
    { 
     lua_getglobal(thread, functioname.c_str()); 
     lua_pushlightuserdata(thread, http); 
     lua_pushstring(thread, User.c_str()); 
     lua_pushstring(thread, Pass.c_str()); 
     lua_pushlightuserdata(thread, &Cookie); 
     int result = lua_resume(thread, 4); 
     if(result == LUA_YIELD) 
     { 
      HClient.Do(*http, false); 
      AsyncWait(http, thread, timer); 
     } 
     else if(result == 0) 
     { 
      //fisnished at first call 
     } 
     else 
     { 
      //yield error, will handle late 
     } 
    } 
} 

답변

1

죄송 결코이 질문을 마음, 2 잘, ASIO 얻을 페이지 잘 작동도 오류하지만 스크립트 작업을 의미 반환하지 lua_resume 클래스에서 그것을 riped이고, 나는 추적 lua_resume 실패에 대한 응답 선 아래로 : 그것은이 라인은 루아 스레드 상태를 단지에 영향을 줄 수있는 일을하지 않는 0 반환 스크립트의 종료를 의미 예상대로

httpinfo.header.append(buffer, (HeaderEndIndex-buffer+2));

은 그 라인 lua_resume 일을 언급하는 경우 문자열 할당, 거기에 오버플로가 없습니다. 그래서 이상한.

+0

다행입니다. 자신의 답변을 수락하면 다른 사람들이 답을 알 수 있습니다. –

관련 문제