⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jnw_socket.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 5 页
字号:
                g_pcHostName[ori_dns_idx] = NULL;
            }

            return SOC_SUCCESS; /* SUCCESS */
        }
        else
        {
            /* It might be SOC_ERROR or BEARER_FAIL. and I add a IF case to handle BEARER_FAIL. */
            if (SOC_BEARER_FAIL == J2ME_async_ghbn_ind[ori_dns_idx].error_cause)
            {
                /* Actually, we do not have to set this variable to TRUE, I set this just in case we have to check 
                   this variable under some circustance in the future. */
                g_bNeedBearerfallback = KAL_TRUE;

                /* The follow ELSE-IF case is for Bearer Fallback Handling, it's wel-commented. Other part that does similar Bearer Fallback
                   handling should reference the comments here. */

                /*
                 * Bearer fallback handling here.
                 * We handle bearer fallback only when:
                 * 1. We receive SOC_BEARER_FAIL from SOC.
                 * 2. Current active NW ID is GPRS NW ID. 
                 * 3. CSD NW ID is a valid ID.
                 */

                /* if the fallback is failed, we switch back to GPRS account */
                if ((KAL_TRUE == g_bNeedBearerfallback) && (J2ME_current_active_nw_id == J2ME_active_nw_acc_id_CSD))
                {
                    J2ME_current_active_nw_id = J2ME_active_nw_acc_id;
                }
                else if ((KAL_TRUE == g_bNeedBearerfallback) &&
                         (J2ME_current_active_nw_id == J2ME_active_nw_acc_id) && (J2ME_active_nw_acc_id_CSD != 255))
                {
                    /* This happens when we polling this function, and we get IO_WOULDBLOCK several times, but finally
                       we get the SOC_BEARER_FAIL. Under this situation, we will do bearer fallback handling. */

                    l_i4DialogSelectedItem = get_bearer_fallback_user_confirm();

                    if (J2ME_GET_NEXT_EVENT_ABORT == l_i4DialogSelectedItem)
                    {
                    }
                    else if (KAL_FALSE == l_i4DialogSelectedItem)
                    {
                    }
                    else if (KAL_TRUE == l_i4DialogSelectedItem)
                    {

                        J2ME_current_active_nw_id = J2ME_active_nw_acc_id_CSD;

                        ASSERT(g_pcHostName[ori_dns_idx] != NULL);
                        ipn = prim_com_sun_midp_io_j2me_socket_Protocol_getIpNumber(g_pcHostName[ori_dns_idx], dns_idx);

                        if (g_pcHostName[ori_dns_idx] != NULL)
                        {
                            free_ctrl_buffer(g_pcHostName[ori_dns_idx]);
                            g_pcHostName[ori_dns_idx] = NULL;
                        }

                        if (ipn == SOC_ERROR || ipn == SOC_INVAL)
                        {
                        #ifdef MIDP_CONNECTION_DEBUG
                            sprintf(_kvmLogStr, "J2ME Error: getIpNumber failed ipn=%d", ipn);
                            Kputs(_kvmLogStr);
                        #endif /* MIDP_CONNECTION_DEBUG */ 

                            /* Switch back to GPRS ID. */
                            J2ME_current_active_nw_id = J2ME_active_nw_acc_id;
                            g_bNeedBearerfallback = KAL_FALSE;

                            /* Modify the return error code to make JNW interface remain the same. */
                            ipn = SOC_ERROR;

                            return ipn;
                        }
                        else if (ipn == SOC_WOULDBLOCK)
                        {
                            /* We do not have to record the HostName again because we'll never do 
                               Bearer Fallback again. */

                        #ifdef MIDP_CONNECTION_DEBUG
                            sprintf(_kvmLogStr, "J2ME Error: getIpNumber wouldblock");
                            Kputs(_kvmLogStr);
                        #endif /* MIDP_CONNECTION_DEBUG */ 

                            g_bNeedBearerfallback = KAL_FALSE;

                            return ipn;
                        }
                        else
                        {
                            g_bNeedBearerfallback = KAL_FALSE;

                            return SOC_SUCCESS;
                        }
                    }

                }

                if (g_pcHostName[ori_dns_idx] != NULL)
                {
                    free_ctrl_buffer(g_pcHostName[ori_dns_idx]);
                    g_pcHostName[ori_dns_idx] = NULL;
                }
                
                /* Reset this variable in case we have a invalid CSD ID or we are currently use CSD ID. */
                g_bNeedBearerfallback = KAL_FALSE;

                /*
                 * When we reach here, it must be:
                 * 1. User says NO or User presses END to Bearer Fallback.
                 * 2. We have a invalid CSD ID and therefore we do not do Bearer Fallback.
                 * 3. We are currently use CSD ID and therefore we do not do Bearer Fallback. 
                 */
                return SOC_ERROR;

            }
            else
            {
                if (g_pcHostName[ori_dns_idx] != NULL)
                {
                    free_ctrl_buffer(g_pcHostName[ori_dns_idx]);
                    g_pcHostName[ori_dns_idx] = NULL;
                }

                return SOC_ERROR;
            }
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  jnw_network_initialize
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void jnw_network_initialize(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int8 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!net_initialized)
    {
        _active_socket_count = 0;
        _active_datagram_count = 0;

        kal_take_mutex(J2ME_async_mutex);
        kal_mem_set(J2ME_asnyc_ind, 0, sizeof(J2ME_asnyc_ind));
        kal_mem_set(J2ME_blockedasnyc_ind, 0, sizeof(J2ME_asnyc_ind));
    #ifdef __JAVA_SUPPORT_SERVER_SOCKET__
        kal_mem_set(J2ME_wait_bearer, 0, sizeof(J2ME_wait_bearer));
    #endif
        kal_mem_set(J2ME_async_ghbn_ind, 0, sizeof(J2ME_async_ghbn_ind));
        
        J2ME_pendingasyn_bitmap = J2ME_setasyn_bitmap = 0;
        J2ME_dns_setasyn_bitmap = J2ME_blockedasyn_bitmap = 0;
        /* initialize the callback function table */
        J2ME_asyn_table.bearer_callback = NULL;
        J2ME_asyn_table.gethostbyaddr_callback = NULL;
        J2ME_asyn_table.gethostbyname_callback = NULL;
        J2ME_asyn_table.notify_callback = NULL;

        for (i=0; i<J2ME_MAX_SOC_NUM; i++)
        {
            g_pcHostName[i] = NULL;
        }

        kal_give_mutex(J2ME_async_mutex);
        if (!soc_get_csd_auto_disconnect_timer(&csd_disconnect_time))
        {
            csd_disconnect_time = 0;
        }
        else
        {
            set_java_csd_timing();
        }
        net_initialized = KAL_TRUE;
    }
}


