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

📄 sockettest.c

📁 MTK联网
💻 C
📖 第 1 页 / 共 2 页
字号:
			test_soc_demo_transaction->snd_data_len+=2;

			
			strcat((char*)test_soc_demo_transaction->snd_buffer,CRLF);
			test_soc_demo_transaction->snd_data_len+=2; 


	
			kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:\n %s", test_soc_demo_transaction->snd_buffer);
			kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:\n %s", &test_soc_demo_transaction->snd_buffer[60]);
			kal_prompt_trace(MOD_WAP, "test_soc_demo_transaction->snd_buffer:\n %s", &test_soc_demo_transaction->snd_buffer[120]);

#ifdef MMI_ON_HARDWARE_P
			kal_prompt_trace(MOD_WAP, "___________________ Http connect to %d.%d,%d,%d and port: %d",
				test_soc_demo_transaction->server_ip_addr.addr[0],
				test_soc_demo_transaction->server_ip_addr.addr[1],
				test_soc_demo_transaction->server_ip_addr.addr[2],
				test_soc_demo_transaction->server_ip_addr.addr[3],
				test_soc_demo_transaction->server_ip_addr.port);
	   
			ret = soc_connect(test_soc_demo_transaction->socket_id, &test_soc_demo_transaction->server_ip_addr);
	 
			kal_prompt_trace(MOD_WAP, "___________________ Http connect result is %d", ret);
#endif 
			if (ret == SOC_SUCCESS)
			{
				test_en_soc_demo_http_send_request();
				return EN_SOC_SUCCESS;
			}
			else if (ret == SOC_WOULDBLOCK)
			{
				SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
				return EN_SOC_SUCCESS;
			}
			else
			{
				if (ret == SOC_ERROR)
				{
					return EN_SOC_PEER_NOT_REACHABLE;
				}
				else
				{
					return EN_SOC_ERROR;
				}
			}
		}
		else if (test_soc_demo_transaction->state == HTTP_TCP_CON_CREATED || test_soc_demo_transaction->state == REQ_SEND_RETRY ||
				 test_soc_demo_transaction->state == REQ_SENDING)
		{
			kal_int32 ret;

			if (test_soc_demo_transaction->state != REQ_SENDING)
			{
				test_soc_demo_transaction->snd_counter = 0;
			}
			test_soc_demo_transaction->state = REQ_SENDING;
#ifdef MMI_ON_HARDWARE_P
			kal_prompt_trace(MOD_WAP, "___________________ Http send request to %d.%d,%d,%d and port: %d",
				test_soc_demo_transaction->server_ip_addr.addr[0],
				test_soc_demo_transaction->server_ip_addr.addr[1],
				test_soc_demo_transaction->server_ip_addr.addr[2],
				test_soc_demo_transaction->server_ip_addr.addr[3],
				test_soc_demo_transaction->server_ip_addr.port);
#endif /* MMI_ON_HARDWARE_P */ 
			ret = soc_send(
					test_soc_demo_transaction->socket_id,
					(kal_uint8*) (test_soc_demo_transaction->snd_buffer + test_soc_demo_transaction->snd_counter),
					(test_soc_demo_transaction->snd_data_len - test_soc_demo_transaction->snd_counter),
					0);
#ifdef MMI_ON_HARDWARE_P
			kal_prompt_trace(MOD_WAP, "___________________ Http send request result, sent_bytes:%d", ret);
#endif 
			if (ret > 0)
			{
				if (ret == (kal_int32) test_soc_demo_transaction->snd_data_len)
				{
					test_soc_demo_transaction->state = REQ_SENT;
					test_soc_demo_transaction->post_retry_counter++;
					tst_em_soc_demo_app_start_timer();	/* wait for servwer's response */
					tst_en_soc_demo_tcp_app_recv_response();
					return EN_SOC_SUCCESS;
				}
				else
				{
					test_soc_demo_transaction->snd_counter += ret;
					return EN_SOC_SUCCESS;
				}
			}
			else
			{
				if (ret == SOC_WOULDBLOCK)
				{
					/* waits for socket notify */
					SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
					return EN_SOC_SUCCESS;
				}
				else
				{
					if (ret == SOC_ERROR)
					{
						return EN_SOC_PEER_NOT_REACHABLE;
					}
					else
					{
						return EN_SOC_ERROR;
					}
				}
			}
		}
		else
		{
			return EN_SOC_ERROR;
		}
	}
	else
	{
		return EN_SOC_ERROR;
	}
}



void test_em_soc_demo_app_socket_notify(void *inMsg)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/
	app_soc_notify_ind_struct *soc_notify = (app_soc_notify_ind_struct*) inMsg;

	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/
	kal_prompt_trace(MOD_WAP," entry the function test_em_soc_demo_app_socket_notify");
	
	if (!test_soc_demo_transaction)
	{
		return;
	}
