Exemplo n.º 1
0
bool https_client::connect_server(acl::http_client& client)
{
	logger_debug(DEBUG, 1, "begin connect server");

	if (client.open(server_addr_.c_str(), 60, 60, true) == false)
	{
		logger_error("failed to connect server %s", server_addr_.c_str());
		return false;
	}
	else
		logger_debug(DEBUG, 1, "connect server ok");

	if (ssl_conf_)
	{
		logger_debug(DEBUG, 1, "begin open ssl");

		acl::polarssl_io* ssl = new acl::polarssl_io(*ssl_conf_, false);
		if (client.get_stream().setup_hook(ssl) == ssl)
		{
			logger_error("open ssl client error");
			ssl->destroy();
			return false;
		}
		else
			logger_debug(DEBUG, 1, "open ssl ok");
	}

	return true;
}
Exemplo n.º 2
0
bool https_client::connect_server(const acl::string& server_addr,
	acl::http_client& client)
{
	// 先查本地映射表中有没有映射项
	master_service& ms = acl::singleton2<master_service>::get_instance();
	const char* addr = ms.get_addr(server_addr.c_str());
	if (addr == NULL)
		addr = server_addr.c_str();

	if (client.open(addr, 60, 60, true) == false)
	{
		out_.format("connect server %s error", addr);
		return false;
	}
	else
		logger_debug(DEBUG, 1, "connect server ok");

	if (ssl_conf_)
	{
		logger_debug(DEBUG, 1, "begin open ssl");

		acl::polarssl_io* ssl = new acl::polarssl_io(*ssl_conf_, false);
		if (client.get_stream().setup_hook(ssl) == ssl)
		{
			out_.puts("open ssl client error");
			ssl->destroy();
			return false;
		}
		else
			logger_debug(DEBUG, 1, "open ssl ok");
	}

	return true;
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
    Allocator* alloc = allocator_nginx_create(1024);
    Config* config = config_xml_expat_create();
    
    config_load(config, "../../../src/app/genesis-config.xml");
    Reactor* reactor = reactor_create(config, alloc);

    SourcesManager* sources_manager = NULL;
    reactor_get_sources_manager(reactor, &sources_manager);
    MainLoop* main_loop = NULL;
    reactor_get_main_loop(reactor, &main_loop);
    Source* timer_source = source_timer_create(2000, test_timer, (void*)reactor);
    //sources_manager_add_source(sources_manager, timer_source);
    logger_debug(reactor->logger, "sources_count = %d", sources_manager_get_count(sources_manager));
    main_loop_add_source(main_loop, timer_source);
    logger_debug(reactor->logger, "sources_count = %d", sources_manager_get_count(sources_manager));

    reactor_run(reactor);
    
    reactor_destroy(reactor);

    config_destroy(config);

    allocator_destroy(alloc);

    return 0;
}
Exemplo n.º 4
0
int			network_listen(struct timeval *timeout)
{
  fd_set		set;
  int			ret;

  flush_list();
  setfd(&set);
  if (timeout)
    logger_debug("[NETWORK] waiting for next action in %lu:%lu",
	   timeout->tv_sec,
	   timeout->tv_usec);
  else
    logger_debug("[NETWORK] waiting for extern action. nothing planified");
  if ((ret = (select(g_network->nfds, &set, NULL, NULL, timeout))) > 0)
    {
      find_speaker(&set,
		   g_network->read,
		   &extract_from_socket,
		   &execute_from_socket);
      find_speaker(&set,
		   g_network->listened,
		   &extract_from_listener,
		   &execute_from_listener);
    }
  g_network->nfds = 0;
  return (ret);
}
Exemplo n.º 5
0
bool logger_servlet::doPost(acl::HttpServletRequest& req,
	acl::HttpServletResponse&)
{
	const char* uri = req.getRequestUri();
	if (uri == NULL || *uri == 0)
	{
		logger_debug(DEBUG_HTTP, 1, "getRequestUri null");
		return false;
	}

	const char* host = req.getRemoteHost();
	if (host == NULL || *host == 0)
	{
		logger_debug(DEBUG_HTTP, 1, "no Host");
		return false;
	}

	acl::string url;
	url.format("http://%s/%s", host, uri);
	logger("%s", url.c_str());

	int   n;
	char  buf[8192];
	acl::http_client* conn = req.getClient();
	while (true)
	{
		n = conn->read_body(buf, sizeof(buf));
		if (n < 0)
			return false;
		else if (n == 0)
			break;
	}

	return true;
}
Exemplo n.º 6
0
bool ServerIOCallback::read_callback(char* data, int len)
{
    const char* myname = "read_callback";

    if (data == NULL || *data == 0 || len <= 0)
    {
        logger_warn("invalid data: %s, len: %d",
                    data ? data : "null", len);
        return false;
    }

    // 处理服务端发来的命令

    acl::url_coder coder;
    coder.decode(data);

    logger_debug(DEBUG_SVR, 1, "client: %s", data);

    const char* ptr = coder.get("count");
    if (ptr == NULL)
    {
        logger_warn("%s(%d), %s: no count", __FILE__, __LINE__, myname);
        return true;
    }

    unsigned int nconns = (unsigned int) atoi(ptr);
    conn_->set_nconns(nconns);

    // 尝试将服务端连接对象添加进服务端管理对象中
    ServerManager::get_instance().set(conn_);

    return true;
}
Exemplo n.º 7
0
/**
 * Format has to contain at least one %s. The first occurrence
 * of %s is substituted with the binary value of the register.
 */
