Lines Matching refs:fd

190 #define FDLOCK_ID(fd)		((fd) % FDLOCK_COUNT)
193 #define FDLOCK_ID(fd) 0
296 int fd;
606 if (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
612 "%s: %s", sock->fd,
636 watch_fd(isc_socketmgr_t *manager, int fd, int msg) {
648 evchange.ident = fd;
661 event.data.fd = fd;
662 if (epoll_ctl(manager->epoll_fd, EPOLL_CTL_ADD, fd, &event) == -1 &&
670 int lockid = FDLOCK_ID(fd);
677 pfd.fd = fd;
684 manager->fdpollinfo[fd].want_read = 1;
686 manager->fdpollinfo[fd].want_write = 1;
694 FD_SET(fd, manager->read_fds);
696 FD_SET(fd, manager->write_fds);
704 unwatch_fd(isc_socketmgr_t *manager, int fd, int msg) {
716 evchange.ident = fd;
729 event.data.fd = fd;
730 if (epoll_ctl(manager->epoll_fd, EPOLL_CTL_DEL, fd, &event) == -1 &&
735 "epoll_ctl(DEL), %d: %s", fd, strbuf);
742 int lockid = FDLOCK_ID(fd);
746 pfds[0].fd = fd;
755 manager->fdpollinfo[fd].want_write == 1) {
757 pfds[1].fd = fd;
761 manager->fdpollinfo[fd].want_read == 1) {
763 pfds[1].fd = fd;
771 manager->fdpollinfo[fd].want_read = 0;
773 manager->fdpollinfo[fd].want_write = 0;
781 FD_CLR(fd, manager->read_fds);
783 FD_CLR(fd, manager->write_fds);
791 wakeup_socket(isc_socketmgr_t *manager, int fd, int msg) {
793 int lockid = FDLOCK_ID(fd);
801 INSIST(fd >= 0 && fd < (int)manager->maxsocks);
805 INSIST(manager->fdstate[fd] == CLOSE_PENDING);
806 manager->fdstate[fd] = CLOSED;
807 (void)unwatch_fd(manager, fd, SELECT_POKE_READ);
808 (void)unwatch_fd(manager, fd, SELECT_POKE_WRITE);
809 (void)close(fd);
814 if (manager->fdstate[fd] == CLOSE_PENDING) {
825 (void)unwatch_fd(manager, fd, SELECT_POKE_READ);
826 (void)unwatch_fd(manager, fd, SELECT_POKE_WRITE);
829 if (manager->fdstate[fd] != MANAGED) {
838 result = watch_fd(manager, fd, msg);
848 fd, isc_result_totext(result));
859 select_poke(isc_socketmgr_t *mgr, int fd, int msg) {
864 buf[0] = fd;
895 * Read a message on the internal fd.
898 select_readmsg(isc_socketmgr_t *mgr, int *fd, int *msg) {
906 *fd = -1; /* Silence compiler. */
922 *fd = buf[0];
930 select_poke(isc_socketmgr_t *manager, int fd, int msg) {
933 else if (fd >= 0)
934 wakeup_socket(manager, fd, msg);
940 * Make a fd non-blocking.
943 make_nonblock(int fd) {
950 ret = ioctl(fd, FIONBIO, (char *)&on);
952 flags = fcntl(fd, F_GETFL, 0);
954 ret = fcntl(fd, F_SETFL, flags);
961 "ioctl(%d, FIONBIO, &on): %s", fd,
963 "fcntl(%d, F_SETFL, %d): %s", fd, flags,
1487 cc = recvmsg(sock->fd, &msghdr, 0);
1504 sock->fd, cc, recv_errno, strbuf);
1673 cc = sendmsg(sock->fd, &msghdr, 0);
1771 closesocket(isc_socketmgr_t *manager, isc_socket_t *sock, int fd) {
1773 int lockid = FDLOCK_ID(fd);
1780 manager->fds[fd] = NULL;
1782 manager->fdstate[fd] = CLOSED;
1784 manager->fdstate[fd] = CLOSE_PENDING;
1789 * and `fd' may be reassigned for a new socket. So we do
1796 (void)unwatch_fd(manager, fd, SELECT_POKE_READ);
1797 (void)unwatch_fd(manager, fd, SELECT_POKE_WRITE);
1799 select_poke(manager, fd, SELECT_POKE_CLOSE);
1809 if (manager->maxfd == fd) {
1813 for (i = fd - 1; i >= 0; i--) {
1835 int fd;
1846 REQUIRE(sock->fd == -1 || sock->fd < (int)manager->maxsocks);
1848 if (sock->fd >= 0) {
1849 fd = sock->fd;
1850 sock->fd = -1;
1851 closesocket(manager, sock, fd);
1887 sock->fd = -1;
1991 * like the lock, must be initialized as well. The fd associated must be
2073 (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_USE_MIN_MTU,
2083 (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_MTU,
2106 sock->fd = socket(sock->pf, SOCK_DGRAM, IPPROTO_UDP);
2109 sock->fd = socket(sock->pf, SOCK_STREAM, IPPROTO_TCP);
2112 sock->fd = socket(sock->pf, SOCK_STREAM, 0);
2121 if (sock->fd == -1 && errno == EINTR && tries++ < 42)
2129 sock->fd >= 0 && sock->fd < manager->reserved) {
2131 new = fcntl(sock->fd, F_DUPFD, manager->reserved);
2133 (void)close(sock->fd);
2135 sock->fd = new;
2137 } else if (sock->fd >= 0 && sock->fd < 20) {
2139 new = fcntl(sock->fd, F_DUPFD, 20);
2141 (void)close(sock->fd);
2143 sock->fd = new;
2148 if (sock->fd >= (int)manager->maxsocks) {
2149 (void)close(sock->fd);
2155 sock->fd, manager->maxsocks);
2159 if (sock->fd < 0) {
2196 result = make_nonblock(sock->fd);
2198 (void)close(sock->fd);
2206 setsockopt(sock->fd, SOL_SOCKET, SO_BSDCOMPAT,
2211 sock->fd,
2220 if (setsockopt(sock->fd, SOL_SOCKET, SO_NOSIGPIPE,
2225 sock->fd,
2243 if (setsockopt(sock->fd, SOL_SOCKET, SO_TIMESTAMP,
2249 sock->fd,
2273 && (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_RECVPKTINFO,
2278 "%s: %s", sock->fd,
2288 && (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_PKTINFO,
2293 sock->fd,
2308 (void)setsockopt(sock->fd, IPPROTO_IPV6,
2322 (void)setsockopt(sock->fd, IPPROTO_IP, IP_MTU_DISCOVER,
2332 (void)setsockopt(sock->fd, IPPROTO_IP, IP_DONTFRAG,
2339 if (getsockopt(sock->fd, SOL_SOCKET, SO_RCVBUF,
2343 if (setsockopt(sock->fd, SOL_SOCKET, SO_RCVBUF,
2348 sock->fd, size,
2419 lockid = FDLOCK_ID(sock->fd);
2421 manager->fds[sock->fd] = sock;
2422 manager->fdstate[sock->fd] = MANAGED;
2424 INSIST(sock->manager->fdpollinfo[sock->fd].want_read == 0 &&
2425 sock->manager->fdpollinfo[sock->fd].want_write == 0);
2432 if (manager->maxfd < sock->fd)
2433 manager->maxfd = sock->fd;
2457 REQUIRE(sock->fd == -1);
2461 sock->fd = -1;
2464 int lockid = FDLOCK_ID(sock->fd);
2467 sock->manager->fds[sock->fd] = sock;
2468 sock->manager->fdstate[sock->fd] = MANAGED;
2470 INSIST(sock->manager->fdpollinfo[sock->fd].want_read == 0 &&
2471 sock->manager->fdpollinfo[sock->fd].want_write == 0);
2477 if (sock->manager->maxfd < sock->fd)
2478 sock->manager->maxfd = sock->fd;
2493 isc_socket_fdwatchcreate(isc_socketmgr_t *manager, int fd, int flags,
2508 sock->fd = fd;
2523 lockid = FDLOCK_ID(sock->fd);
2525 manager->fds[sock->fd] = sock;
2526 manager->fdstate[sock->fd] = MANAGED;
2532 if (manager->maxfd < sock->fd)
2533 manager->maxfd = sock->fd;
2538 select_poke(sock->manager, sock->fd, SELECT_POKE_READ);
2540 select_poke(sock->manager, sock->fd, SELECT_POKE_WRITE);
2591 int fd;
2600 REQUIRE(sock->fd >= 0 && sock->fd < (int)sock->manager->maxsocks);
2612 fd = sock->fd;
2613 sock->fd = -1;
2624 closesocket(manager, sock, fd);
2824 int fd;
2877 fd = accept(sock->fd, &dev->newsocket->peer_address.type.sa,
2884 if (fd >= 0 && fd < 20) {
2886 new = fcntl(fd, F_DUPFD, 20);
2888 (void)close(fd);
2890 fd = new;
2895 if (fd < 0) {
2936 fd = -1;
2945 (void)close(fd);
2957 (void)close(fd);
2959 } else if (fd >= (int)manager->maxsocks) {
2966 fd, manager->maxsocks);
2967 (void)close(fd);
2972 if (fd != -1) {
2986 select_poke(sock->manager, sock->fd, SELECT_POKE_ACCEPT);
2990 if (fd != -1) {
2991 result = make_nonblock(fd);
2993 (void)close(fd);
2994 fd = -1;
3001 if (fd != -1) {
3002 int lockid = FDLOCK_ID(fd);
3004 dev->newsocket->fd = fd;
3019 manager->fds[fd] = dev->newsocket;
3020 manager->fdstate[fd] = MANAGED;
3026 if (manager->maxfd < fd)
3027 manager->maxfd = fd;
3057 select_poke(sock->manager, sock->fd, SELECT_POKE_ACCEPT);
3124 select_poke(sock->manager, sock->fd, SELECT_POKE_READ);
3179 select_poke(sock->manager, sock->fd, SELECT_POKE_WRITE);
3219 select_poke(sock->manager, sock->fd, SELECT_POKE_WRITE);
3259 select_poke(sock->manager, sock->fd, SELECT_POKE_READ);
3265 * Process read/writes on each fd here. Avoid locking
3269 process_fd(isc_socketmgr_t *manager, int fd, isc_boolean_t readable,
3275 int lockid = FDLOCK_ID(fd);
3281 if (manager->fdstate[fd] == CLOSE_PENDING) {
3284 (void)unwatch_fd(manager, fd, SELECT_POKE_READ);
3285 (void)unwatch_fd(manager, fd, SELECT_POKE_WRITE);
3289 sock = manager->fds[fd];
3330 (void)unwatch_fd(manager, fd, SELECT_POKE_READ);
3332 (void)unwatch_fd(manager, fd, SELECT_POKE_WRITE);
3395 REQUIRE(events[i].data.fd < (int)manager->maxsocks);
3397 if (events[i].data.fd == manager->pipe_fds[0]) {
3413 process_fd(manager, events[i].data.fd,
3442 REQUIRE(events[i].fd < (int)manager->maxsocks);
3444 if (events[i].fd == manager->pipe_fds[0]) {
3449 process_fd(manager, events[i].fd,
3484 int msg, fd;
3487 select_readmsg(manager, &fd, &msg);
3493 "for socket %d"), msg, fd);
3516 wakeup_socket(manager, fd, msg);
3553 * Get the control fd here. This will never change.
3635 * Process reads on internal, control fd.
4222 select_poke(sock->manager, sock->fd, SELECT_POKE_READ);
4419 select_poke(sock->manager, sock->fd,
4767 setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
4770 "setsockopt(%d) %s", sock->fd,
4778 if (bind(sock->fd, &sockaddr->type.sa, sockaddr->length) < 0) {
4830 if (setsockopt(sock->fd, SOL_SOCKET, SO_ACCEPTFILTER,
4870 if (listen(sock->fd, (int)backlog) < 0) {
4956 select_poke(manager, sock->fd, SELECT_POKE_ACCEPT);
5004 cc = connect(sock->fd, &addr->type.sa, addr->length);
5095 select_poke(manager, sock->fd, SELECT_POKE_CONNECT);
5153 if (getsockopt(sock->fd, SOL_SOCKET, SO_ERROR,
5162 * fd and pretend nothing strange happened.
5166 select_poke(sock->manager, sock->fd,
5262 if (getsockname(sock->fd, &addressp->type.sa, (void *)&len) < 0) {
5432 if (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_V6ONLY,
5438 "%s: %s", sock->fd,
5634 if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {