📄 jnw_datagram.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2001
*
*****************************************************************************/
/*****************************************************************************
*
* Filename:
* ---------
* jnw_datagram.c
*
* Project:
* --------
* Maui_Software
*
* Description:
* ------------
* datagram connection machine dependent API
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
/*************************************************************************
* Include files
*************************************************************************/
#if !defined(__MTK_TARGET__)
/* mdi_datatype.h include MMIDataType.h which conflict with soc_api.h */
#include "Windows.h"
#endif /* !defined(__MTK_TARGET__) */
#include "jal.h"
#include "jam_internal.h"
#include "jnw_internal.h"
#include "jvm_adaptor.h"
#include "app2soc_struct.h"
#include "soc_api.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "task_main_func.h"
#include "app_ltlcom.h"
#include <stdlib.h>
#include <string.h>
/* Network */
#include "soc_api.h"
#include "soc2tcpip_struct.h"
/*************************************************************************
* External Declaration
*************************************************************************/
extern int net_errno;
extern kal_bool j2me_socket_io_activated;
extern int netError(void);
extern kal_int32 readAsyncEvent(kal_int32 handle, kal_int32 dns_idx, kal_uint32 protect);
extern j2me_soc_get_host_by_addr_ind_struct J2ME_async_ghbaddr_ind[];
extern char *g_pcHostName[J2ME_MAX_SOC_NUM];
extern int socketCloseHandle(int handle);
extern void jui_widget_show_connect_icon(void);
extern void jui_widget_hide_connect_icon(void);
extern j2me_soc_notify_ind_struct J2ME_asnyc_ind[];
int _active_datagram_count = 0;
/*************************************************************************
* Function Definition
*************************************************************************/
/*****************************************************************************
* FUNCTION
* _jnw_datagram_gethost_byaddress
* DESCRIPTION
*
* PARAMETERS
* dns_idx [IN] Dns index
* RETURNS
* result
*****************************************************************************/
int _jnw_datagram_gethost_byaddress(int dns_idx)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
int result;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
while (readAsyncEvent(30, dns_idx, KAL_TRUE) != MSG_ID_APP_SOC_GET_HOST_BY_ADDR_IND)
{
return IO_WOULDBLOCK;
}
if (NULL != g_pcHostName[dns_idx])
{
free_ctrl_buffer(g_pcHostName[dns_idx]);
g_pcHostName[dns_idx] = NULL;
}
if (J2ME_async_ghbaddr_ind[dns_idx].result == KAL_TRUE)
{
result = SOC_SUCCESS;
}
else
{
result = SOC_ERROR;
}
return result;
}
/*****************************************************************************
* FUNCTION
* _jnw_datagram_set_nonblocking
* DESCRIPTION
*
* PARAMETERS
* handle [IN]
* RETURNS
* void
*****************************************************************************/
void _jnw_datagram_set_nonblocking(int handle)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_bool falsebuf = KAL_TRUE;
kal_int8 ret;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ret = soc_setsockopt((kal_int8) handle, SOC_NBIO, (kal_uint8*) & falsebuf, sizeof(kal_bool));
if (ret != SOC_SUCCESS)
{
net_errno = ret;
#ifdef MIDP_CONNECTION_DEBUG
sprintf(_kvmLogStr, "J2ME Error: datagram setNonBlocking res=%d", ret);
Kputs(_kvmLogStr);
#endif /* MIDP_CONNECTION_DEBUG */
}
}
/*****************************************************************************
* FUNCTION
* is_datagram_activated
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* kal_bool
*****************************************************************************/
kal_bool is_datagram_activated(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (_active_datagram_count != 0)
{
return KAL_TRUE;
}
else
{
return KAL_FALSE;
}
}
/*****************************************************************************
* FUNCTION
* jnw_datagram_open
* DESCRIPTION
*
* PARAMETERS
* port [IN]
* exception [OUT]
* RETURNS
* int
*****************************************************************************/
int jnw_datagram_open(int port, int *exception)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int8 handle;
kal_int8 ret;
kal_uint8 option;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* important! use this comparison to block the case to connect CSD when
Java in paused mode or background running */
*exception = JNW_SOC_ERROR_DEFAULT;
handle = soc_create(PF_INET, SOCK_DGRAM, 0, MOD_JASYN, J2ME_active_nw_acc_id);
if (handle < 0)
{
*exception = JNW_SOC_ERROR_OPEN_FAIL;
net_errno = handle;
return -1;
}
J2ME_asnyc_ind[handle].error_cause = 0;
resouceRegistering(JAVA_IO_DATAGRAM_DEVICE, handle, NULL, NULL, &socketCloseHandle);
j2me_socket_io_activated = KAL_TRUE;
/* Set ansync mode */
option = SOC_READ | SOC_WRITE | SOC_ACCEPT | SOC_CONNECT | SOC_CLOSE;
ret = soc_setsockopt(handle, SOC_ASYNC, &option, sizeof(kal_uint8));
if (ret != SOC_SUCCESS)
{
net_errno = ret;
#ifdef MIDP_CONNECTION_DEBUG
sprintf(_kvmLogStr, "J2ME Error: open0 datagram async res=%d", ret);
Kputs(_kvmLogStr);
#endif /* MIDP_CONNECTION_DEBUG */
soc_close(handle);
*exception = JNW_SOC_ERROR_ARGUMENT;
return -1;
}
_active_datagram_count++;
jui_widget_show_connect_icon();
#ifdef MIDP_CONNECTION_DEBUG
kal_trace(TRACE_INFO, J2ME_MSG1, port, ret);
#endif /* INCLUDEDEBUGCODE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -