- for (i = 0; i < pr_poll_array_size(&instance->poll_array); i++) {
- user_data = pr_poll_array_get_user_data(&instance->poll_array, i);
-
- client = NULL;
- ipc_client = NULL;
- client_disconnect = 0;
-
- switch (user_data->type) {
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_SOCKET:
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_CLIENT:
- client = user_data->client;
- client_disconnect = client->schedule_disconnect;
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_SOCKET:
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_CLIENT:
- ipc_client = user_data->ipc_client;
- client_disconnect = ipc_client->schedule_disconnect;
- }
-
- if (!client_disconnect && poll_res > 0 &&
- pfds[i].out_flags & PR_POLL_READ) {
- switch (user_data->type) {
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_SOCKET:
- qnetd_client_net_accept(instance);
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_CLIENT:
- if (qnetd_client_net_read(instance, client) == -1) {
- client_disconnect = 1;
- }
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_SOCKET:
- qnetd_ipc_accept(instance, &ipc_client);
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_CLIENT:
- qnetd_ipc_io_read(instance, ipc_client);
- break;
- }
- }
-
- if (!client_disconnect && poll_res > 0 &&
- pfds[i].out_flags & PR_POLL_WRITE) {
- switch (user_data->type) {
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_SOCKET:
- /*
- * Poll write on listen socket -> fatal error
- */
- log(LOG_CRIT, "POLL_WRITE on listening socket");
-
- return (-1);
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_CLIENT:
- if (qnetd_client_net_write(instance, client) == -1) {
- client_disconnect = 1;
- }
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_SOCKET:
- log(LOG_CRIT, "POLL_WRITE on listening IPC socket");
- return (-1);
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_CLIENT:
- qnetd_ipc_io_write(instance, ipc_client);
- break;
- }
- }
-
- if (!client_disconnect && poll_res > 0 &&
- (pfds[i].out_flags & (PR_POLL_ERR|PR_POLL_NVAL|PR_POLL_HUP|PR_POLL_EXCEPT)) &&
- !(pfds[i].out_flags & (PR_POLL_READ|PR_POLL_WRITE))) {
- switch (user_data->type) {
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_SOCKET:
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_SOCKET:
- if (pfds[i].out_flags != PR_POLL_NVAL) {
- /*
- * Poll ERR on listening socket is fatal error.
- * POLL_NVAL is used as a signal to quit poll loop.
- */
- log(LOG_CRIT, "POLL_ERR (%u) on listening "
- "socket", pfds[i].out_flags);
- } else {
- log(LOG_DEBUG, "Listening socket is closed");
- }
-
- return (-1);
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_CLIENT:
- log(LOG_DEBUG, "POLL_ERR (%u) on client socket. "
- "Disconnecting.", pfds[i].out_flags);
-
- client_disconnect = 1;
- break;
- case QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_CLIENT:
- log(LOG_DEBUG, "POLL_ERR (%u) on ipc client socket."
- " Disconnecting.", pfds[i].out_flags);
-
- client_disconnect = 1;
- break;
- }
- }
-
- /*
- * If client is scheduled for disconnect, disconnect it
- */
- if (user_data->type == QNETD_POLL_ARRAY_USER_DATA_TYPE_CLIENT &&
- client_disconnect) {
- qnetd_instance_client_disconnect(instance, client, 0);
- } else if (user_data->type == QNETD_POLL_ARRAY_USER_DATA_TYPE_IPC_CLIENT &&
- (client_disconnect || ipc_client->schedule_disconnect)) {
- qnetd_ipc_client_disconnect(instance, ipc_client);
- }
- }