易截截图软件、单文件、免安装、纯绿色、仅160KB

linux中select()函数分析

select()的机制中提供一fd_set的数据结构,实际上是一long类型的数组, 每一个数组元素都能与一打开的文件句柄(不管是Socket句柄,还是其他 文件或命名管道或设备句柄)建立联系,建立联系的工作由程序员完成, 当调用select()时,由内核根据IO状态修改fd_set的内容,由此来通知执 行了select()的进程哪一Socket或文件可读,下面具体解释: 
#include 
#include 
#include 
int select(nfds, readfds, writefds, exceptfds, timeout) 
int nfds; 
fd_set *readfds, *writefds, *exceptfds; 
struct timeval *timeout; 
ndfs:select监视的文件句柄数,视进程中打开的文件数而定,一般设为呢要监视各文件 中的最大文件号加一。 
readfds:select监视的可读文件句柄集合。 
writefds: select监视的可写文件句柄集合。 
exceptfds:select监视的异常文件句柄集合。 
timeout:本次select()的超时结束时间。(见/usr/sys/select.h, 可精确至百万分之一秒!) 
当readfds或writefds中映象的文件可读或可写或超时,本次select() 就结束返回。程序员利用一组系统提供的宏在select()结束时便可判 断哪一文件可读或可写。对Socket编程特别有用的就是readfds。 几只相关的宏解释如下: 
FD_ZERO(fd_set *fdset):清空fdset与所有文件句柄的联系。 
FD_SET(int fd, fd_set *fdset):建立文件句柄fd与fdset的联系。 
FD_CLR(int fd, fd_set *fdset):清除文件句柄fd与fdset的联系。 
FD_ISSET(int fd, fdset *fdset):检查fdset联系的文件句柄fd是否 
可读写,>0表示可读写。 
(关于fd_set及相关宏的定义见/usr/include/sys/types.h) 
这样,你的socket只需在有东东读的时候才读入,大致如下: 
... 
int sockfd; 
fd_set fdR; 
struct timeval timeout = ..; 
... 
for(;;) { 
FD_ZERO(&fdR); 
FD_SET(sockfd, &fdR); 
switch (select(sockfd + 1, &fdR, NULL, &timeout)) {&


相关文档:

我的linux没有声音了

前天开机实然没有声音了,怎么弄也不行,在论坛挂了一个帖子,到现在也没有人回复。昨天妈妈过生日我回妈家去了,今天才回来。我打开机器盼望能好起来,结果还是没有声音。
1、在控制台下有声音
 control+alt+f1切换到控制台,之后mplayer /mnt/wine/music/*.mp3   结果有声音
2、创建新用户有声音
useradd - ......

linux内核读书笔记(进程数据结构分析)一

include/linux/sched.h
384   struct task_struct {
385     volatile long state;
386     struct thread_info *thread_info;
387     atomic_t usage;
388     unsigned long flags; 
389   &nbs ......

Linux 下消除netbeans字体锯齿

编辑
$netbeans_home/etc/netbeans.conf,在"netbeans_default_options"项中添加"-J-
Dawt.useSystemAAFontSettings=on --fontsize=12"
p.s:让所有的Java程序都使用反锯
齿: export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on'
------------------------------------------------- ......

linux内核学习

1. 内核学习方法,编译、调试等常见问题
1.1 关于编译升级内核到2.6.0的一些问题 作者:ommm
        http://linux.chinaunix.net/bbs/thread-281831-1-5.html
1.2 VMWare Workstation 6.0调试Linux Kernel,竟如此方便 作者:albcamus
        http://linux.chinaunix.net/bb ......

linux内核读书笔记(进程终止函数分析)三

do_exit() Function
-----------------------------------------------------------------------
kernel/exit.c
707 NORET_TYPE void do_exit(long code)
708 {
709 struct task_struct *tsk = current;
710
711 if (unlikely(in_interrupt()))
712 panic("Aiee, killing interrupt handler!");
713 if ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号