// Funcion que elimina todos los mapeos y libera la memoria asignada void del_maps () { map * m = maps; map * e = m; while (m != NULL) { e = m->psig; erase_buf(m->out); erase_buf(m->in); free(m); m = e; } return; }
// funcion que elimina un mapeo en un determinado modo // recibe como parámetro un char *, además del modo void del_map(char * in, int mode) { map * ant; map * m = maps; if (m == NULL) return; // Si el nodo a eliminar es el primero char strin [MAXSC * get_bufsize(m->in)]; get_mapstr_buf(m->in, strin); if ( ! strcmp(in, strin) && mode == m->mode) { maps = m->psig; erase_buf(m->out); erase_buf(m->in); free(m); len_maps--; return; } // si el nodo esta al medio o final ant = m; m = m->psig; while (m != NULL) { char strin [MAXSC * get_bufsize(m->in)]; get_mapstr_buf(m->in, strin); if ( ! strcmp(in, strin) && mode == m->mode) { ant->psig = m->psig; erase_buf(m->out); erase_buf(m->in); free(m); m = ant->psig; len_maps--; return; } ant = m; m = m->psig; } return; }
// Funcion que agrega un mapeo a la lista de mapeos de sesion // recibe un comando in, un out, y un caracter 'type' que indica el modo // en donde tiene efecto el mapeo void add_map(char * in, char * out, int mode, short recursive) { map * m; // si el mapeo ya existe, reemplazo su contenido // guardando su posicion! int exists = exists_map(in, mode); if (exists == -1) { m = (map *) malloc (sizeof(map)); } else { m = maps; while (exists--) m = m->psig; erase_buf(m->in); erase_buf(m->out); exists = TRUE; } m->out = (struct block *) get_mapbuf_str(out); m->in = (struct block *) get_mapbuf_str(in); m->mode = mode; m->recursive = recursive; if (exists == TRUE) return; // in case a map was updated and not created! // inserto al comienzo. comentar lo de abajo en caso de desear esta opción // m->psig = maps == NULL ? NULL : maps; // maps = m; // inserto al final m->psig= NULL; if (maps == NULL) maps = m; else ((map *) get_last_map())->psig = m; len_maps++; return; }
bool ClientServer::unwatch(int fd, bool no_callback) { if (EventManager::unwatch(fd, no_callback)) { if (_c2s.find(fd) != _c2s.end()) { auto session_id = _c2s[fd]; _s2c.erase(session_id); _c2s.erase(fd); } //只有is_child && recv_session_id成功前有内容 //但不排除_session_task中unwatch的可能性 //所以暂时不加条件 TODO 把可能性排除 加上条件 _session_tasks.erase(fd); erase_buf(fd); return true; } return false; }
void Redis::on_close(int client) { erase_buf(client); queue<pair<GUID, RedisCB>>().swap(_callbacks); }