ChinaUnix.net
相关文章推荐:

read完数据 没有阻塞

read 的两种情况,为什么第一中不阻塞,第二种阻塞? /********************** 情况1 *************************/ #include #include #include #include #define MAXLINE 5000 int main(void) { int n; char line[MAXLINE]; int fd = open("dump", O_RDONLY); while (1){ n = read(fd, line, MAXLINE); if (0 > n){ printf("read error\n")...

by vivian2086 - C/C++ - 2009-10-15 19:52:32 阅读(1240) 回复(3)

相关讨论

#include #include #include #include #include #include #define MAXLINE 1024 #define MMFCPORT 80 int main(int argc,char *argv[]){ struct sockaddr_in srv; int sock, nbytes; if((sock = socket(AF_INET,SOCK_STREAM,0))==-1){ fprintf(stderr, "socket() error! %s \n",strerror(errno)); exit(1); ...

by mmxcq - C/C++ - 2010-05-18 11:27:34 阅读(5439) 回复(15)

服务器端应该是用.net写的 我客户端去读取数据 代码段1:[code]Bufferedreader in = new Bufferedreader(new InputStreamreader( socket.getInputStream())); int n = 0; while ((n = in.read()) > 0) { char c = (char)n; System.out.print((char) n); } System.out.println("end");[/code]代码段2:[code]DataInputStream in = new DataInputStream(socket.getInputStream()); byte[] buf = new byte[1024...

by bellszhu - Java - 2012-09-07 13:23:02 阅读(2806) 回复(1)

不能用非阻塞打开设备文件。现在想要read在1秒内读不到数据,就返回,如何做呀? 请各位提示提示。。

by haoyue - 程序开发 - 2006-12-25 17:06:27 阅读(2266) 回复(11)

不能用非阻塞打开设备文件。现在想要read在1秒内读不到数据,就返回,如何做呀? 请各位提示提示。。

by haoyue - Linux环境编程 - 2006-12-25 17:06:27 阅读(6752) 回复(11)

:shock:调用read函数读串口,等到真正读到数据后才返回。现在想让其没有读到数据就返回,怎么做?

by zhpzh - 程序开发 - 2006-03-22 18:08:11 阅读(1242) 回复(7)

:shock:调用read函数读串口,等到真正读到数据后才返回。现在想让其没有读到数据就返回,怎么做?

by zhpzh - Linux环境编程 - 2006-03-22 18:08:11 阅读(3217) 回复(7)

我希望一个在需要结束一个线程的时候, 能让它从阻塞read()处很快的返回。 怎么样做到这一点呢, 不能用pthread_cancel, read()返 回后做一点处理再正常的退出线程。

by oatmeal3000 - Linux环境编程 - 2009-11-21 16:41:52 阅读(2449) 回复(3)

一直以为你和阻塞send一样,没成任务,绝不回来。 没想到,你是这样容易满足,一个字节就能让你屁颠屁颠的回来,哪怕你的任务是1000,100,你和非阻塞read 只有一个字节的区别而已。 难道是我误解了阻塞 read,我希望我误解他了。有谁和我一样,也被欺骗过,说说。或者告诉我,我的确误解阻塞read

by learntolinux - C/C++ - 2009-06-18 14:59:07 阅读(3414) 回复(11)

该程序是APUE2第14章程序清单14-1 [code] #include "head.h" char buf[500000]; int main(int argc, char** argv) { int nwrite, ntowrite; char *ptr = NULL; ntowrite = read(STDIN_FILENO, buf, sizeof(buf)); fprintf(stderr, "read %d bytes\n", ntowrite); set_fl(STDOUT_FILENO, O_NONBLOCK); ptr = buf; ...

by xiaozhu2007 - C/C++ - 2008-01-15 23:54:41 阅读(11581) 回复(4)

read()阻塞的读套接字时,应该只有对方断开连接才会返回0; 但是我在一个多线程程序中,对方并没断掉连接也返回0了,可能会有什么其他状况呢? 还望高手指点!:em14:

by xcj_101 - 程序开发 - 2006-05-21 13:40:15 阅读(911) 回复(1)