Exemplo n.º 1
0
int main(void)
{
	init_func();
	
	while (1)
	{
		loop_func();
		wait_milliseconds(500);
	}
}
Exemplo n.º 2
0
int main(void)
{
	DDRB = 0xFF;
	DDRA = 0x00;
	Signal = Zero;

	while (1)
	{
		char input = !(PINA & 0x01);
		PORTB = 255 - bounce(input);
		wait_milliseconds(100);
	}
}
Exemplo n.º 3
0
int csnet_hotpatch_do_patching(csnet_hotpatch_t* hp) {
	int ret = -1;
	int len = strlen("business_module.so");
	cs_pqueue_t* pq = cs_pqueue_new(CS_PQ_HIGHEST_PRIORITY);
	DIR* d;
	struct dirent* dir;
	d = opendir(".");

	if (d) {
		while ((dir = readdir(d)) != NULL) {
			if (strncmp(dir->d_name, "business_module.so", len) == 0) {
				struct stat stat_buff;
				stat(dir->d_name, &stat_buff);
				char buff[32] = {0};
				strcat(buff, "./");
				strcat(buff, dir->d_name);
				char* value = strdup(buff);
				cs_pqueue_push(pq, stat_buff.st_mtime, value);
			}
		}
		closedir(d);
	}

	cs_pqnode_t* highest = cs_pqueue_pop(pq);
	if (highest) {
		unsigned char new_md5[17];
		csnet_md5sum(highest->value, new_md5);
		new_md5[16] = '\0';

		if (strcmp((char*)new_md5, (char*)hp->module->md5) == 0) {
			ret = -1;
			goto out;
		}

		csnet_module_t* old_module = hp->module;
		hp->module = csnet_module_new();
		csnet_module_init(hp->module, hp->conntor, hp->log, hp->ctx, hp->q);
		csnet_module_load(hp->module, highest->value);

		if (hotpatching(old_module->business_entry, hp->module->business_entry) == 0) {
			csnet_reset_module(hp->csnet, hp->module);
			if (hp->conntor) {
				csnet_conntor_reset_module(hp->conntor, hp->module);
			}
			while (hp->conntor && old_module->ref_count != 0) {
				wait_milliseconds(10);
			}
			csnet_module_free(old_module);
			LOG_INFO(hp->log, "hotpatch done");
			ret = 0;
			goto out;
		}

		LOG_ERROR(hp->log, "hotpatch failed");
		ret = -1;
	}

out:
	if (highest) {
		free(highest->value);
		cs_pqueue_delete(pq, highest);
	}
	cs_pqueue_free(pq);
	return ret;
}