| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: socket.c,v 1.19 2021/02/19 16:42:20 christos Exp $ */ | | 1 | /* $NetBSD: socket.c,v 1.20 2021/02/22 01:31:51 christos Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") | | 4 | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
5 | * | | 5 | * |
6 | * This Source Code Form is subject to the terms of the Mozilla Public | | 6 | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | * License, v. 2.0. If a copy of the MPL was not distributed with this | | 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | * file, you can obtain one at https://mozilla.org/MPL/2.0/. | | 8 | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | * | | 9 | * |
10 | * See the COPYRIGHT file distributed with this work for additional | | 10 | * See the COPYRIGHT file distributed with this work for additional |
11 | * information regarding copyright ownership. | | 11 | * information regarding copyright ownership. |
12 | */ | | 12 | */ |
13 | | | 13 | |
14 | /*! \file */ | | 14 | /*! \file */ |
| @@ -3204,56 +3204,52 @@ internal_fdwatch_write(isc__socket_t *so | | | @@ -3204,56 +3204,52 @@ internal_fdwatch_write(isc__socket_t *so |
3204 | sock->fdwatcharg, ISC_SOCKFDWATCH_WRITE); | | 3204 | sock->fdwatcharg, ISC_SOCKFDWATCH_WRITE); |
3205 | | | 3205 | |
3206 | LOCK(&sock->lock); | | 3206 | LOCK(&sock->lock); |
3207 | | | 3207 | |
3208 | if (isc_refcount_decrement(&sock->references) == 0) { | | 3208 | if (isc_refcount_decrement(&sock->references) == 0) { |
3209 | UNLOCK(&sock->lock); | | 3209 | UNLOCK(&sock->lock); |
3210 | destroy(&sock); | | 3210 | destroy(&sock); |
3211 | return; | | 3211 | return; |
3212 | } | | 3212 | } |
3213 | | | 3213 | |
3214 | if (more_data) | | 3214 | if (more_data) |
3215 | select_poke(sock->manager, sock->threadid, sock->fd, | | 3215 | select_poke(sock->manager, sock->threadid, sock->fd, |
3216 | SELECT_POKE_WRITE); | | 3216 | SELECT_POKE_WRITE); |
3217 | | | | |
3218 | UNLOCK(&sock->lock); | | | |
3219 | } | | 3217 | } |
3220 | | | 3218 | |
3221 | static void | | 3219 | static void |
3222 | internal_fdwatch_read(isc__socket_t *sock) | | 3220 | internal_fdwatch_read(isc__socket_t *sock) |
3223 | { | | 3221 | { |
3224 | int more_data; | | 3222 | int more_data; |
3225 | | | 3223 | |
3226 | INSIST(VALID_SOCKET(sock)); | | 3224 | INSIST(VALID_SOCKET(sock)); |
3227 | | | 3225 | |
3228 | isc_refcount_increment(&sock->references); | | 3226 | isc_refcount_increment(&sock->references); |
3229 | UNLOCK(&sock->lock); | | 3227 | UNLOCK(&sock->lock); |
3230 | | | 3228 | |
3231 | more_data = (sock->fdwatchcb)(sock->fdwatchtask, (isc_socket_t *)sock, | | 3229 | more_data = (sock->fdwatchcb)(sock->fdwatchtask, (isc_socket_t *)sock, |
3232 | sock->fdwatcharg, ISC_SOCKFDWATCH_READ); | | 3230 | sock->fdwatcharg, ISC_SOCKFDWATCH_READ); |
3233 | | | 3231 | |
3234 | LOCK(&sock->lock); | | 3232 | LOCK(&sock->lock); |
3235 | | | 3233 | |
3236 | if (isc_refcount_decrement(&sock->references) == 0) { | | 3234 | if (isc_refcount_decrement(&sock->references) == 0) { |
3237 | UNLOCK(&sock->lock); | | 3235 | UNLOCK(&sock->lock); |
3238 | destroy(&sock); | | 3236 | destroy(&sock); |
3239 | return; | | 3237 | return; |
3240 | } | | 3238 | } |
3241 | | | 3239 | |
3242 | if (more_data) | | 3240 | if (more_data) |
3243 | select_poke(sock->manager, sock->threadid, sock->fd, | | 3241 | select_poke(sock->manager, sock->threadid, sock->fd, |
3244 | SELECT_POKE_READ); | | 3242 | SELECT_POKE_READ); |
3245 | | | | |
3246 | UNLOCK(&sock->lock); | | | |
3247 | } | | 3243 | } |
3248 | | | 3244 | |
3249 | /* | | 3245 | /* |
3250 | * Process read/writes on each fd here. Avoid locking | | 3246 | * Process read/writes on each fd here. Avoid locking |
3251 | * and unlocking twice if both reads and writes are possible. | | 3247 | * and unlocking twice if both reads and writes are possible. |
3252 | */ | | 3248 | */ |
3253 | static void | | 3249 | static void |
3254 | process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) { | | 3250 | process_fd(isc__socketthread_t *thread, int fd, bool readable, bool writeable) { |
3255 | isc__socket_t *sock; | | 3251 | isc__socket_t *sock; |
3256 | int lockid = FDLOCK_ID(fd); | | 3252 | int lockid = FDLOCK_ID(fd); |
3257 | | | 3253 | |
3258 | /* | | 3254 | /* |
3259 | * If the socket is going to be closed, don't do more I/O. | | 3255 | * If the socket is going to be closed, don't do more I/O. |