|
在展讯6531D上创建一个socket连接,pap激活成功,创建socket也是成功,但是socket连接的时候,返回-1,错误代码为22.
请大神帮帮忙,看看是不是哪里出问题了。
代码如下:
#define TEST_URL_PORT 18000
#define TEST_URL_ADDRESS "223.4.58.68"
//创建调度
Socket int TEST_OpenSocket(void)
{
struct sci_sockaddr server_addr; unsigned short port = TEST_URL_PORT; /* port number */
int taiduSockfd = -1;
int ret = 0; //初始化socket
if((taiduSockfd = sci_sock_socket(AF_INET,SOCK_STREAM,0,taiodu_net_id)) == -1)
{
SCI_TRACE_LOW("TEST_OpenSocket:Socket Error, %d\n", sci_sock_errno((long)-1));
goto SocketError;
}
SCI_TRACE_LOW("TEST_OpenSocket:Socket = %d\n", taiduSockfd);
#ifdefined(NBIO_RECV)
sci_sock_setsockopt(taiduSockfd,SO_NBIO, NULL);
#endif //链接
server_addr.family = AF_INET;
server_addr.port = htons(port);
server_addr.ip_addr = inet_addr(TEST_URL_ADDRESS);
SCI_TRACE_LOW("TEST_OpenSocket:begin sci_sock_connect!! \n");
SCI_TRACE_LOW("TEST_OpenSocket:server_addr.port=%d!! \n",server_addr.port);
SCI_TRACE_LOW("TEST_OpenSocket:server_addr.ip_addr=%d!! \n",server_addr.ip_addr);
SCI_TRACE_LOW("TEST_OpenSocket:sizeof(server_addr)=%d!! \n",sizeof(server_addr));
ret = sci_sock_connect(taiduSockfd,&server_addr,sizeof(server_addr)) ;
SCI_TRACE_LOW("TEST_OpenSocket:ret , %d\n", ret );
SCI_TRACE_LOW("TEST_OpenSocket:ret=%d!! \n",ret);
if(ret == -1)
{
SCI_TRACE_LOW("TEST_OpenSocket:Connect Error, %d\n", sci_sock_errno(taiduSockfd)); goto SocketError; }
SCI_TRACE_LOW("TEST_OpenSocket:Socket connect success!!");
return taiduSockfd;
SocketError:
sci_sock_socketclose(taiduSockfd);
return -1;
}
//TEST cmnet 回调函数
LOCAL void HandlePDPTESTMsg(MMIPDP_CNF_INFO_T *msg_ptr)
{
if(PNULL == msg_ptr)
{
return;
}
SCI_TRACE_LOW("[MMIMMS]:HandlePDPTESTMsg msg_id=%d",msg_ptr->msg_id);
switch(msg_ptr->msg_id)
{
case MMIPDP_ACTIVE_CNF:
taiodu_net_id = msg_ptr->nsapi;
SCI_TRACE_LOW("+++++++HandlePDPTESTMsg,case MMIPDP_ACTIVE_CNF,taiodu_net_id :%ld",taiodu_net_id);
TEST_OpenSocket();
// MMK_PostMsg(MAIN_IDLE_WIN_ID, MSG_TEST_NETLINK_SUCCESS, PNULL,0); //发送网络激活成功 break;
case MMIPDP_DEACTIVE_CNF:
break;
case MMIPDP_DEACTIVE_IND:
SCI_TRACE_LOW("+++++++HandlePDPMsg: MMIPDP_DEACTIVE_IND");
//MMK_PostMsg(MAIN_IDLE_WIN_ID, MSG_TEST_NETLINK_DISCONNECT, PNULL,0); //发送网络断开 break;
default:
break;
}
//SCI_FREE(msg_ptr);
}
//打开cmnet
BOOLEAN openTESTNet(void)
{
MMIPDP_ACTIVE_INFO_T active_info = {0};
char apn_ptr[10] = {0};//apn string
BOOLEAN ret = FALSE;
strcpy(apn_ptr,"cmnet");
if (MMIPHONE_IsSimAvailable(0))//判断飞行模式
{
SCI_TRACE_LOW("openTESTNet");
active_info.dual_sys = 0;
active_info.auth_type = 1;
active_info.priority = 3;
active_info.app_handler = MMI_MODULE_COMMON;
active_info.handle_msg_callback = HandlePDPTESTMsg;
active_info.apn_ptr = apn_ptr;
active_info.ps_service_rat = MN_TD_PREFER;
MNGPRS_ReadStorageExtReqQosEx(active_info.dual_sys,MN_GPRS_STORAGE_ALL,BROWSER_E,&active_info.qos_info);
ret =MMIAPIPDP_Active(&active_info);
}
else
{
SCI_TRACE_LOW("openTESTNet sim is not available");
}
SCI_TRACE_LOW("openTESTNet :MMIAPIPDP_Active = %d!", ret);
return ret;
}
|
|