* Register the fd in the fdset with read/write handler and context. */
| 113 | * Register the fd in the fdset with read/write handler and context. |
| 114 | */ |
| 115 | int |
| 116 | fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat) |
| 117 | { |
| 118 | int i; |
| 119 | |
| 120 | if (pfdset == NULL || fd == -1) |
| 121 | return -1; |
| 122 | |
| 123 | pthread_mutex_lock(&pfdset->fd_mutex); |
| 124 | i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; |
| 125 | if (i == -1) { |
| 126 | pthread_mutex_lock(&pfdset->fd_pooling_mutex); |
| 127 | fdset_shrink_nolock(pfdset); |
| 128 | pthread_mutex_unlock(&pfdset->fd_pooling_mutex); |
| 129 | i = pfdset->num < MAX_FDS ? pfdset->num++ : -1; |
| 130 | if (i == -1) { |
| 131 | pthread_mutex_unlock(&pfdset->fd_mutex); |
| 132 | return -2; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | fdset_add_fd(pfdset, i, fd, rcb, wcb, dat); |
| 137 | pthread_mutex_unlock(&pfdset->fd_mutex); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Unregister the fd from the fdset. |
no test coverage detected