ChinaUnix.net
相关文章推荐:

c socket write read 函数

按照书上写 了一个程序结果是正确的,但有的地方看不懂,请大虾指教 了谢谢阿 :) 以下是程序,看不懂为什么从hello1文件读出一次内容后他的文件描述符fds[0]就变为0 了 ,而向hello2文件里写一次以后他的文件描述符就不变阿。这个程序完成的功能是每 隔10s中就向hello2文件写一次数据。 #include #include #include #include #include #include #include

by destinyliu - 程序开发 - 2006-12-21 13:25:47 阅读(1306) 回复(5)

相关讨论

按照书上写 了一个程序结果是正确的,但有的地方看不懂,请大虾指教 了谢谢阿 :) 以下是程序,看不懂为什么从hello1文件读出一次内容后他的文件描述符fds[0]就变为0 了 ,而向hello2文件里写一次以后他的文件描述符就不变阿。这个程序完成的功能是每 隔10s中就向hello2文件写一次数据。 #include #include #include #include #include #include #include

by destinyliu - Linux环境编程 - 2006-12-21 13:25:47 阅读(1984) 回复(5)

我看一本书上说write一个128字节的数据,调用read时,可能第一次接受10字节,第二次接收100字节,第三次接受18字节。所以必须重复的调用read。 但服务端write("hello"); 后, 如果用 while((n=read(buf))>0) { printf(buf); } 接收完服务端发过来的数据后,read就会由于没有数据到来而阻塞,就不能往下继续执行了。 怎么才能让read接受完write传过来的数据后就跳出while?

by ifosn - C/C++ - 2008-11-12 23:23:27 阅读(5315) 回复(7)

#include #include #include #include #include #include #include #define MAXSIZE int main(void) { int fd,size,len; char *buf="Hello!I'm writing to this file!"; char buf_r[10]; len=strlen(buf); if((fd=open("/tmp/hello.c",O_CREAT|O_TRUNC|O_RDWR,0666)) 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43581/showart_343164.html

by For Free - Linux文档专区 - 2007-07-19 22:40:08 阅读(1416) 回复(0)

似乎是因为write默认是非阻塞的? 我整个write运行时间大概是9~10s 但是用clock测试总是接近0~clock()应该不会错的。 不过设置了write阻塞也是这样。。用了fcntl和ioctl都不行。。不知道是不是设置有问题。。还是其他的问题。。

by a2188360 - Linux新手园地 - 2013-08-20 14:48:24 阅读(953) 回复(2)

read : > 0 :返回实际读到的字节数目 0 : 说明遇到了EOF -1 :说明读操作出现错误 write: > 0 : 返回实际写入的字节数目 -1 : 说明写操作中出现错误了 ----------------------------- 问题: 1> write为什么没有返回值0 ? 2> 可以把char=0,写入文件吗? 3> 可以把EOF写入文件吗?(EOF的值好像是-1)

by anank - 内核源码 - 2010-06-14 22:46:55 阅读(10828) 回复(2)

read 函数write 函数 最近开始从事搜索引擎的工作,所以又重新开始了c/c++的旅程,时隔4年 不得不复习一下c/c++其中的内容,以下内容有网上别的朋友发表的,也有我自己总结的. 1. read #include ssize_t read(int filedes, void *buf, size_t nbytes); 返回值:读取到的字节数;0(读到 EOF);-1(出错) read 函数从 filedes 指定的已打开文件中读取 nbytes 字节到 buf...

by 我爱spring - Linux文档专区 - 2007-03-28 10:30:12 阅读(1206) 回复(0)

本帖最后由 飘扶摇 于 2011-05-26 23:41 编辑 ssize_t xxx_read(struct file *filp, char *buffer, size_t count, loff_t *ppos); ssize_t xxx_write(struct file *filp,const char *buffer, size_t count); 上面两个函数中的"buffer" 是什么时候分配出来的,分配在什么地方,是内核分配的吗?

by 飘扶摇 - 驱动开发 - 2011-06-18 16:46:50 阅读(5931) 回复(9)

static ssize_t mem_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos) static ssize_t mem_write(struct file *filp, const char __user *buf, size_t size, loff_t *ppos) struct file 结构中不是有当前的读写位置的变量吗。为什么函数仍要传递“loff_t *ppos”这个值呢?

loff_treadwrite

by add358 - 驱动开发 - 2011-05-08 21:49:01 阅读(3705) 回复(1)

http://bbs.chinaunix.net/viewthread.php?tid=697231&extra=&page=1 本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/76292/showart_2153307.html

by ubuntuer - Linux文档专区 - 2010-01-19 16:11:54 阅读(1038) 回复(0)

vc++怎么连open,read,write函数都没有?

by mabuc - C/C++ - 2009-04-29 13:15:34 阅读(3986) 回复(9)