void delete_bootstrap_services(bootstrap_info_t *bootstrap) { server_t *serverp; service_t *servicep; service_t *next; for ( servicep = FIRST(services) ; !IS_END(servicep, services) ; servicep = next) { next = NEXT(servicep); if (bootstrap != servicep->bootstrap) continue; if (!servicep->isActive || !servicep->server) { delete_service(servicep); continue; } serverp = servicep->server; delete_service(servicep); serverp->active_services--; if (!active_server(serverp)) delete_server(serverp); } }
void delete_server_list(lwm2m_context_t * context) { while (NULL != context->serverList) { lwm2m_server_t * server; server = context->serverList; context->serverList = server->next; delete_server(server); } }
static int refresh_server_list(lwm2m_context_t * contextP) { lwm2m_server_t * targetP; lwm2m_server_t * nextP; // Remove all servers marked as dirty targetP = contextP->bootstrapServerList; contextP->bootstrapServerList = NULL; while (targetP != NULL) { nextP = targetP->next; if (!targetP->dirty) { targetP->status = STATE_DEREGISTERED; targetP->next = contextP->bootstrapServerList; contextP->bootstrapServerList = targetP; } else { delete_server(targetP); } targetP = nextP; } targetP = contextP->serverList; contextP->serverList = NULL; while (targetP != NULL) { nextP = targetP->next; if (!targetP->dirty) { // TODO: Should we revert the status to STATE_DEREGISTERED ? targetP->next = contextP->serverList; contextP->serverList = targetP; } else { delete_server(targetP); } targetP = nextP; } return object_getServers(contextP); }
static void server_onevent(int fd, int event, void* userdata) { tcp_server_t *server = (tcp_server_t *)userdata; int error; tcp_connection_t* connection; int client_fd; struct sockaddr_in addr; socklen_t len; inetaddr_t peer_addr; log_debug("server_onevent: fd(%d), event(%d), local addr(%s:%u)", fd, event, server->addr.ip, server->addr.port); len = sizeof(addr); memset(&addr, 0, len); client_fd = accept(server->fd, (struct sockaddr*)&addr, &len); if (client_fd < 0) { error = errno; if (EMFILE == error) { close(server->idle_fd); client_fd = accept(server->fd, (struct sockaddr*)&addr, &len); close(client_fd); server->idle_fd = open("/dev/null", O_RDONLY); } else { log_error("failed to accept a connection request, error: %d, local addr: %s:%u", error, server->addr.ip, server->addr.port); } return; } inetaddr_init(&peer_addr, &addr); log_debug("new connection arrived from %s:%d, local addr: %s:%u", peer_addr.ip, peer_addr.port, server->addr.ip, server->addr.port); set_socket_onblock(client_fd, 1); connection = tcp_connection_new(server->loop, client_fd, server_ondata, server_onclose, server, &peer_addr); server->is_in_callback = 1; server->on_connection(connection, server->userdata, &peer_addr); server->is_in_callback = 0; if (0 == server->is_alive) { delete_server(server); } return; }
static void do_tcp_server_destroy(void* userdata) { tcp_server_t *server = (tcp_server_t*)userdata; if (server->is_in_callback) { server->is_alive = 0; } else { delete_server(server); } return; }