예제 #1
0
파일: dtestx.c 프로젝트: Cai900205/test
/* RC - Server only, UD - Server and Client, one per EP */
void process_cr(int idx)
{
	DAT_EVENT event;
	DAT_COUNT nmore;
	DAT_RETURN status;
	int pdata;
	DAT_CR_HANDLE cr = DAT_HANDLE_NULL;
	DAT_CONN_QUAL exp_qual = server ? SERVER_ID : CLIENT_ID;
	DAT_CR_PARAM cr_param;
	DAT_CR_ARRIVAL_EVENT_DATA *cr_event =
	    &event.event_data.cr_arrival_event_data;

	LOGPRINTF("%s waiting for connect[%d] request\n",
		  server ? "Server" : "Client", idx);

	status = dat_evd_wait(cr_evd, SERVER_TIMEOUT, 1, &event, &nmore);
	_OK(status, "CR dat_evd_wait");

	if (event.event_number != DAT_CONNECTION_REQUEST_EVENT &&
	    (ud_test && event.event_number !=
	     DAT_IB_UD_CONNECTION_REQUEST_EVENT)) {
		printf("unexpected event,!conn req: 0x%x\n",
		       event.event_number);
		exit(1);
	}

	if ((cr_event->conn_qual != exp_qual) ||
	    (cr_event->sp_handle.psp_handle != psp)) {
		printf("wrong cr event data\n");
		exit(1);
	}

	cr = cr_event->cr_handle;
	status = dat_cr_query(cr, DAT_CSP_FIELD_ALL, &cr_param);
	_OK(status, "dat_cr_query");

	/* use private data to select EP */
	pdata = ntoh32(*((int *)cr_param.private_data));

	LOGPRINTF("%s recvd pdata=0x%x, send pdata=0x%x\n",
		  server ? "Server" : "Client", pdata,
		  *(int *)cr_param.private_data);

	status = dat_cr_accept(cr, ep[pdata], 4, cr_param.private_data);
	_OK(status, "dat_cr_accept");

	printf("%s accepted CR on EP[%d]=%p\n",
	       server ? "Server" : "Client", pdata, ep[pdata]);
}
예제 #2
0
파일: psdapl.c 프로젝트: ParaStation/pscom
static
int _psdapl_get_con_accept(psdapl_con_info_t *ci,
					  DAT_CR_HANDLE cr_handle,
					  psdapl_init_msg_t *imsg)
{
	DAT_RETURN dat_rc;
	int rc;

	rc = psdapl_init_buffers_local(ci);
	if (rc) goto err_init_buf;

	psdapl_init_buffers_remote(ci, imsg);

	rc = psdapl_create_ep(ci);
	if (rc) goto err_create_ep;

	psdapl_init_msg_t res_imsg;
	psdapl_init_init_msg(&res_imsg, ci);

	/* accept connect request. Send info message about my buffers: */
	dat_rc = dat_cr_accept(cr_handle,
			       ci->ep_handle,//   DAT_HANDLE_NULL /* ep_handle */,
			       sizeof(res_imsg) /* private_data_size */,
			       &res_imsg /* private_data*/);
	if (dat_rc != DAT_SUCCESS) goto err_cr_accept;


	rc =psdapl_wait4event(ci, DAT_CONNECTION_EVENT_ESTABLISHED,
			      "DAT_CONNECTION_EVENT_ESTABLISHED");
	if (rc) goto err_con_established;

	return 0;
	/*---*/
err_cr_accept:
	psdapl_dprint_dat_err(0, dat_rc, "CR: dat_cr_accept() failed");
err_con_established:
	/* ToDo: Cleanup ci->ep_handle!! */
err_create_ep:
err_init_buf:
	/* ToDo: Cleanup recv_evd_handle!! */
	/* ToDo: Cleanup connect_evd_handle!! */
	/* ToDo: Cleanup bufpairs!!!!! */
	return -1;
}
static int mca_btl_udapl_accept_connect(mca_btl_udapl_module_t* btl,
                                        DAT_CR_HANDLE cr_handle)
{
    DAT_EP_HANDLE ep;
    int rc;
    mca_btl_base_endpoint_t* proc_ep;
    mca_btl_udapl_addr_t priv_data_in_addr;
    int32_t priv_data_in_conn_type;     /* incoming endpoint type  */

    if (mca_btl_udapl_component.udapl_conn_priv_data) {
        DAT_CR_PARAM cr_param;

        /* query the connection request for incoming private data */
        rc = dat_cr_query(cr_handle,
                    DAT_CR_FIELD_ALL,
                    &cr_param);
        if (rc != DAT_SUCCESS) {
            char* major;
            char* minor;

            dat_strerror(rc, (const char**)&major,
                (const char**)&minor);
            BTL_ERROR(("ERROR: %s %s %s\n", "dat_cr_query",
                major, minor));
            return OMPI_ERROR;
        }

        /* retrieve data from connection request event;
         * cr_param contains remote_port_qual but we need to
         * match on the psp port and address of remote
         * so we get this from the private data.
         */
        memcpy(&priv_data_in_addr,
            (mca_btl_udapl_addr_t *)cr_param.private_data,
            sizeof(mca_btl_udapl_addr_t));
        priv_data_in_conn_type = *(int32_t *)
            ((char *)cr_param.private_data + sizeof(mca_btl_udapl_addr_t));
    }

    /* create the endpoint for the incoming connection */
    rc = mca_btl_udapl_endpoint_create(btl, &ep);
    if(OMPI_SUCCESS != rc) {
        BTL_ERROR(("ERROR: mca_btl_udapl_endpoint_create"));
        return OMPI_ERROR;
    }
    
    /* cr_param no longer valid once dat_cr_accept called */
    rc = dat_cr_accept(cr_handle, ep, 0, NULL);
    if(DAT_SUCCESS != rc) {
        char* major;
        char* minor;

        dat_strerror(rc, (const char**)&major,
            (const char**)&minor);
        BTL_ERROR(("ERROR: %s %s %s\n", "dat_cr_accept",
            major, minor));
        return OMPI_ERROR;
    }

    if (mca_btl_udapl_component.udapl_conn_priv_data) {
        /* With accept now in process find a home for the DAT ep by
         * matching against the private data that came in on the
         * connection request event
         */

        /* find the endpoint which matches the address in data received */
        proc_ep = 
            mca_btl_udapl_find_endpoint_address_match(btl, priv_data_in_addr);

        if (proc_ep == NULL) {
            return OMPI_ERROR;
        }

        if (BTL_UDAPL_EAGER_CONNECTION == priv_data_in_conn_type) {
            proc_ep->endpoint_eager = ep;
        } else {
            assert(BTL_UDAPL_MAX_CONNECTION == priv_data_in_conn_type);
            proc_ep->endpoint_max = ep;
        }
    }

    return OMPI_SUCCESS;
}
예제 #4
0
bool
DT_Performance_Test_Server_Connect(DT_Tdep_Print_Head * phead,
				   Performance_Test_t * test_ptr)
{
	DAT_RETURN ret;
	bool status;
	DAT_RSP_HANDLE rsp_handle;
	DAT_PSP_HANDLE psp_handle;

	DAT_CR_ARRIVAL_EVENT_DATA cr_stat;
	DAT_CR_HANDLE cr_handle;
	DAT_EVENT_NUMBER event_num;

	rsp_handle = DAT_HANDLE_NULL;
	psp_handle = DAT_HANDLE_NULL;
#if 0				/* FIXME */
	if (test_ptr->cmd->use_rsp) {
		/*
		 * Server - create a single-use RSP and
		 *          await a connection for this EP
		 */
		ret = dat_rsp_create(test_ptr->ia_handle,
				     test_ptr->ep_context.port,
				     test_ptr->ep_context.ep_handle,
				     test_ptr->creq_evd_hdl, &rsp_handle);
		if (ret != DAT_SUCCESS) {
			DT_Tdep_PT_Printf(phead,
					  "Test[" F64x
					  "]: dat_rsp_create error: %s\n",
					  test_ptr->base_port,
					  DT_RetToString(ret));
			status = false;
			goto psp_free;
		}

		DT_Tdep_PT_Debug(1,
				 (phead,
				  "Server[" F64x "]: Listen on RSP port 0x" F64x
				  "\n", test_ptr->base_port,
				  test_ptr->ep_context.port));

		/* wait for the connection request */
		if (!DT_cr_event_wait(test_ptr->conn_evd_hdl, &cr_stat) ||
		    !DT_cr_check(&cr_stat,
				 DAT_HANDLE_NULL,
				 test_ptr->ep_context.port,
				 &cr_handle, "Server")) {
			status = false;
			goto psp_free;
		}

		/* what, me query?  just try to accept the connection */
		ret = dat_cr_accept(cr_handle,
				    test_ptr->ep_context.ep_handle,
				    0, (DAT_PVOID) 0 /* no private data */ );
		if (ret != DAT_SUCCESS) {
			DT_Tdep_PT_Printf(phead,
					  "Test[" F64x
					  "]: dat_cr_accept error: %s\n",
					  test_ptr->base_port,
					  DT_RetToString(ret));
			/* cr_handle consumed on failure */
			status = false;
			goto psp_free;
		}

		/* wait for DAT_CONNECTION_EVENT_ESTABLISHED */
		if (!DT_conn_event_wait(test_ptr->ep_context.ep_handle,
					test_ptr->conn_evd_hdl, &event_num)) {
			/* error message printed by DT_conn_event_wait */
			status = false;
			goto psp_free;
		}

	} else
#endif				/* FIXME */
	{
		/*
		 * Server - use a short-lived PSP instead of an RSP
		 */
		status = true;

		ret = dat_psp_create(test_ptr->ia_handle,
				     test_ptr->ep_context.port,
				     test_ptr->creq_evd_hdl,
				     DAT_PSP_CONSUMER_FLAG, &psp_handle);
		if (ret != DAT_SUCCESS) {
			DT_Tdep_PT_Printf(phead,
					  "Test[" F64x
					  "]: dat_psp_create error: %s\n",
					  test_ptr->base_port,
					  DT_RetToString(ret));
			status = false;
			psp_handle = DAT_HANDLE_NULL;
			return (status);
		}

	}

	/*
	 * Here's where we tell the main server process that
	 * this thread is ready to wait for a connection request
	 * from the remote end.
	 */
	DT_Mdep_wait_object_wakeup(&test_ptr->pt_ptr->synch_wait_object);

	DT_Tdep_PT_Debug(1,
			 (phead,
			  "Server[" F64x "]: Listen on PSP port 0x" F64x "\n",
			  test_ptr->base_port, test_ptr->ep_context.port));

	/* wait for a connection request */
	if (!DT_cr_event_wait(phead, test_ptr->creq_evd_hdl, &cr_stat) ||
	    !DT_cr_check(phead,
			 &cr_stat,
			 psp_handle,
			 test_ptr->ep_context.port, &cr_handle, "Server")) {
		status = false;
		goto psp_free;
	}

	/* what, me query?  just try to accept the connection */
	ret = dat_cr_accept(cr_handle,
			    test_ptr->ep_context.ep_handle,
			    0, (DAT_PVOID) 0 /* no private data */ );
	if (ret != DAT_SUCCESS) {
		DT_Tdep_PT_Printf(phead,
				  "Test[" F64x "]: dat_cr_accept error: %s\n",
				  test_ptr->base_port, DT_RetToString(ret));
		/* cr_handle consumed on failure */
		status = false;
		goto psp_free;
	}

	/* wait for DAT_CONNECTION_EVENT_ESTABLISHED */
	if (!DT_conn_event_wait(phead,
				test_ptr->ep_context.ep_handle,
				test_ptr->conn_evd_hdl, &event_num)) {
		/* error message printed by DT_cr_event_wait */
		status = false;
		goto psp_free;
	}

	DT_Tdep_PT_Debug(1,
			 (phead,
			  "Server[" F64x "]: Accept on port 0x" F64x "\n",
			  test_ptr->base_port, test_ptr->ep_context.port));
      psp_free:
	if (DAT_HANDLE_NULL != psp_handle) {
		/* throw away single-use PSP */
		ret = dat_psp_free(psp_handle);
		if (ret != DAT_SUCCESS) {
			DT_Tdep_PT_Printf(phead,
					  "Test[" F64x
					  "]: dat_psp_free error: %s\n",
					  test_ptr->base_port,
					  DT_RetToString(ret));
			status = false;
		}
	}
	if (DAT_HANDLE_NULL != rsp_handle) {
		/* throw away single-use PSP */
		ret = dat_rsp_free(rsp_handle);
		if (ret != DAT_SUCCESS) {
			DT_Tdep_PT_Printf(phead,
					  "Test[" F64x
					  "]: dat_rsp_free error: %s\n",
					  test_ptr->base_port,
					  DT_RetToString(ret));
			status = false;
		}
	}
	/* end short-lived PSP */
#ifdef CM_BUSTED
    /*****  XXX Chill out a bit to give the kludged CM a chance ...
     *****/ DT_Mdep_Sleep(5000);
#endif

	return status;
}