社区
C语言
帖子详情
fcntl问题
gccli
2008-08-07 04:34:19
我用socket写一个客户端程序,用fcntl设置了非阻塞,但是在read时却阻塞了。
服务器并没有向客户端发数据,我想让他在read处不阻塞,怎么弄? 还有,最重要的,为什么fcntl不起作用????
fd = socket(AF_INET, SOCK_STREAM, 0);
fcntl(fd, F_SETFL, O_NONBLOCK);
...
len = read(fd, buf, 1024);//
...
...全文
305
8
打赏
收藏
fcntl问题
我用socket写一个客户端程序,用fcntl设置了非阻塞,但是在read时却阻塞了。 服务器并没有向客户端发数据,我想让他在read处不阻塞,怎么弄? 还有,最重要的,为什么fcntl不起作用???? fd = socket(AF_INET, SOCK_STREAM, 0); fcntl(fd, F_SETFL, O_NONBLOCK); ... len = read(fd, buf, 1024);// ...
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zjl878586
2009-08-09
打赏
举报
回复
怎么回事?我也遇到这样的问题,有谁知道啊
快乐田伯光
2008-08-07
打赏
举报
回复
用read一样的可以做到非阻塞读的。
这个后面应该还有一个参数的。
fdflags = fcntl(fd, F_GETFL, 0);
gccli
2008-08-07
打赏
举报
回复
我好像找到了答案
http://topic.csdn.net/t/20030726/00/2073466.html
为什么不用recv读socket???
recv(flag[i],buf,sizeof(buf), MSG_DONTWAIT)非阻塞读
去试试
快乐田伯光
2008-08-07
打赏
举报
回复
最好是变量名不要混用,
int fdflags
int iRtn;
fdflags = fcntl(fd, F_GETFL);
fdflags |= O_NONBLOCK;
iRtn = fcntl(fd, F_SETFL, fdflags);
快乐田伯光
2008-08-07
打赏
举报
回复
int flags = fcntl(fd, F_GETFL);
flags ¦= O_NONBLOCK;
flags = fcntl(fd, F_SETFL, flags);
gccli
2008-08-07
打赏
举报
回复
谢谢楼上,又见到你了
是这样,没有设置其他任何属性,创建套接字后,调用fcntl
int flags = fcntl(fd, F_GETFL);//这时得到flags = 0
然后,flags |= O_NONBLOCK;
flags = fcntl(fd, F_SETFL, O_NONBLOCK); //这里得到flags也是0
奇怪了,怎么不起作用?
快乐田伯光
2008-08-07
打赏
举报
回复
fcntl()调用成功了没有?或是别的地方又改了属性了吧
快乐田伯光
2008-08-07
打赏
举报
回复
不可能吧
解决这个错误
问题
:importerror no module named
fcn
tl
解决这个错误
问题
:importerror no module named
fcn
tl
。 解压后,将
fcn
tl
.py文件放到PYTHONPATH路径即可,我是放到了Python27\Lib目录下。
fcn
tl
.py文件下载
fcn
tl
是posix 类型的系统 比喻 linux的 文件接口部分 对应linux C开发里的
fcn
tl
.h python 的linux版本自带的 标准模块 win下是冒得的
fcn
tl
.py文件
django-crontab插件对linux底层的调用,调用过程中会出现 ImportError: No module named
fcn
tl
fcn
tl
.py 解决no module named fan
tl
的
问题
解决no module named fan
tl
的
问题
,把文件复制放到你所需要的python path环境的LIb中即可 可自行建
fcn
tl
.py文件,敲入如下代码: def
fcn
tl
(fd, op, arg=0): return 0 def ioc
tl
(fd, op, arg=0, mutable_flag=True): if mutable_flag: return 0 else: return "" def flock(fd, op): return def lockf(fd, operation, length=0, start=0, whence=0): return
fcn
tl
函数的功能介绍
函数可以改变已打开的文件的性质。 #include <
fcn
tl
.h> int
fcn
tl
(int fields, int cmd, .../* int arg */); //若成功则依赖于cmd,若出错则返回-1
C语言
70,037
社区成员
243,243
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章