MTKSOCKET编程死机
如下代码接收服务器端发来得数据,这样接收一次后手机就死掉。局部变量的数组也有问题?不是很明白
#define SOCKET_BUF_SIZE 1500
socReceive()
{
unsigned char buf[SOCKET_BUF_SIZE];
int soc_ret =0;
memset(buf, 0, sizeof(buf));
soc_ret = soc_recv(soc_id, buf, sizeof(buf), 0);
......
}
数组buf应该是使用完后跳出函数后就释放了,为什么会卡死,不太明白,现在改为内存分配的方式来接收数据,OK
不会出现卡死现象,如下:
#define SOCKET_BUF_SIZE 1500
unsigned char* buf= (unsigned char*)OslMalloc(sizeof(unsigned char)*SOCKET_BUF_SIZE);
int soc_ret =0;
memset(buf, 0, sizeof(unsigned char)*SOCKET_BUF_SIZE);
soc_ret = soc_recv(soc_id, buf, sizeof(unsigned char)*SOCKET_BUF_SIZE, 0);
dbg_print("GXT:receive len = %d \r\n",soc_ret);
。。。
OslMfree(buf);