Linux 设备驱动 Edition 3Linux设备驱动第三版(中文版)

Linux 设备驱动 Edition 3-Linux设备驱动第三版(中文版)- -

Linux 设备驱动 Edition 3

By Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman

 

由 quickwhale 翻译的简体中文版 V0.1.0 2006-6-2

 

遵循原版的版权声明. 还在完善中. 欢迎任何意见, 请给我邮件. 请发信至 quickwhale 的邮箱

 

Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/insti-tutional sales department: (800) 998-9938 or corporate@oreilly.com.

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 2.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.


多路复用与设置阻塞、非阻塞模式 - To be, or not to be: that is the question - 博客频道 - CSDN.NET

多路复用与设置阻塞、非阻塞模式

分类: Linux/Unix C/C++ Network Program 202人阅读 评论(0) 收藏 举报

阻塞和非阻塞模式使用fcntl()可以进行设置,linux下默认的是阻塞模式,windows下相反。下面讲述设置模式三步骤:

1、获取模式标识

int  mode_flag;  listen_socket;

mode_flag = fcntl(listen_socket,F_GETFL,0);

2、设置模式标识为目标模式。非阻塞模式为O_NONBLOCK,阻塞模式为~O_NONBLOCK。这里以阻塞模式为例。

mode_flag&=~O_NONBLOCK;

3、将套接字设置为模式标识所表示的模式

fcntl(listen_socket,F_SETFL,mode_flag);

另外,使用ioctl()也可以设置阻塞和非阻塞模式。

int b_on=1;

ioctl(listen_socket,FIONBIO,&b_on);

通过setsockopt()可以设置端口可被多次绑定,以达到多路复用的目的。

setsockopt(listen_socket,(struct sockaddr *)&servaddr,sizeof(servaddr));

原文地址:https://www.cnblogs.com/lexus/p/2857770.html