diff --git a/modules/ti.Network/HTTPServerRequestFactory.cpp b/modules/ti.Network/HTTPServerRequestFactory.cpp index 0ba326607..22e667e2f 100644 --- a/modules/ti.Network/HTTPServerRequestFactory.cpp +++ b/modules/ti.Network/HTTPServerRequestFactory.cpp @@ -37,13 +37,15 @@ class HTTPRequestHandler : public Poco::Net::HTTPRequestHandler { }; void HTTPRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { - // XXX(Josh): The request and response object's lifetime is limited to this functions call. - // If the developer should keep a reference to these around past the callback lifetime and then - // attempts to access it may result in a crash! ValueList args; args.push_back(Value::NewObject(new HTTPServerRequest(request))); - args.push_back(Value::NewObject(new HTTPServerResponse(response))); + HTTPServerResponse * resp = new HTTPServerResponse(response); + args.push_back(Value::NewObject(resp)); + resp->asyncState = 0; RunOnMainThread(m_callback, args); + while (resp->asyncState > 0) { + Poco::Thread::sleep(5); + } } HTTPServerRequestFactory::HTTPServerRequestFactory(KMethodRef callback) diff --git a/modules/ti.Network/HTTPServerResponse.cpp b/modules/ti.Network/HTTPServerResponse.cpp index d2634b373..8d3f408c7 100644 --- a/modules/ti.Network/HTTPServerResponse.cpp +++ b/modules/ti.Network/HTTPServerResponse.cpp @@ -35,6 +35,7 @@ HTTPServerResponse::HTTPServerResponse(Poco::Net::HTTPServerResponse &response) SetMethod("addCookie",&HTTPServerResponse::AddCookie); SetMethod("setHeader",&HTTPServerResponse::SetHeader); SetMethod("write",&HTTPServerResponse::Write); + SetMethod("enableAsync",&HTTPServerResponse::EnableAsync); } void HTTPServerResponse::SetStatus(const ValueList& args, KValueRef result) @@ -102,6 +103,7 @@ void HTTPServerResponse::SetHeader(const ValueList& args, KValueRef result) void HTTPServerResponse::Write(const ValueList& args, KValueRef result) { std::ostream& ostr = response.send(); + asyncState = -1; if (args.at(0)->IsString()) { @@ -123,4 +125,14 @@ void HTTPServerResponse::Write(const ValueList& args, KValueRef result) } } +void HTTPServerResponse::EnableAsync(const ValueList& args, KValueRef result) +{ + if (asyncState >= 0) { + //int v = args.at(0)->ToInt(); + asyncState = 1; + } else { + throw ValueException::FromString("response already written, no async allowed."); + } +} + } // namespace Titanium diff --git a/modules/ti.Network/HTTPServerResponse.h b/modules/ti.Network/HTTPServerResponse.h index 7a7fc4ecf..f6fe3e5b3 100644 --- a/modules/ti.Network/HTTPServerResponse.h +++ b/modules/ti.Network/HTTPServerResponse.h @@ -25,7 +25,7 @@ namespace Titanium { class HTTPServerResponse : public StaticBoundObject { public: HTTPServerResponse(Poco::Net::HTTPServerResponse &response); - + int asyncState; //0:sync & waiting for response; 1:async & waiting for response; -1: got response private: void SetStatus(const ValueList& args, KValueRef result); void SetReason(const ValueList& args, KValueRef result); @@ -35,6 +35,7 @@ class HTTPServerResponse : public StaticBoundObject { void AddCookie(const ValueList& args, KValueRef result); void SetHeader(const ValueList& args, KValueRef result); void Write(const ValueList& args, KValueRef result); + void EnableAsync(const ValueList& args, KValueRef result); Poco::Net::HTTPServerResponse& response; }; diff --git a/modules/ti.UI/mac/MenuDelegate.h b/modules/ti.UI/mac/MenuDelegate.h index 39b15ddc0..a7e9f0b32 100644 --- a/modules/ti.UI/mac/MenuDelegate.h +++ b/modules/ti.UI/mac/MenuDelegate.h @@ -18,7 +18,7 @@ #include "MenuMac.h" -@interface MenuDelegate : NSObject +@interface MenuDelegate : NSObject { Titanium::MenuMac* menu; BOOL dirty; diff --git a/modules/ti.UI/mac/NativeWindow.h b/modules/ti.UI/mac/NativeWindow.h index ef5141590..70643e0ca 100644 --- a/modules/ti.UI/mac/NativeWindow.h +++ b/modules/ti.UI/mac/NativeWindow.h @@ -31,7 +31,7 @@ class UserWindowMac; @class WebViewDelegate; -@interface NativeWindow : NSWindow +@interface NativeWindow : NSWindow { BOOL canReceiveFocus; WebView* webView; diff --git a/modules/ti.UI/mac/TitaniumApplicationDelegate.h b/modules/ti.UI/mac/TitaniumApplicationDelegate.h index eeec5a12b..817d739b1 100644 --- a/modules/ti.UI/mac/TitaniumApplicationDelegate.h +++ b/modules/ti.UI/mac/TitaniumApplicationDelegate.h @@ -18,7 +18,7 @@ #include "UIMac.h" -@interface TitaniumApplicationDelegate : NSObject +@interface TitaniumApplicationDelegate : NSObject { Titanium::UIMac *binding; }