proxy_C_WaitForSlotEvent (CK_X_FUNCTION_LIST *self,
                          CK_FLAGS flags,
                          CK_SLOT_ID_PTR slot,
                          CK_VOID_PTR reserved)
{
	State *state = (State *)self;
	Proxy *py = state->px;
	CK_FUNCTION_LIST_PTR *f;
	CK_FUNCTION_LIST_PTR funcs;
	CK_SLOT_ID real_slot;
	unsigned int i;
	CK_RV rv = CKR_NO_EVENT;

	/* Only the non-blocking case is supported. */
	if ((flags & CKF_DONT_BLOCK) == 0)
		return CKR_FUNCTION_NOT_SUPPORTED;

	p11_lock ();

	for (f = py->inited; *f; ++f) {
		funcs = *f;
		assert (funcs != NULL);

		rv = (funcs->C_WaitForSlotEvent) (flags, &real_slot, reserved);
		if (rv == CKR_NO_EVENT)
			continue;
		if (rv != CKR_OK)
			break;
		for (i = 0; i < py->n_mappings; i++)
			if (py->mappings[i].funcs == funcs &&
			    py->mappings[i].real_slot == real_slot) {
				*slot = py->mappings[i].wrap_slot;
				break;
			}
	}

	p11_unlock ();

	return rv;
}
proxy_C_WaitForSlotEvent (CK_X_FUNCTION_LIST *self,
                          CK_FLAGS flags,
                          CK_SLOT_ID_PTR slot,
                          CK_VOID_PTR reserved)
{
	State *state = (State *)self;
	Proxy *py = state->px;
	CK_FUNCTION_LIST_PTR *f;
	CK_FUNCTION_LIST_PTR funcs;
	CK_SLOT_ID real_slot;
	unsigned int i;
	CK_RV rv = CKR_NO_EVENT;

	 
	if ((flags & CKF_DONT_BLOCK) == 0)
		return CKR_FUNCTION_NOT_SUPPORTED;

	p11_lock ();

	for (f = py->inited; *f; ++f) {
		funcs = *f;
		assert (funcs != NULL);

		rv = (funcs->C_WaitForSlotEvent) (flags, &real_slot, reserved);
		if (rv == CKR_NO_EVENT)
			continue;
		if (rv != CKR_OK)
			break;
		for (i = 0; i < py->n_mappings; i++)
			if (py->mappings[i].funcs == funcs &&
			    py->mappings[i].real_slot == real_slot) {
				*slot = py->mappings[i].wrap_slot;
				break;
			}
	}

	p11_unlock ();

	return rv;
}