使用select去读串口数据,监听端口的时候,select阻塞了....鼠标卡住不动了?
本帖最后由 鬼鬼一哈 于 2011-11-08 10:25 编辑不过数据还是能接受的到了,就是在限定时间内,鼠标不能用,超时后就又可以用了。如何解决select阻塞的问题?程序读写代码如下:
if( write (gprs_fd, gsm_data,71) == 71)
{
fd_set inset;
FD_ZERO(&inset);
FD_SET(gprs_fd, &inset );
struct timeval tv;
tv.tv_sec = 24;
tv.tv_usec = 0;
memset(buff,0,2048 );
while(1)
{
int res = select(gprs_fd+ 1, &inset, NULL, NULL, &tv );
switch(res)
{
case -1:
{
printf("Select error\n" );
}
break;
case 0: /* Timeout */
{
printf("Time out\n" );
return 0;
}
break;
default:
{
if(FD_ISSET(gprs_fd, &inset))
{
int real_read = read(gprs_fd, buff, 2048 );
if (real_read < 0) printf("read err\n" );
else printf("%s",buff );
}
}
break;
}
} 本帖最后由 鬼鬼一哈 于 2011-11-08 11:26 编辑
多线程加阻塞,貌似挺好使的哈。。嘎嘎。。。ok啦! select阻塞时是不是程序一直停在select函数中,请问又是如何解决的,多线程+阻塞 应该是停在select那里 等待你监听的事件!
页:
[1]