/* * This function will start a new recv() on a socket for this client manager. */ isc_result_t ns_lwdclient_startrecv(ns_lwdclientmgr_t *cm) { ns_lwdclient_t *client; isc_result_t result; isc_region_t r; if (SHUTTINGDOWN(cm)) { lwdclientmgr_destroy(cm); return (ISC_R_SUCCESS); } /* * If a recv is already running, don't bother. */ if ((cm->flags & NS_LWDCLIENTMGR_FLAGRECVPENDING) != 0) return (ISC_R_SUCCESS); /* * If we have no idle slots, just return success. */ client = ISC_LIST_HEAD(cm->idle); if (client == NULL) return (ISC_R_SUCCESS); INSIST(NS_LWDCLIENT_ISIDLE(client)); /* * Issue the recv. If it fails, return that it did. */ r.base = client->buffer; r.length = LWRES_RECVLENGTH; result = isc_socket_recv(cm->sock, &r, 0, cm->task, ns_lwdclient_recv, client); if (result != ISC_R_SUCCESS) return (result); /* * Set the flag to say we've issued a recv() call. */ cm->flags |= NS_LWDCLIENTMGR_FLAGRECVPENDING; /* * Remove the client from the idle list, and put it on the running * list. */ NS_LWDCLIENT_SETRECV(client); ISC_LIST_UNLINK(cm->idle, client, link); ISC_LIST_APPEND(cm->running, client, link); return (ISC_R_SUCCESS); }
/* * This function will start a new recv() on a socket for this client manager. */ isc_result_t ns_lwdclient_startrecv(ns_lwdclientmgr_t *cm) { ns_lwdclient_t *client; isc_result_t result; isc_region_t r; isc_boolean_t destroy = ISC_FALSE; LOCK(&cm->lock); if (SHUTTINGDOWN(cm)) { destroy = ISC_TRUE; result = ISC_R_SUCCESS; goto unlock; } /* * If a recv is already running, don't bother. */ if ((cm->flags & NS_LWDCLIENTMGR_FLAGRECVPENDING) != 0) { result = ISC_R_SUCCESS; goto unlock; } /* * If we have no idle slots, just return success. */ client = ISC_LIST_HEAD(cm->idle); if (client == NULL) { result = ISC_R_SUCCESS; goto unlock; } INSIST(NS_LWDCLIENT_ISIDLE(client)); /* * Set the flag to say there is a recv pending. If isc_socket_recv * fails we will clear the flag otherwise it will be cleared by * ns_lwdclient_recv. */ cm->flags |= NS_LWDCLIENTMGR_FLAGRECVPENDING; /* * Issue the recv. If it fails, return that it did. */ r.base = client->buffer; r.length = LWRES_RECVLENGTH; result = isc_socket_recv(cm->sock, &r, 0, cm->task, ns_lwdclient_recv, client); if (result != ISC_R_SUCCESS) { cm->flags &= ~NS_LWDCLIENTMGR_FLAGRECVPENDING; goto unlock; } /* * Remove the client from the idle list, and put it on the running * list. */ NS_LWDCLIENT_SETRECV(client); ISC_LIST_UNLINK(cm->idle, client, link); ISC_LIST_APPEND(cm->running, client, link); unlock: UNLOCK(&cm->lock); if (destroy) lwdclientmgr_destroy(cm); return (result); }