void logger_log_register(char* format, volatile unsigned int * register_ptr) {
    char bin_reg_val [32];
    unsigned int register_val = *register_ptr;
    int i = 0;
    for(i = 31; i >= 0; i--) {
        if(register_val & 1) {
            bin_reg_val[i] = '1';
        } else {
            bin_reg_val[i] = '0';
        }
        register_val >>= 1;
    }
    logger_debug(format, bin_reg_val);
}
Exemplo n.º 8
0
static Ret main_loop_select_add_source(MainLoop* thiz, Source* source)
{
    DECLES_PRIV(priv, thiz);
    Event event;

    event_init(&event, EVT_ADD_SOURCE);
    event.u.extra = source;

//    source->active = 1;
    source_enable(source);
    
    logger_debug(priv->logger, "%s: add sources", __func__);
    return source_queue_event(sources_manager_get_primary_source(priv->sources_manager),
                              &event);
}
Exemplo n.º 9
0
static int	finish_elevation(t_case *c, int lvl)
{
  t_node	*node;
  char		buffer[BUFFER_SIZE];
  int		ret;

  ret = 0;
  node = c->players->head;
  logger_debug("Fin d'incantation");
  sprintf(buffer, "niveau actuel : %d\n", lvl);
  while (node)
    {
      ((t_player *)node->data)->level = lvl;
      if (write_socket(((t_player *)node->data)->client->fd, buffer) <= 0)
	ret = 1;
      node = node->next;
    }
  return (ret);
}
Exemplo n.º 10
0
static gboolean
_exclude_memory_from_core_dump(gpointer area, gsize len)
{
#if defined(MADV_DONTDUMP)
  if (madvise(area, len, MADV_DONTDUMP) < 0)
    {

      if (errno == EINVAL)
        {
          logger_debug("secret storage: MADV_DONTDUMP not supported",
                       "len: %"G_GSIZE_FORMAT", errno: %d\n", len, errno);
          return TRUE;
        }

      logger_fatal("secret storage: cannot madvise buffer", "errno: %d\n", errno);
      return FALSE;
    }
#endif
  return TRUE;
}
Exemplo n.º 11
0
void		player_drop_end_cb(t_client *client, int error)
{
  int		*ressources;
  int		*inventory;
  t_tile	*tile;

  logger_debug("[GAME] ");
  if (!error)
    {
      tile = client->player->tile;
      ressources = (int *)&tile->ressources;
      inventory = (int *)&client->player->inventory;
      if (inventory[item] > 0)
	{
	  inventory[item] -= 1;
	  ressources[item] += 1;
	  client_send(client, REP_OK);
	}
      else
	client_send(client, REP_KO);
    }
  else
    client_send(client, REP_KO);
}
Exemplo n.º 12
0
int8_t ipc_handle_syscall(ProcessId_t o, uint8_t call_type, message_t* msg) {
	Process_t* src = process_manager_current_process;
	Process_t* dst = NULL;

	if (src->pid == o) {
		return IPC_DEADLOCK;
	}

	if (call_type == IPC_RECEIVE_ASYNC && src->ipc.sender.head == NULL) {
		return IPC_NOTHING_RECEIVED;
	}

	if (o == PROCESS_STDIN) {
		o = src->stdin;
	} else if (o == PROCESS_STDOUT) {
		o = src->stdout;
	}

	if (o == PROCESS_INVALID_ID) {
		return IPC_OTHER_NOT_FOUND;
	} else if ((call_type & IPC_RECEIVE) != IPC_RECEIVE || o != PROCESS_ANY) { /* allow ANY only on receive */
		dst = process_manager_get_process_byid(o);

		if (dst == NULL) {
			return IPC_OTHER_NOT_FOUND;
		}
	}

	src->ipc.other = o;
	src->ipc.msg = mmu_get_physical_address(src->page_table, msg);

	switch (call_type) {
		case IPC_SEND:
		case IPC_SENDREC: /* SEND is falling through here */
			_disable_interrupts();
			if (dst->state == PROCESS_ZOMBIE) {
				_enable_interrupts();
				return IPC_DEAD;
			}
			if (dst->state == PROCESS_BLOCKED && dst->ipc.call_type == IPC_RECEIVE && (dst->ipc.other == src->pid || dst->ipc.other == PROCESS_ANY)) {
				logger_debug("IPC: SEND-copying src=%i:%s dst=%i:%s", src->pid, src->name, o, (dst != NULL) ? dst->name : "<ANY>");
				if (dst->ipc.other == PROCESS_ANY) {
					dst->ipc.other = src->pid;
				}
				_enable_interrupts();
				/* both process are now BLOCKED */
				copy_msg(src, dst);
				dst->ipc.call_type = IPC_NOOP;
				process_manager_set_process_ready(dst);
			} else {
				logger_debug("IPC: SEND-blocked src=%i:%s dst=%i:%s", src->pid, src->name, o, (dst != NULL) ? dst->name : "<ANY>");
				if (dst->ipc.other == src->pid && dst->ipc.call_type & IPC_SEND) {
					return IPC_DEADLOCK;
				}

				src->ipc.call_type = IPC_SEND;

				/* place msg for later delivery into the IPC queue of the destination */
				linked_list_add(&dst->ipc.sender, src); /* TODO: check for too less memory */

				/* pause process */
				process_manager_block_current_process();
				process_manager_run_process(dst);
				_enable_interrupts();
			}

			/* msg delivered, falling through receive except for send only */
			if (call_type == IPC_SEND) {
				break;
			}

		case IPC_RECEIVE: /* SENDREC and SEND are falling through here */
		case IPC_RECEIVE_ASYNC:
			_disable_interrupts();
			if (dst != NULL) {
				if (dst->state == PROCESS_ZOMBIE) {
					_enable_interrupts();
					return IPC_DEAD;
				}
			} else {
				/* receiving from ANY, maybe someone is already sending to this process */
				linked_list_node_t* node;
				do {
					node = linked_list_pop_head(&src->ipc.sender);
					if (node != NULL) {
						dst = node->value;
						free(node);
					}
				} while (dst != NULL && dst->state == PROCESS_ZOMBIE);
			}
			if (dst != NULL && dst->state == PROCESS_BLOCKED && (dst->ipc.call_type & IPC_SEND) == IPC_SEND && dst->ipc.other == src->pid) {
				logger_debug("IPC: RECIEVED-copying src=%i:%s dst=%i:%s", src->pid, src->name, o, (dst != NULL) ? dst->name : "<ANY>");
				/* both process are now BLOCKED */
				_enable_interrupts();

				/* remove sender out of sender list */
				if (o != PROCESS_ANY) {
					linked_list_node_t* node = src->ipc.sender.head;
					while (node != NULL) {
						Process_t* p = node->value;
						if (p->pid == o) {
							linked_list_remove(&src->ipc.sender, node);
							break;
						}

						node = node->next;
					}
				}

				copy_msg(dst, src);
				dst->ipc.call_type = IPC_NOOP;
				process_manager_set_process_ready(dst);
			} else {
				if (dst != NULL && dst->ipc.other == src->pid && dst->ipc.call_type == IPC_RECEIVE) {
					return IPC_DEADLOCK;
				}

				src->ipc.call_type = IPC_RECEIVE;

				/* wait for msg delivery */
				process_manager_block_current_process();
				process_manager_run_process(dst);
				if (dst->state == PROCESS_ZOMBIE) {
					_enable_interrupts();
					return IPC_DEAD;
				}
				logger_debug("IPC: RECIEVED-blocked src=%i:%s dst=%i:%s", src->pid, src->name, o, (dst != NULL) ? dst->name : "<ANY>");
				_enable_interrupts();

				/* msg received */
			}
			break;
	}

	return IPC_OK;
}
Exemplo n.º 13
0
void main(void) {
	/* logger_init() */
	/*uart_get(3, &uart3);
	uart_protocol_format_t protocol;
	protocol.baudrate = 0x001A; //115.2Kbps		138;	//9.6 Kbps
	protocol.stopbit = 0x0;		//1 stop bit
	protocol.datalen = 0x3;		//length 8
	protocol.use_parity = 0x0;
	uart_init(&uart3, 0x00, protocol);
	//irq_add_handler(UART3_INTCPS_MAPPING_ID, &uart3_irq_handler);

	logger_debug("\r\n\r\nSystem initialize ...");
	logger_logmode();*/

	ram_manager_init();
	mmu_table_t* page_table = mmu_init();

	/* init led stuff */
	turnoff_rgb();

	process_manager_init(page_table);

	binaries[0] = osx_init(&BINARY_driver_manager, &mem_elf_read);
	driver_manager = process_manager_start_process_bybinary(binaries[0], PROCESS_PRIORITY_HIGH, PROCESS_DRIVER_MANAGER_NAME);

	/* add drivers to the driver manager */
	binaries[1] = osx_init(&BINARY_gpio, &mem_elf_read);
//	add_driver(binaries[1], "GPIO", GPIO5);

	/* add drivers to the driver manager */
	binaries[4] = osx_init(&BINARY_uart, &mem_elf_read);
//	add_driver(binaries[4], "UART 21", UART1);
	add_driver(binaries[4], "UART 22", UART2);
//	add_driver(binaries[4], "UART 23", UART3);

	binaries[2] = osx_init(&BINARY_led0_user, &mem_elf_read);

	//process_manager_start_process_bybinary(binaries[2], PROCESS_PRIORITY_HIGH, "LED(fast) 21 100 100");
	//process_manager_start_process_bybinary(binaries[2], PROCESS_PRIORITY_HIGH, "LED(slow) 22 1000");

	dmx_uart_set_send_mode(); //TODO: remove

	//binaries[3] = osx_init(&BINARY_uart2_user, &mem_elf_read);
	//process_manager_start_process_bybinary(binaries[3], PROCESS_PRIORITY_HIGH, "UART2_user_proc");

	//binaries[3] = osx_init(&BINARY_dmx, &mem_elf_read);
	// TODO: add_driver(binaries[3], "DMX", DMX);
	//process_manager_start_process_bybinary(binaries[3], PROCESS_PRIORITY_HIGH, "DMX");

	binaries[3] = osx_init(&BINARY_tty, &mem_elf_read);
	process_manager_start_process_bybinary(binaries[3], PROCESS_PRIORITY_HIGH, "tty 23");

	binaries[5] = osx_init(&BINARY_cpu_info, &mem_elf_read);
	process_manager_start_process_bybinary(binaries[5], PROCESS_PRIORITY_HIGH, "CPU_INFO");

	binaries[6] = osx_init(&BINARY_dmx, &mem_elf_read);
	add_driver(binaries[6], "DMX 5", DMX);

//	binaries[7] = osx_init(&BINARY_dmx_user, &mem_elf_read);
//	process_manager_start_process_bybinary(binaries[7], PROCESS_PRIORITY_HIGH, "DMX_User_app 5");

	binaries[8] = osx_init(&BINARY_dmx_control, &mem_elf_read);
	process_manager_start_process_bybinary(binaries[8], PROCESS_PRIORITY_HIGH, "DMX_Control 5");

	logger_debug("System started ...");

	system_main_loop();
}
Exemplo n.º 14
0
static Ret main_loop_select_run(MainLoop* thiz)
{
    DECLES_PRIV(priv, thiz);

    int i = 0;
    int n = 0;
    int fd = -1;
    int mfd = -1;
    int wait_time = 3600 * 3000;
//    int wait_time = 1000;
    int source_wait_time = 0;
    int ret = 0;
    struct timeval tv = {0};
    Source* source = NULL;
    int count = 0;

    priv->running = 1;
    while(priv->running) {
        FD_ZERO(&(priv->fdset));
        FD_ZERO(&(priv->err_fdset));
        count = sources_manager_get_count(priv->sources_manager);
        logger_debug(priv->logger, "%s: sources count = %d", __func__, count);

        for (i = 0; i < count; i++) {
            source = NULL;
            sources_manager_get(priv->sources_manager, i, &source);
            if ((fd = source_get_fd(source)) >= 0) {
                FD_SET(fd, &(priv->fdset));
                FD_SET(fd, &(priv->err_fdset));
                if (fd > mfd) mfd = fd;
                ++n;
            }

            source_wait_time = source_check(source);
            logger_debug(priv->logger, "%s: source_wait_time = %d", __func__, source_wait_time);
            if (source_wait_time >= 0 && source_wait_time < wait_time) {
                wait_time = source_wait_time;
            }
            
            // process signal sources here;
            // TODO add time interval into source_signal
            if (source_get_type(source) == SOURCE_SIGNAL && source->active == 1) {
                source_dispatch(source);
                source->active = 0;
            }
        }
        
        logger_debug(priv->logger, "%s: wait_time = %d", __func__, wait_time);

        tv.tv_sec = wait_time / 1000;
        tv.tv_usec = (wait_time % 1000)*1000;

        ret = select(mfd + 1, &(priv->fdset), NULL, &(priv->err_fdset), &tv);

        for (i = 0; i < sources_manager_get_count(priv->sources_manager); ) {
            if (sources_manager_need_refresh(priv->sources_manager)) {
                break;
            }
            sources_manager_get(priv->sources_manager, i, &source);

            if (source->disable > 0) {
                sources_manager_del_source(priv->sources_manager, source);
                continue;
            }

            if ((fd = source_get_fd(source)) >= 0 && ret != 0) {
                if (ret > 0 && FD_ISSET(fd, &(priv->fdset))) {
                    if (source_dispatch(source) != RET_OK) {
                        sources_manager_del_source(priv->sources_manager, source);
                    } else {
                        ++i;
                    }
                    continue;
                }
            } else if (FD_ISSET(fd, &(priv->fdset))) {
                sources_manager_del_source(priv->sources_manager, source);
                continue;
            }

            if ((source_wait_time = source_check(source)) == 0) {
                if (source_dispatch(source) != RET_OK) {
                    sources_manager_del_source(priv->sources_manager, source);
                } else {
                    ++i;
                }
                continue;
            }

            ++i;
        }
    }

    return RET_OK;
}
Exemplo n.º 15
0
void uart3_irq_handler(void) {
	char received_char = *((char*) 0x49020000);
	logger_debug("UART3 - Received a character: %c", received_char);
}
Exemplo n.º 16
0
void logger_logmode(void) {
    logger_debug("System currently in %s mode", logger_getmode(_get_CPSR()));
}
Exemplo n.º 17
0
Arquivo: util.c Projeto: jwerle/ebmq
void
ebmq_debug (char *message) {
  logger_debug(message);
}