/*****************************************************************************
 * FUNCTION
 *  jnw_network_finalize
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void jnw_network_finalize(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (net_initialized)
    {
        kal_take_mutex(J2ME_async_mutex);
        kal_mem_set(J2ME_asnyc_ind, 0, sizeof(J2ME_asnyc_ind));
        kal_mem_set(J2ME_blockedasnyc_ind, 0, sizeof(J2ME_asnyc_ind));
    #ifdef __JAVA_SUPPORT_SERVER_SOCKET__
        kal_mem_set(J2ME_wait_bearer, 0, sizeof(J2ME_wait_bearer));
    #endif
        kal_mem_set(J2ME_async_ghbn_ind, 0, sizeof(J2ME_async_ghbn_ind));
        
        J2ME_pendingasyn_bitmap = J2ME_setasyn_bitmap = 0;
        J2ME_dns_setasyn_bitmap = J2ME_blockedasyn_bitmap = 0;
        kal_give_mutex(J2ME_async_mutex);
        restore_java_csd_timing();
        net_initialized = KAL_FALSE;
    }

}


/*****************************************************************************
 * FUNCTION
 *  jnw_register_callback
 * DESCRIPTION
 *  register the callback function based on type
 * PARAMETERS
 *  type                [IN]        Register type
 *  callback_ptr        [IN]        Callback function
 * RETURNS
 *  void
 *****************************************************************************/
void jnw_register_callback(jnw_soc_asyn_ind_enum type, java_async_callback_fn callback_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (type)
    {
        case J2ME_NOTIFY_IND:
            J2ME_asyn_table.notify_callback = callback_ptr;
            break;

        case J2ME_HOST_NAME:
            J2ME_asyn_table.gethostbyname_callback = callback_ptr;
            break;

        case J2ME_HOST_ADDR:
            J2ME_asyn_table.gethostbyaddr_callback = callback_ptr;
            break;

        case J2ME_BEARER_INFO:
            J2ME_asyn_table.bearer_callback = callback_ptr;
            break;

        default:
            kal_trace(TRACE_ERROR, J2ME_MSG19, type);
            break;
    }

    return;
}


/*****************************************************************************
 * FUNCTION
 *  jnw_deregister_callback
 * DESCRIPTION
 *  
 * PARAMETERS
 *  type        [IN]        Deregister type
 * RETURNS
 *  void
 *****************************************************************************/
void jnw_deregister_callback(jnw_soc_asyn_ind_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (type)
    {
        case J2ME_NOTIFY_IND:
            J2ME_asyn_table.notify_callback = NULL;
            break;

        case J2ME_HOST_NAME:
            J2ME_asyn_table.gethostbyname_callback = NULL;
            break;

        case J2ME_HOST_ADDR:
            J2ME_asyn_table.gethostbyaddr_callback = NULL;
            break;

        case J2ME_BEARER_INFO:
            J2ME_asyn_table.bearer_callback = NULL;
            break;

        default:
            kal_trace(TRACE_ERROR, J2ME_MSG19, type);
            break;
    }

    return;
}


/*****************************************************************************
 * FUNCTION
 *  jnw_get_errno
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  int
 *****************************************************************************/
int jnw_get_errno(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    int result = net_errno;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    net_errno = 0;
    return result;
}


/*****************************************************************************
 * FUNCTION
 *  process_soc_async_ind
 * DESCRIPTION
 *  Called by main while message loop of JDaemon to process incoming message from SOC
 * PARAMETERS
 *  ilm_ptr     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void process_soc_async_ind(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef __JAVA_SUPPORT_SERVER_SOCKET__
    kal_int8 i;
#endif
    kal_int32 handle = -1;
    kal_int16 dns_idx = -1;
    kal_bool in_blocked = KAL_FALSE;
    kal_bool suspend = KAL_FALSE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (ilm_ptr->msg_id)
    {
        case MSG_ID_APP_SOC_NOTIFY_IND:
        {
            app_soc_notify_ind_struct *ind_ptr = (app_soc_notify_ind_struct*) ilm_ptr->local_para_ptr;

            handle = ind_ptr->socket_id;
            ASSERT(handle < 31 && handle >= 0);

            if (ind_ptr->event_type == SOC_CLOSE && ind_ptr->error_cause == SOC_CONNRESET)
            {
                /* half close for write end" from server. 
                   This stands for "server won't send data to client anymore */
                return;
            }

            /* if previous event is connect indication and not processed (by jnw), 
               we need to suspend process for a while */
            /* Otherwise, we will lose the indication. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -