Example #1
0
	void CoroutinePool::finalize(){
		m_cleaning =true;

		// clean idle list
		for(int64_t i=0; i<m_idle_coroutine_list->size(); ++i){
			Coroutine* cr =static_cast< Coroutine* >(m_idle_coroutine_list->get(i));
			cr->resume(SafeNew<Error>(ErrorCode::COROUTINE_CLEAN), 0);
			ASSERT(cr->getStatus() == Coroutine::STATUS_DEAD);
		}
		CLEAN_POINTER(m_idle_coroutine_list);

		// clean active table
		Hash* active_cr_tb =m_active_coroutine_table;
		m_active_coroutine_table =0;
		HashIterator* it =static_cast< HashIterator* >(active_cr_tb->iterator());
		while(it->next()){
			Coroutine* cr =static_cast< Coroutine* >(it->getValue());
			cr->resume(SafeNew<Error>(ErrorCode::COROUTINE_CLEAN), 0);
			ASSERT(cr->getStatus() == Coroutine::STATUS_DEAD);
		}
		CLEAN_POINTER(active_cr_tb);

		// super
		Super::finalize();
	}
Example #2
0
	void HttpCookie::finalize(){
		CLEAN_POINTER(m_Name);
		CLEAN_POINTER(m_Value);
		CLEAN_POINTER(m_Domain);
		CLEAN_POINTER(m_Path);
		CLEAN_POINTER(m_ExpireTime);
		Super::finalize();
	}
Example #3
0
	void ServiceManager::finalize(){
		OPH();
		unloadAllService();
		CLEAN_POINTER(m_unloading_service_tb);
		CLEAN_POINTER(m_service_tb);
		CLEAN_POINTER(m_route_tb);
		OutputDebug("service manager released [ ok ]");
		Super::finalize();
	}
Example #4
0
	void Coroutine::finalize(){
		if(m_status != STATUS_DEAD){
			FATAL("!!! coroutine need cleaned");
		}
#ifdef VALGRIND_CHECK_ENABLE
		if(m_stack){
			_valgrind_unregister();
		}
#endif
		DEALLOCATE(m_stack);
		m_status =STATUS_DESTORY;
		CLEAN_POINTER(m_arg);
		CLEAN_POINTER(m_yield_param);
		CLEAN_POINTER(m_resume_param);
		Super::finalize();
	}
Example #5
0
	/** object **/
	void Logger::finalize(){
		CLEAN_POINTER(m_szName);
		if(m_file){
			fclose(m_file);
			m_file =0;
		}
		Super::finalize();
	}
Example #6
0
	void Url::clean(){
		CLEAN_POINTER(m_url);
		CLEAN_POINTER(m_protocol);
		CLEAN_POINTER(m_auth);
		CLEAN_POINTER(m_host);
		CLEAN_POINTER(m_path);
		CLEAN_POINTER(m_query_string);
		CLEAN_POINTER(m_query);
		CLEAN_POINTER(m_fragment);
	}
Example #7
0
	void ApplicationBase::setDataPath(String* path){
		// root
		ASSIGN_POINTER(m_data_path, path);

		// bin & data
		if(m_data_path){
			ASSIGN_POINTER(m_root_path, FileSystem::Join(m_data_path, STR("../")));
			ASSIGN_POINTER(m_bin_path, FileSystem::Join(m_root_path, STR("bin/")));

			INFO("data path is '%s'", m_data_path->c_str());
			INFO("root path is '%s'", m_root_path->c_str());
			INFO("bin path is '%s'", m_bin_path->c_str());
		}
		else{
			CLEAN_POINTER(m_root_path);
			CLEAN_POINTER(m_bin_path);
		}
	}
Example #8
0
	void ProcessLocal::finalize(){
		OPH();
		// clear dispatcher
		m_dispatcher_manager->clearDispatcher();

		CLEAN_POINTER(m_service_manager);
		CLEAN_POINTER(m_network);
		CLEAN_POINTER(m_dispatcher_manager);

		CLEAN_POINTER(m_lua_init_callback);
		CLEAN_POINTER(m_protocol_manager);
		CLEAN_POINTER(m_string_table);
		CLEAN_POINTER(m_object_factory);

		Super::finalize();
		OutputDebug("process local released [ ok ]");
	}
Example #9
0
	void HttpRespond::finalize(){
		// head line
		CLEAN_POINTER(m_version);
		CLEAN_POINTER(m_msg);

		// header
		CLEAN_POINTER(m_header_tb);
		CLEAN_POINTER(m_cookie_tb);

		// content
		CLEAN_POINTER(m_content);

		// mime
		CLEAN_POINTER(m_post_tb);

		// misc
		CLEAN_POINTER(m_requestor);

		Super::finalize();
	}
Example #10
0
	/** entry **/
	void Coroutine::_entry(){
		// prepare
		Coroutine* self =Running();
		ASSERT(self);
		self->retain();

		// loop
		while(1){
			// check break
			if(Error* err= dynamic_cast< Error* >(self->m_resume_param)){
				if(err->getCode() == ErrorCode::COROUTINE_CLEAN){
					break;
				}
			}
			// run task
			try{
				if(self->m_task){
					self->m_task(self->m_arg);
					self->m_task =0;
					CLEAN_POINTER(self->m_arg);
				}
			}
			catch(...){
				ERROR("coroutine exec task occurs exception, perhaps coroutine is cleaned");
				break;
			}
			// yield
			self->_yield(0, STATUS_IDLE);
		}

		// clean
		INFO("coroutine %lld exit", (long long)self->m_id);
		self->m_status =STATUS_DEAD;
		g_running =0;
		self->release();
	}
Example #11
0
void RpcInfo::finalize() {
    CLEAN_POINTER(m_command);
    Super::finalize();
}
Example #12
0
	void LogService::on_unload(){
		CLEAN_POINTER(m_logger_table);
		Super::on_unload();
		DEBUG("unload log service");
	}
Example #13
0
	void CoroutineService::on_unload(){
		CLEAN_POINTER(m_command_desc_table);
		CLEAN_POINTER(m_sleeper_table);
		CLEAN_POINTER(m_cr_pool);
		Super::on_unload();
	}
Example #14
0
	void TcpListener::finalize(){
		_close_sock();
		CLEAN_POINTER(m_path);
		Super::finalize();
	}
Example #15
0
void ClassInfo::finalize() {
    CLEAN_POINTER(m_name);
    CLEAN_POINTER(m_super_name);
    CLEAN_POINTER(m_FieldInfo);
    Super::finalize();
}
Example #16
0
	void ProtocolManager::finalize(){
		CLEAN_POINTER(m_creator_table);
		Super::finalize();
	}
Example #17
0
void CommandService::finalize() {
    ASSERT(m_processing_command == 0);
    CLEAN_POINTER(m_queue_tb);
    CLEAN_POINTER(m_rpc_tb);
    Super::finalize();
}
Example #18
0
	void Actor::finalize(){
		CLEAN_POINTER(m_observer_manager);
		CLEAN_POINTER(m_component_manager);
		Super::finalize();
	}
Example #19
0
	/** modify **/
	bool Url::parse(String* url){
		// clean
		clean();
		
		// check
		if(!url){
			return false;
		}

		// prepare sz
		const char* sz =url->c_str();
		// puts(sz);

		// protocol
		const char* cursor =strstr(sz, "://");
		int64_t pos =(cursor ? (cursor-sz) : -1);
		if(pos == 0){
			ERROR("fail to call %s, len(protocol) can't be 0");
			return false;
		}
		else if(pos > 0){
			ASSIGN_POINTER(m_protocol, String::New(sz, pos));
			sz =cursor + 3;
		}

		// auth
		cursor =strchr(sz, '@');
		pos =(cursor ? (cursor-sz) : -1);
		if(pos == 0){
			CLEAN_POINTER(m_protocol);
			ERROR("fail to call %s, len(auth) can't be 0");
			return false;
		}
		else if(pos > 0){
			ASSIGN_POINTER(m_auth, String::New(sz, pos));
			sz =cursor + 1;
		}

		// host
		const char* szbeg =sz;
		while(const char ch =*sz){
			if(ch=='/' || ch=='?' || ch=='#'){
				break;
			}
			++sz;
		}
		if(sz > szbeg){
			ASSIGN_POINTER(m_host, String::New(szbeg, sz-szbeg));
		}

		// path
		if(*sz == '/'){
			const char* szbeg =sz++;
			while(const char ch =*sz){
				if(ch=='?' || ch=='#'){
					break;
				}
				++sz;
			}
			ASSIGN_POINTER(m_path, String::New(szbeg, sz-szbeg));
		}

		// query
		if(*sz == '?'){
			const char* szbeg =++sz;
			while(const char ch =*sz){
				if(ch == '#'){
					break;
				}
				++sz;
			}
			if(sz > szbeg){
				ASSIGN_POINTER(m_query_string, String::New(szbeg, sz-szbeg));
				ASSIGN_POINTER(m_query, SafeNew<Hash>());
				if(!ParseQuery(m_query_string, m_query)){
					clean();
					return false;
				}
			}
			else{
				ASSIGN_POINTER(m_query_string, String::New(szbeg, sz-szbeg));
			}
		}

		// fragment
		if(*sz == '#'){
			ASSIGN_POINTER(m_fragment, String::New(sz+1));
		}

		// url
		ASSIGN_POINTER(m_url, url);

		return true;
	}
Example #20
0
	void DispatcherManager::finalize(){
		CLEAN_POINTER(m_dispatcher_list);
		Super::finalize();
	}
