.developing Skylark

git-svn-id: svn://ultimatepp.org/upp/trunk@5148 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-07-08 09:56:18 +00:00
parent d4818f900f
commit f99e584ee9
8 changed files with 34 additions and 39 deletions

View file

@ -53,7 +53,8 @@ void SkylarkApp::RunThread()
accept_mutex.Leave();
break;
}
bool b = request.Timeout(2000).Accept(server);
SKYLARKLOG("Waiting for accept " << Thread::GetCurrentId());
bool b = request.Timeout(60000).Accept(server);
accept_mutex.Leave();
if(quit)
break;
@ -71,8 +72,6 @@ void SkylarkApp::RunThread()
#endif
SKYLARKLOG("Finished " << Thread::GetCurrentId());
}
else
SKYLARKLOG("Waiting " << Thread::GetCurrentId());
}
}
@ -159,23 +158,13 @@ void SkylarkApp::Run()
#if defined(PLATFORM_POSIX) && defined(_DEBUG)
// Avoid the need to close running server in debug mode...
String pidf = ConfigFile("debug_pid");
int prev_pid = atoi(LoadFile(pidf));
if(prev_pid) {
kill(prev_pid, SIGTERM);
int status = 0;
waitpid(prev_pid, &status, 0);
}
for(int i = 0; i < 100; i++) {
Cout() << "Trying to start listening " << i << "\n";
int qq = 0;
for(;;) {
if(server.Listen(port, 5))
goto listening;
Sleep(100);
break;
Cout() << "Trying to start listening (other process using the same port?) " << ++qq << "\n";
Sleep(1000);
}
LOG("Cannot open server socket!");
Cout() << "Cannot open server socket!\n";
return;
listening:;
#else
if(!server.Listen(port, 5)) {
LOG("Cannot open server socket!");
@ -185,9 +174,6 @@ listening:;
#endif
#ifdef PLATFORM_POSIX
#ifdef _DEBUG
SaveFile(pidf, AsString(main_pid));
#endif
if(prefork) {
struct sigaction sa;
memset(&sa, 0, sizeof(sa));

View file

@ -385,18 +385,11 @@ One<Exe> Compiler::Block()
One<Exe> Compile(const char *code, const Index<String>& vars)
{
Compiler c(code, vars);
try {
One<Exe> exe = c.Block();
LLOG("Before optimization node count: " << c.GetNodeCount(exe));
c.Optimize(exe);
LLOG("After optimization node count: " << c.GetNodeCount(exe));
return exe;
}
catch(CParser::Error e) {
One<Exe> result;
result.Create<Compiler::ExeConst>().value = e;
return result;
}
One<Exe> exe = c.Block();
LLOG("Before optimization node count: " << c.GetNodeCount(exe));
c.Optimize(exe);
LLOG("After optimization node count: " << c.GetNodeCount(exe));
return exe;
}
};

View file

@ -331,14 +331,17 @@ Http& Http::Ux(const char *id, const String& text)
Http& Http::UxRender(const char *id, const char *template_name)
{
Ux(id, RenderString(template_name));
return *this;
return Ux(id, RenderString(template_name));
}
Http& Http::UxSetValue(const char *id, const String& value)
{
Ux(String(">") + id, value);
return *this;
return Ux(String(">") + id, value);
}
Http& Http::UxRun(const String& js_code)
{
return Ux("!", js_code);
}
};

View file

@ -118,6 +118,7 @@ public:
Http& Ux(const char *id, const String& text);
Http& UxRender(const char *id, const char *template_name);
Http& UxSetValue(const char *id, const String& value);
Http& UxRun(const String& js_code);
String GetResponse() const { return response; }

View file

@ -17,9 +17,10 @@ String LoadTemplate(const char *file, const String& search_path, int lang)
if(IsNull(path)) {
path = GetFileOnPath1(f, search_path);
if(IsNull(path))
return Null;
throw Exc("missing template " + String(file));
}
}
SKYLARKLOG("Loading template file " << path);
FileIn in(path);
String r;
while(in && !in.IsEof()) {

View file

@ -28,7 +28,7 @@ SKYLARK(ServeStaticPage, "static/**")
}
}
SKYLARK(ServeIml, "iml/*")
SKYLARK(Iml, "iml/*")
{
String name = http[0];
int q = name.Find('.');

View file

@ -46,12 +46,20 @@ Value JsIdentity(const Vector<Value>&, const Renderer *r)
return Raw("<script type=\"text/javascript\">var __js_identity__ = \"" + GetIdentity(r) + "\"</script>");
}
Value ImlImg(const Vector<Value>& arg, const Renderer *)
{
if(arg.GetCount() < 1)
throw Exc("Missing image name for ImlImg");
return Raw("<img src=\"iml/" + AsString(arg[0]) + "\")/>");
}
INITBLOCK {
Compiler::Register("cycle", Cycle);
Compiler::Register("raw", RawFn);
Compiler::Register("count", CountFn);
Compiler::Register("post_identity", PostIdentity);
Compiler::Register("js_identity", JsIdentity);
Compiler::Register("ImlImg", ImlImg);
};
};

View file

@ -10,6 +10,9 @@ function ProcessAjaxResult(ss)
if(pos >= 0) {
var id = ss[i].slice(0, pos);
var text = ss[i].slice(pos + 1);
if(id == "!")
eval(text);
else
if(id.length > 1 && id.charAt(0) == '>')
document.getElementById(id.slice(1)).value = text;
else