| 232 | */ |
| 233 | |
| 234 | int /* O - 1 on success, 0 on error */ |
| 235 | cupsdAddSelect(int fd, /* I - File descriptor */ |
| 236 | cupsd_selfunc_t read_cb, /* I - Read callback */ |
| 237 | cupsd_selfunc_t write_cb,/* I - Write callback */ |
| 238 | void *data) /* I - Data to pass to callback */ |
| 239 | { |
| 240 | _cupsd_fd_t *fdptr; /* File descriptor record */ |
| 241 | #ifdef HAVE_EPOLL |
| 242 | int added; /* 1 if added, 0 if modified */ |
| 243 | #endif /* HAVE_EPOLL */ |
| 244 | |
| 245 | |
| 246 | /* |
| 247 | * Range check input... |
| 248 | */ |
| 249 | |
| 250 | cupsdLogMessage(CUPSD_LOG_DEBUG2, |
| 251 | "cupsdAddSelect(fd=%d, read_cb=%p, write_cb=%p, data=%p)", |
| 252 | fd, read_cb, write_cb, data); |
| 253 | |
| 254 | if (fd < 0) |
| 255 | return (0); |
| 256 | |
| 257 | /* |
| 258 | * See if this FD has already been added... |
| 259 | */ |
| 260 | |
| 261 | if ((fdptr = find_fd(fd)) == NULL) |
| 262 | { |
| 263 | /* |
| 264 | * No, add a new entry... |
| 265 | */ |
| 266 | |
| 267 | if ((fdptr = calloc(1, sizeof(_cupsd_fd_t))) == NULL) |
| 268 | return (0); |
| 269 | |
| 270 | fdptr->fd = fd; |
| 271 | fdptr->use = 1; |
| 272 | |
| 273 | if (!cupsArrayAdd(cupsd_fds, fdptr)) |
| 274 | { |
| 275 | cupsdLogMessage(CUPSD_LOG_EMERG, "Unable to add fd %d to array!", fd); |
| 276 | free(fdptr); |
| 277 | return (0); |
| 278 | } |
| 279 | |
| 280 | #ifdef HAVE_EPOLL |
| 281 | added = 1; |
| 282 | } |
| 283 | else |
| 284 | added = 0; |
| 285 | #else |
| 286 | } |
| 287 | #endif /* HAVE_EPOLL */ |
| 288 | |
| 289 | #ifdef HAVE_KQUEUE |
no test coverage detected