#ifdef MMI_ON_HARDWARE_P
	kal_prompt_trace(MOD_WAP, "___________________ Got socket notify, event_type:%d", soc_notify->event_type);
#endif 
	switch (soc_notify->event_type)
	{
		case SOC_WRITE:
		{
			switch (test_soc_demo_transaction->soc_demo_app_id)
			{
				case HTTP:
					test_en_soc_demo_http_send_request();
					break;
				case DAYTIME:
				case ECHO:
					break;
				case TRACERT:
					break;
			}
			break;
		}
		case SOC_READ:
		{
			switch (test_soc_demo_transaction->soc_demo_app_id)
			{
				case HTTP:
					tst_en_soc_demo_tcp_app_recv_response();
					break;
				case DAYTIME:
				case ECHO:
					break;
				case TRACERT:
					if ( test_soc_demo_transaction->state != REQ_SENT)
					{
					}
					else
					{
					}
					break;
			}
			break;
		}
		case SOC_CONNECT:
		{
			if (test_soc_demo_transaction->soc_demo_app_id == HTTP)
			{
				if (soc_notify->result == KAL_TRUE)
				{
					test_soc_demo_transaction->state = HTTP_TCP_CON_CREATED;
					test_en_soc_demo_http_send_request();
				}
				else
				{
					kal_prompt_trace(MOD_WAP," SOC_CONNECT ____________________ ERROR");
				}
			}
			break;
		}
		case SOC_CLOSE:
		{
			kal_prompt_trace(MOD_WAP,"soc_demo_transaction->rcvd_counter:%d",test_soc_demo_transaction->rcvd_counter);
			kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction->rcvd_buffer:\n%s",test_soc_demo_transaction->rcvd_buffer);
		}
		default:
			break;
	}
}

void tst_em_soc_demo_app_start_timer(void)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/

	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/
	StartTimer(EM_GPRS_SOC_DEMO_APP_TIMER, SOC_DEMO_APP_POST_TIMEOUT, tst_em_soc_demo_app_timer_handler);
	
}

void tst_em_soc_demo_app_timer_handler(void)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/

	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/
	if (test_soc_demo_transaction->post_retry_counter < MAX_POST_RETRY_NUM)
	{
		test_soc_demo_transaction->state = REQ_SEND_RETRY;
		switch (test_soc_demo_transaction->soc_demo_app_id)
		{
			case HTTP:
				test_en_soc_demo_http_send_request();
				break;
			case DAYTIME:
			case ECHO:
				break;
			default:
				break;
		}
	}
	else
	{
	}
}


void tst_en_soc_demo_tcp_app_recv_response(void)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/
	   int i = 0;
	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/
	if (test_soc_demo_transaction && test_soc_demo_transaction->state < RSP_RCVD)
	{
        int ret_val = 0;

        test_soc_demo_transaction->state = RSP_RCVING;
		do{
			
			  ret_val = soc_recv(
                    test_soc_demo_transaction->socket_id,
                    (kal_uint8*) (test_soc_demo_transaction->rcvd_buffer + test_soc_demo_transaction->rcvd_counter),
                    (MAX_RCV_BUFFER_SIZE - test_soc_demo_transaction->rcvd_counter),
                    0);
			   test_soc_demo_transaction->rcvd_counter += ret_val;
			   
			 kal_prompt_trace(MOD_WAP,"tst_en_soc_demo_tcp_app_recv_response--ret_val[%d]",ret_val);
			 kal_prompt_trace(MOD_WAP," test_soc_demo_transaction->rcvd_counter [%d]", test_soc_demo_transaction->rcvd_counter );
			}while(ret_val>0);
		
		if (ret_val == SOC_WOULDBLOCK)
	  	{
		  SetProtocolEventHandler(test_em_soc_demo_app_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
		  test_soc_demo_transaction->rcvd_counter += 2;
		  return;
	 	}
		else
		tst_en_soc_output_result(
                EN_SOC_SUCCESS,
                (char*)test_soc_demo_transaction->rcvd_buffer,
                test_soc_demo_transaction->rcvd_counter);
    }
}