Example #21
0
	/* Service */
	bool CService::load_module(const int64_t id, const char* path){
		if(!Super::load_module(id, path)) return false;
		if(!path) return false;
		m_id =id;

		// load dll
		m_dl =::dlopen(path, RTLD_NOW | RTLD_GLOBAL);
		if(m_dl == 0){
			const char* err =::dlerror();
			ERROR("fail to call dlopen <%s>, %s", path, err ? err : "no error");
			return false;
		}

		// object pool manager
		OPH();

		// set path
		String* p =String::NewString(path);
		ASSIGN_POINTER(m_path, p);

		// get name
		{
			const char* (*fn_get_name)() =(const char* (*)())::dlsym(m_dl, "get_name");
			if(!fn_get_name){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, get_name>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
			const char* name =fn_get_name();
			if(!name) name ="unnamed";
			CLEAN_POINTER(m_name);
			m_name =String::NewString(name);
			m_name->retain();
		}

		// get desc
		{
			const char* (*fn_get_desc)() =(const char* (*)())::dlsym(m_dl, "get_desc");
			if(!fn_get_desc){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, get_desc>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
			const char* desc =fn_get_desc();
			if(!desc) desc ="";
			CLEAN_POINTER(m_desc);
			m_desc =String::NewString(desc);
			m_desc->retain();
		}

		// get on_load
		{
			m_on_load =(PFN_ON_LOAD)::dlsym(m_dl, "on_load");
			if(!m_on_load){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_load>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		// get on_update
		{
			m_on_update =(PFN_ON_UPDATE)::dlsym(m_dl, "on_update");
			if(!m_on_update){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_update>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		// get on_start_command
		{
			m_on_start_command =(PFN_ON_START_COMMAND)::dlsym(m_dl, "on_start_command");
			if(!m_on_start_command){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_start_command>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		// get on_unload
		{
			m_on_unload =(PFN_ON_UNLOAD)::dlsym(m_dl, "on_unload");
			if(!m_on_unload){
				const char* err =::dlerror();
				ERROR("fail to call dlsym <%s, on_unload>, %s", path, err ? err : "no error");
				unload_module();
				return false;
			}
		}

		return true;
	}
Example #22
0
	bool HttpRespond::flush(){
		// check
		if(m_requestor == 0){
			WARN("http flush failed, requestor is null");
			return false;
		}

		//// build data
		BinaryCoder<4096> coder;

		/// head line
		// version
		if(m_version){
			coder.append(m_version);
		}
		else{
			coder.append("HTTP/1.1");
		}
		coder.append(" ");
		// code
		coder.append(String::Format("%lld", (long long)m_code));
		coder.append(" ");
		// msg
		coder.append(_code_to_msg(m_code));
		coder.append("\r\n");

		/// header
	  	if(!m_header_tb->has("Content-Type")){
			coder.append("Content-Type: text/html\r\n");
		}
	  	if(!m_header_tb->has("Content-Length")){
			coder.append(String::Format("Content-Length: %lld\r\n", (long long)m_content->size()));
		}
		HashIterator* it =static_cast< HashIterator* >(m_header_tb->iterator());
		while(it->next()){
			if(String* name =dynamic_cast< String* >(it->getKey())){
				if(String* value =dynamic_cast< String* >(it->getValue())){
					coder.append(name);
					coder.append(": ");
					coder.append(value);
					coder.append("\r\n");
				}
			}
		}
		it =static_cast< HashIterator* >(m_cookie_tb->iterator());
		while(it->next()){
			if(dynamic_cast< String* >(it->getKey())){
				if(HttpCookie* cookie =dynamic_cast< HttpCookie* >(it->getValue())){
					if(String* str =cookie->build(false)){
						coder.append(str);
						coder.append("\r\n");
					}
				}
			}
		}
		coder.append("\r\n");

		/// content
		if(m_content->size() > 0){
			coder.append(m_content->c_str(), m_content->size());
		}

		//// send
		const bool ok =m_requestor->send(coder.c_str(), coder.size());

		//// clear
		CLEAN_POINTER(m_version);
		m_code =200;
		CLEAN_POINTER(m_msg);
		m_header_tb->clear();
		m_cookie_tb->clear();
		m_content->clear();

		//// post process
		if(!ok){
			close();
		}
		m_auto_flush =false;
		return ok;
	}
Example #23
0
	void ObjectFactory::finalize(){
		CLEAN_POINTER(m_class_info_tb);
		Super::finalize();
	}
Example #24
0
	void CallbackService::on_unload(){
		CLEAN_POINTER(m_command_desc_table);
		Super::on_unload();
	}
Example #25
0
	void BytesChannel::finalize(){
		_close_fd();
		CLEAN_POINTER(m_cycle_buffer);
		Super::finalize();
	}
Example #26
0
	void HttpRespond::close(){
		CLEAN_POINTER(m_requestor);
	}