* Remove the source belonging to the specified channel. * * @todo Add more error checks and logging. * * @param channel The channel for which the source should be removed. * * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or * SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon * internal errors. */
| 461 | * internal errors. |
| 462 | */ |
| 463 | static int _sr_session_source_remove(gintptr poll_object) |
| 464 | { |
| 465 | struct source *new_sources; |
| 466 | GPollFD *new_pollfds; |
| 467 | unsigned int old; |
| 468 | |
| 469 | if (session == NULL){ |
| 470 | sr_err("_sr_session_source_remove(), session is null."); |
| 471 | return SR_ERR_CALL_STATUS; |
| 472 | } |
| 473 | |
| 474 | if (!session->sources || !session->num_sources) { |
| 475 | sr_err("%s: sources was NULL", __func__); |
| 476 | return SR_ERR_BUG; |
| 477 | } |
| 478 | |
| 479 | for (old = 0; old < session->num_sources; old++) { |
| 480 | if (session->sources[old].poll_object == poll_object) |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | /* fd not found, nothing to do */ |
| 485 | if (old == session->num_sources) |
| 486 | return SR_OK; |
| 487 | |
| 488 | session->num_sources -= 1; |
| 489 | |
| 490 | if (session->num_sources == 0) { |
| 491 | session->source_timeout = -1; |
| 492 | g_free(session->pollfds); |
| 493 | g_free(session->sources); |
| 494 | session->pollfds = NULL; |
| 495 | session->sources = NULL; |
| 496 | } |
| 497 | else { |
| 498 | if (old != session->num_sources) { |
| 499 | memmove(&session->pollfds[old], &session->pollfds[old+1], |
| 500 | (session->num_sources - old) * sizeof(GPollFD)); |
| 501 | memmove(&session->sources[old], &session->sources[old+1], |
| 502 | (session->num_sources - old) * sizeof(struct source)); |
| 503 | } |
| 504 | |
| 505 | new_pollfds = g_try_realloc(session->pollfds, sizeof(GPollFD) * session->num_sources); |
| 506 | if (!new_pollfds && session->num_sources > 0) { |
| 507 | sr_err("%s: new_pollfds malloc failed", __func__); |
| 508 | return SR_ERR_MALLOC; |
| 509 | } |
| 510 | |
| 511 | new_sources = g_try_realloc(session->sources, sizeof(struct source) * session->num_sources); |
| 512 | if (!new_sources && session->num_sources > 0) { |
| 513 | sr_err("%s: new_sources malloc failed", __func__); |
| 514 | return SR_ERR_MALLOC; |
| 515 | } |
| 516 | |
| 517 | session->pollfds = new_pollfds; |
| 518 | session->sources = new_sources; |
| 519 | } |
| 520 |
no outgoing calls
no test coverage detected