void *chunk_find(size_t size) { unsigned int i; t_mem m; t_chunk c; m.size = size; i = -1; while (++i < g_malloc_memory->size) { c = *(t_chunk *)array_get(g_malloc_memory, i); if ((size <= SMALL_SIZE && c.size != SMALL_CHUNK) || (size > SMALL_SIZE && size <= MEDIUM_SIZE && c.size != MEDIUM_CHUNK) || (size > MEDIUM_SIZE && c.size >= MEDIUM_CHUNK)) continue ; m.start = mem_find(&c, size); if (m.start) { array_add(c.mem, &m); return (m.start); } } c = *chunk_create(size); m.start = c.start; array_add(c.mem, &m); return (m.start); }
static void console_client_read(evutil_socket_t fd, short bedrock_attribute_unused events, void *data) { struct console_client *client = data; int i; struct command_source source; if (client->in_buffer_len == sizeof(client->in_buffer)) { bedrock_log(LEVEL_INFO, "Receive queue exceeded for console client - dropping client"); io_disable(&client->fd.event_read); io_disable(&client->fd.event_write); return; } i = recv(fd, client->in_buffer + client->in_buffer_len, sizeof(client->in_buffer) - client->in_buffer_len, 0); if (i <= 0) { if (bedrock_list_has_data(&exiting_client_list, client) == false) bedrock_log(LEVEL_INFO, "Lost connection from console client"); io_disable(&client->fd.event_read); io_disable(&client->fd.event_write); console_exit(client); return; } client->in_buffer_len += i; source.user = NULL; source.console = client; while (io_is_pending(&client->fd.event_read, EV_READ) && (i = mem_find(client->in_buffer, client->in_buffer_len, '\n')) > 0) { client->in_buffer[i] = 0; if (client->in_buffer[i - 1] == '\r') client->in_buffer[i - 1] = 0; command_run(&source, (char *) client->in_buffer); memmove(client->in_buffer, client->in_buffer + i + 1, client->in_buffer_len - i - 1); client->in_buffer_len -= i + 1; } }