📄 ch3u_connect_sock.c
字号:
MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_hostd"); } /* --END ERROR HANDLING-- */ } str_errno = MPIU_Str_get_int_arg(bc, MPIDI_CH3I_PORT_KEY, port); if (str_errno != MPIU_STR_SUCCESS) { /* --BEGIN ERROR HANDLING */ if (str_errno == MPIU_STR_FAIL) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_missingport"); } else { /* MPIU_STR_TRUNCATED or MPIU_STR_NONEM */ MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**argstr_port"); } /* --END ERROR HANDLING-- */ } /* ifname is optional */ /* FIXME: This is a hack to allow Windows to continue to use the host description string instead of the interface address bytes when posting a socket connection. This should be fixed by changing the Sock_post_connect to only accept interface address. Note also that Windows does not have the inet_pton routine; the Windows version of this routine will need to be identified or written. See also channels/sock/ch3_progress.c and channels/ssm/ch3_progress_connect.c */ *hasIfaddr = 0;#if !defined(HAVE_WINDOWS_H) && defined(HAVE_INET_PTON) str_errno = MPIU_Str_get_string_arg(bc, MPIDI_CH3I_IFNAME_KEY, ifname, sizeof(ifname) ); if (str_errno == MPIU_STR_SUCCESS) { /* Convert ifname into 4-byte ip address */ /* Use AF_INET6 for IPv6 (inet_pton may still be used). An address with more than 3 :'s is an IPv6 address */ int rc = inet_pton( AF_INET, (const char *)ifname, ifaddr->ifaddr ); if (rc == 0) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**ifnameinvalid"); } else if (rc < 0) { /* af_inet not supported */ MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**afinetinvalid"); } else { /* Success */ *hasIfaddr = 1; ifaddr->len = 4; /* IPv4 address */ ifaddr->type = AF_INET; } }#endif fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDU_SOCK_GET_CONNINFO_FROM_BC); return mpi_errno; fn_fail: goto fn_exit;}/* MPIDI_CH3U_Get_business_card_sock - does socket specific portion of * setting up a business card * * Parameters: * bc_val_p - business card value buffer pointer, updated to the next * available location or freed if published. * val_max_sz_p - ptr to maximum value buffer size reduced by the number * of characters written * */#undef FUNCNAME#define FUNCNAME MPIDI_CH3U_Get_business_card_sock#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPIDI_CH3U_Get_business_card_sock(int myRank, char **bc_val_p, int *val_max_sz_p){ int mpi_errno = MPI_SUCCESS; MPIDU_Sock_ifaddr_t ifaddr; char ifname[MAX_HOST_DESCRIPTION_LEN]; char *bc_orig = *bc_val_p; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3U_GET_BUSINESS_CARD_SOCK); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3U_GET_BUSINESS_CARD_SOCK); MPIDU_CH3U_GetSockInterfaceAddr( myRank, ifname, sizeof(ifname), &ifaddr ); mpi_errno = MPIU_Str_add_int_arg(bc_val_p, val_max_sz_p, MPIDI_CH3I_PORT_KEY, MPIDI_CH3I_listener_port); /* --BEGIN ERROR HANDLING-- */ if (mpi_errno != MPIU_STR_SUCCESS) { if (mpi_errno == MPIU_STR_NOMEM) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard_len"); } else { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard"); } } /* --END ERROR HANDLING-- */ mpi_errno = MPIU_Str_add_string_arg(bc_val_p, val_max_sz_p, MPIDI_CH3I_HOST_DESCRIPTION_KEY, ifname ); /* --BEGIN ERROR HANDLING-- */ if (mpi_errno != MPIU_STR_SUCCESS) { if (mpi_errno == MPIU_STR_NOMEM) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard_len"); } else { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard"); } return mpi_errno; } /* --END ERROR HANDLING-- */ /* Look up the interface address cooresponding to this host description */ /* FIXME: We should start switching to getaddrinfo instead of gethostbyname */ /* FIXME: We don't make use of the ifname in Windows in order to provide backward compatibility with the (undocumented) host description string used by the socket connection routine MPIDU_Sock_post_connect. We need to change to an interface-address (already resolved) based description for better scalability and to eliminate reliance on fragile DNS services. Note that this is also more scalable, since the DNS server may serialize address requests. On most systems, asking for the host info of yourself is resolved locally (i.e., perfectly parallel). Regrettably, not all systems do this (e.g., some versions of FreeBSD). */#if 0#ifndef HAVE_WINDOWS_H { struct hostent *info; char ifname[256]; unsigned char *p; info = gethostbyname( ifname ); if (info && info->h_addr_list) { p = (unsigned char *)(info->h_addr_list[0]); MPIU_Snprintf( ifname, sizeof(ifname), "%u.%u.%u.%u", p[0], p[1], p[2], p[3] ); MPIU_DBG_MSG_S(CH3_CONNECT,VERBOSE,"ifname = %s",ifname ); mpi_errno = MPIU_Str_add_string_arg( bc_val_p, val_max_sz_p, MPIDI_CH3I_IFNAME_KEY, ifname ); if (mpi_errno != MPIU_STR_SUCCESS) { if (mpi_errno == MPIU_STR_NOMEM) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard_len"); } else { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard"); } } } }#endif#endif { char ifname[256]; unsigned char *p; if (ifaddr.len > 0 && ifaddr.type == AF_INET) { p = (unsigned char *)(ifaddr.ifaddr); MPIU_Snprintf( ifname, sizeof(ifname), "%u.%u.%u.%u", p[0], p[1], p[2], p[3] ); MPIU_DBG_MSG_S(CH3_CONNECT,VERBOSE,"ifname = %s",ifname ); mpi_errno = MPIU_Str_add_string_arg( bc_val_p, val_max_sz_p, MPIDI_CH3I_IFNAME_KEY, ifname ); if (mpi_errno != MPIU_STR_SUCCESS) { if (mpi_errno == MPIU_STR_NOMEM) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard_len"); } else { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**buscard"); } } } } if (0) { fprintf( stdout, "business card is %s\n", bc_orig ); fflush(stdout); } fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3U_GET_BUSINESS_CARD_SOCK); return mpi_errno; fn_fail: goto fn_exit;}/* ------------------------------------------------------------------------- *//* Below will be/is the code that is used to create a connection and * to handle changes to the state of a connection. *//* ------------------------------------------------------------------------- */static int connection_post_recv_pkt(MPIDI_CH3I_Connection_t * conn);static int connection_post_send_pkt(MPIDI_CH3I_Connection_t * conn);static int connection_post_send_pkt_and_pgid(MPIDI_CH3I_Connection_t * conn);static int connection_post_sendq_req(MPIDI_CH3I_Connection_t * conn);static void connection_destroy(MPIDI_CH3I_Connection_t * conn);/* This routine is called in response to an MPIDU_SOCK_OP_ACCEPT event in ch3_progress */#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Sockconn_handle_accept_event#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPIDI_CH3_Sockconn_handle_accept_event( void ){ int mpi_errno = MPI_SUCCESS; MPIDI_CH3I_Connection_t * conn; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_ACCEPT_EVENT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_ACCEPT_EVENT); mpi_errno = MPIDI_CH3I_Connection_alloc(&conn); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_POP(mpi_errno); } mpi_errno = MPIDU_Sock_accept(MPIDI_CH3I_listener_conn->sock, MPIDI_CH3I_sock_set, conn, &conn->sock); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER, "**ch3|sock|accept"); } conn->vc = NULL; MPIU_DBG_CONNSTATECHANGE(conn->vc,conn,CONN_STATE_OPEN_LRECV_PKT); conn->state = CONN_STATE_OPEN_LRECV_PKT; conn->send_active = NULL; conn->recv_active = NULL; mpi_errno = connection_post_recv_pkt(conn); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_POP(mpi_errno); } fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_ACCEPT_EVENT); return mpi_errno; fn_fail: goto fn_exit;}#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Sockconn_handle_connect_event#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPIDI_CH3_Sockconn_handle_connect_event( MPIDI_CH3I_Connection_t *conn, int event_error ){ int mpi_errno = MPI_SUCCESS; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_CONNECT_EVENT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_CONNECT_EVENT); /* --BEGIN ERROR HANDLING-- */ if (event_error != MPI_SUCCESS) { /* If the connection fails, conn->vc etc is probably invalid, so we can only report that the connection failed */ mpi_errno = event_error; MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_OTHER,"**ch3|sock|connfailed" ); } /* --END ERROR HANDLING-- */ if (conn->state == CONN_STATE_CONNECTING) { MPIDI_CH3I_Pkt_sc_open_req_t *openpkt = (MPIDI_CH3I_Pkt_sc_open_req_t *)&conn->pkt.type; MPIU_DBG_CONNSTATECHANGE(conn->vc,conn,CONN_STATE_OPEN_CSEND); conn->state = CONN_STATE_OPEN_CSEND; MPIDI_Pkt_init(openpkt, MPIDI_CH3I_PKT_SC_OPEN_REQ); openpkt->pg_id_len = (int) strlen(MPIDI_Process.my_pg->id) + 1; openpkt->pg_rank = MPIR_Process.comm_world->rank; mpi_errno = connection_post_send_pkt_and_pgid(conn); if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } } else { /* CONN_STATE_CONNECT_ACCEPT */ int port_name_tag; MPIDI_CH3I_Pkt_sc_conn_accept_t *acceptpkt = (MPIDI_CH3I_Pkt_sc_conn_accept_t *)&conn->pkt.type; MPIU_Assert(conn->state == CONN_STATE_CONNECT_ACCEPT); MPIU_DBG_CONNSTATECHANGE(conn->vc,conn,CONN_STATE_OPEN_CSEND); conn->state = CONN_STATE_OPEN_CSEND; /* pkt contains port name tag. In memory debugging mode, MPIDI_Pkt_init resets the packet contents. Therefore, save the port name tag and then add it back. */ port_name_tag = acceptpkt->port_name_tag; MPIDI_Pkt_init(acceptpkt, MPIDI_CH3I_PKT_SC_CONN_ACCEPT); acceptpkt->port_name_tag = port_name_tag; mpi_errno = connection_post_send_pkt(conn); if (mpi_errno != MPI_SUCCESS) { MPIU_ERR_SETANDJUMP(mpi_errno,MPI_ERR_INTERN, "**ch3|sock|scconnaccept"); } } fn_exit: MPIDI_FUNC_EXIT(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_CONNECT_EVENT); return mpi_errno; fn_fail: goto fn_exit;}#undef FUNCNAME#define FUNCNAME MPIDI_CH3_Sockconn_handle_close_event#undef FCNAME#define FCNAME MPIDI_QUOTE(FUNCNAME)int MPIDI_CH3_Sockconn_handle_close_event( MPIDI_CH3I_Connection_t * conn ){ int mpi_errno = MPI_SUCCESS; MPIDI_STATE_DECL(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_CLOSE_EVENT); MPIDI_FUNC_ENTER(MPID_STATE_MPIDI_CH3_SOCKCONN_HANDLE_CLOSE_EVENT); /* If the conn pointer is NULL then the close was intentional */ /* FIXME: What does the above comment mean? */ if (conn != NULL) { if (conn->state == CONN_STATE_CLOSING) { MPIU_Assert(conn->send_active == NULL); MPIU_Assert(conn->recv_active == NULL); if (conn->vc != NULL) { MPIDI_CH3I_VC *vcch = (MPIDI_CH3I_VC *)conn->vc->channel_private; MPIU_DBG_VCCHSTATECHANGE(conn->vc,VC_STATE_UNCONNECTED); vcch->state = MPIDI_CH3I_VC_STATE_UNCONNECTED; vcch->sock = MPIDU_SOCK_INVALID_SOCK; /* FIXME: Make sure that this is the correct state for the vc */ /* conn->vc->state = MPIDI_VC_STATE_INACTIVE; */ /* Handle_connection takes care of updating the state on the VC */ mpi_errno = MPIDI_CH3U_Handle_connection(conn->vc, MPIDI_VC_EVENT_TERMINATED); if (mpi_errno) { MPIU_ERR_POP(mpi_errno); } } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -