Helper function to free the context. */
| 299 | |
| 300 | /* Helper function to free the context. */ |
| 301 | static void __redisAsyncFree(redisAsyncContext *ac) { |
| 302 | redisContext *c = &(ac->c); |
| 303 | redisCallback cb; |
| 304 | dictIterator *it; |
| 305 | dictEntry *de; |
| 306 | |
| 307 | /* Execute pending callbacks with NULL reply. */ |
| 308 | while (__redisShiftCallback(&ac->replies,&cb) == REDIS_OK) |
| 309 | __redisRunCallback(ac,&cb,NULL); |
| 310 | |
| 311 | /* Execute callbacks for invalid commands */ |
| 312 | while (__redisShiftCallback(&ac->sub.invalid,&cb) == REDIS_OK) |
| 313 | __redisRunCallback(ac,&cb,NULL); |
| 314 | |
| 315 | /* Run subscription callbacks with NULL reply */ |
| 316 | if (ac->sub.channels) { |
| 317 | it = dictGetIterator(ac->sub.channels); |
| 318 | if (it != NULL) { |
| 319 | while ((de = dictNext(it)) != NULL) |
| 320 | __redisRunCallback(ac,dictGetEntryVal(de),NULL); |
| 321 | dictReleaseIterator(it); |
| 322 | } |
| 323 | |
| 324 | dictRelease(ac->sub.channels); |
| 325 | } |
| 326 | |
| 327 | if (ac->sub.patterns) { |
| 328 | it = dictGetIterator(ac->sub.patterns); |
| 329 | if (it != NULL) { |
| 330 | while ((de = dictNext(it)) != NULL) |
| 331 | __redisRunCallback(ac,dictGetEntryVal(de),NULL); |
| 332 | dictReleaseIterator(it); |
| 333 | } |
| 334 | |
| 335 | dictRelease(ac->sub.patterns); |
| 336 | } |
| 337 | |
| 338 | /* Signal event lib to clean up */ |
| 339 | _EL_CLEANUP(ac); |
| 340 | |
| 341 | /* Execute disconnect callback. When redisAsyncFree() initiated destroying |
| 342 | * this context, the status will always be REDIS_OK. */ |
| 343 | if (ac->onDisconnect && (c->flags & REDIS_CONNECTED)) { |
| 344 | if (c->flags & REDIS_FREEING) { |
| 345 | ac->onDisconnect(ac,REDIS_OK); |
| 346 | } else { |
| 347 | ac->onDisconnect(ac,(ac->err == 0) ? REDIS_OK : REDIS_ERR); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (ac->dataCleanup) { |
| 352 | ac->dataCleanup(ac->data); |
| 353 | } |
| 354 | |
| 355 | /* Cleanup self */ |
| 356 | redisFree(c); |
| 357 | } |
| 358 |
no test coverage detected