void tst_en_soc_show_output_string()
{


    U8 *guiBuffer, *info;
    U8 showbuff[1000];
    memset(showbuff,0,sizeof(showbuff));	

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    guiBuffer = GetCurrGuiBuffer(ORGANIZER_SOCKET_SHOW);
    EntryNewScreen(ORGANIZER_SOCKET_SHOW, NULL,  tst_en_soc_show_output_string, NULL);



     AnsiiToUnicodeString((S8 *)showbuff,(S8 *)test_soc_demo_transaction->rcvd_buffer);

     kal_prompt_trace(MOD_WAP,"entry tst_en_soc_show_output_string");
     kal_prompt_trace(MOD_WAP,"the vaule of showbuff is %s",test_soc_demo_transaction->rcvd_buffer);
     kal_prompt_trace(MOD_WAP,"the length of showbuff is %d",test_soc_demo_transaction->rcvd_counter);


    ShowCategory74Screen(
        0,
        0,
        0,
        0,
        STR_GLOBAL_BACK,
        IMG_GLOBAL_BACK,
        (PU8) showbuff,
        test_soc_demo_transaction->rcvd_counter * 2,
        guiBuffer);
    
    SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
    SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);



}


void tst_en_soc_output_result(int ret, char *out_str, int len)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/

	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/

	
	if (test_soc_demo_transaction)
	{
#ifdef MMI_ON_HARDWARE_P
		kal_prompt_trace(MOD_WAP, "soc demp app result: %d", ret);
		kal_prompt_trace(MOD_WAP, "the value of out_str is %s\n",out_str);


		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 1 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 100));
		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 2 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 200));

		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 3 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 300));
		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 4 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 400));
		
		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 5 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 500));
		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 6 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 600));

		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 7 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 700));
		kal_prompt_trace(MOD_WAP,"test_soc_demo_transaction 8 is %s\n",(test_soc_demo_transaction->rcvd_buffer + 800));


	//	tst_en_soc_show_output_string();
		
#endif 
		if(test_soc_demo_transaction->callback != NULL)//wangdecheng add
		{
			test_soc_demo_transaction->callback(test_soc_demo_transaction->soc_demo_app_id, ret, out_str, len);
		}
		if (ret != EN_SOC_SUCCESS)
		{
			test_soc_demo_transaction->state = SOC_CLOSING;
		}
		tst_mmi_soc_demo_app_request_abort();
	}
}

int tst_mmi_soc_demo_app_request_abort(void)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/

	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/
	if (test_soc_demo_transaction)
	{
		if (test_soc_demo_transaction->socket_id >= 0)
		{
    #ifdef MMI_ON_HARDWARE_P
			ilm_struct *ilm_send = NULL;
    #endif 
    #ifndef MMI_ON_WIN32
			soc_close(test_soc_demo_transaction->socket_id);
			soc_close_nwk_account_by_id(MOD_MMI,test_soc_demo_transaction->nwt_acount_id);
    #endif
    #ifdef MMI_ON_HARDWARE_P
			/* close socket and disconnect bearer here */
			ilm_send = allocate_ilm(MOD_MMI);
			ilm_send->msg_id = MSG_ID_APP_SOC_DEACTIVATE_REQ;
			ilm_send->peer_buff_ptr = NULL;
			ilm_send->local_para_ptr = NULL;
			SEND_ILM(MOD_MMI, MOD_SOC, SOC_APP_SAP, ilm_send);
    #endif /* MMI_ON_HARDWARE_P */ 
		}
		test_soc_demo_transaction->post_retry_counter = 0;
		if (test_soc_demo_transaction->url)
		{
			OslMfree(test_soc_demo_transaction->url);
		}
		/* We have to free recv_buffer. */
		if (test_soc_demo_transaction->rcvd_buffer)
		{
			OslMfree(test_soc_demo_transaction->rcvd_buffer);
		}
		if (test_soc_demo_transaction->snd_buffer)
		{
			OslMfree(test_soc_demo_transaction->snd_buffer);
		}
		if (test_soc_demo_transaction->url_parsed_info)
		{
			if (test_soc_demo_transaction->url_parsed_info->host_name)
			{
				OslMfree(test_soc_demo_transaction->url_parsed_info->host_name);
			}
			if (test_soc_demo_transaction->url_parsed_info->url_link)
			{
				OslMfree(test_soc_demo_transaction->url_parsed_info->url_link);
			}
			OslMfree(test_soc_demo_transaction->url_parsed_info);
		}
		tst_em_soc_demo_app_stop_timer();
		OslMfree(test_soc_demo_transaction);
		test_soc_demo_transaction = NULL;
		 kal_prompt_trace(MOD_WAP,"###########################Transaction have been destroy!!");
		 
	}
	return 0;
}

void tst_em_soc_demo_app_stop_timer(void)
{
	/*----------------------------------------------------------------*/
	/* Local Variables												  */
	/*----------------------------------------------------------------*/

	/*----------------------------------------------------------------*/
	/* Code Body													  */
	/*----------------------------------------------------------------*/
	StopTimer(EM_GPRS_SOC_DEMO_APP_TIMER);
}




⌨️ 快捷键说明

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