Blocking and non-blocking IO and error handling for Linux functions

Source: Internet
Author: User
Tags connection reset

1. Blocking means that the process waits for an event to occur and waits without execution, and resumes execution if the awaited event occurs. Calling the system blocking function may cause the process to block into sleep.

2. Blocking IO read reading keyboard input data

3.linux Error Handling

# # #函数perro (); R prints the string and error information in parentheses, and the global variable errno will be assigned worth error message, the assigned value is the following error label

# # #错误标号及对应错误

#defineEperm 1/* Operation not permitted */#defineENOENT 2/* No such file or directory */#defineEsrch 3/* No such process */#defineEINTR 4/* Interrupted system call */#defineEIO 5 */I/O error */#defineEnxio 6/* No such device or address */#defineE2big 7/* Argument list too long */#defineEnoexec 8/* Exec format Error */#defineEBADF 9/* Bad file number */#defineEchild/* No child processes */#defineEagain/* Try again */#defineENOMEM/* Out of memory */#defineEacces/* Permission denied */#defineEfault/* Bad address */#defineENOTBLK/* Block Device required */#defineEbusy/* Device or resource busy */#defineEexist/* File exists */#defineExdev */* cross-device link */#defineEnodev/* No such device */#defineEnotdir/* Not a directory */#defineEisdir/* is a directory */#defineEINVAL */* Invalid argument */#defineEnfile/* File table overflow */#defineEmfile/* Too many open files */#defineEnotty/* Not a typewriter */#defineEtxtbsy/* Text file Busy */#defineEfbig/* File too large */#defineENOSPC/* No space left on device */#defineEspipe/* Illegal seek * *#defineErofs/* read-only File System */#defineEmlink/* Too many links * *#defineEpipe/* Broken pipe */#defineEDOM/* Math argument out of domain of func * *#defineErange/* Math result not representable */#defineEDEADLK//Resource deadlock would occur * *#defineEnametoolong/* File name too long */#defineEnolck Notoginseng */No record locks available */#defineEnosys/* Function not implemented */#defineEnotempty/* Directory not empty */#defineEloop/* Too Many symbolic links encountered * *#defineEwouldblock Eagain/* operation would block */#defineENOMSG * * No message of desired type */#defineEIDRM */Identifier removed */#defineECHRNG */* Channel number out of range */#defineEl2nsync */Level 2 not synchronized */#defineEL3HLT/* Level 3 halted */#defineEl3rst/* Level 3 Reset */#defineELNRNG/* Link number out of range */#defineEunatch */Protocol driver not attached */#defineENOCSI/* NO CSI structure available */#defineEL2HLT/* Level 2 halted */#defineEbade/* Invalid Exchange * *#defineEBADR-*/Invalid Request Descriptor */#defineExfull/* Exchange full */#defineEnoano/* No anode */#defineEBADRQC */Invalid Request code */#defineEBADSLT/* Invalid slot */#defineEdeadlock Edeadlk#defineEbfont/* Bad font file format */#defineENOSTR/* Device not a stream */#defineEnodata/* NO data available */#defineETime */* Timer expired */#defineENOSR */* out of streams resources * *#defineEnonet./* Machine was not on the network */#defineENOPKG/* Package not installed */#defineEremote/* Object is remote */#defineEnolink/* Link has been severed */#defineEADV/* Advertise Error */#defineESRMNT/* Srmount Error */#defineECOMM/* Communication error on Send */#defineEproto/* Protocol Error */#defineEmultihop */Multihop attempted * *#defineEdotdot/* RFS specific Error */#defineEBADMSG-*/Not a data message */#defineEoverflow */Value too large for defined data type */#defineEnotuniq/* Name not unique on network */#defineEBADFD */* File descriptor in Bad state */#defineEREMCHG/* Remote address changed */#defineELIBACC/* Can not access a needed shared library */#defineElibbad */Accessing a corrupted shared library */#defineELIBSCN Bayi/* lib section in a.out corrupted */#defineElibmax/attempting to link in too many shared libraries */#defineElibexec */cannot exec a shared library directly */#defineEILSEQ/* Illegal byte sequence */#defineErestart/* Interrupted system call should be restarted */#defineEstrpipe */* Streams pipe Error */#defineEusers */Too Many users * *#defineEnotsock */* Socket operation on Non-socket */#defineEdestaddrreq/* Destination address required */#defineEmsgsize/* Message too long */#defineEprototype/* Protocol wrong type for socket */#defineEnoprotoopt */Protocol Not available */#defineEprotonosupport */Protocol not supported */#defineEsocktnosupport 94/* Socket type not supported */#defineEopnotsupp */Operation not supported on transport endpoint * *#defineEpfnosupport */Protocol family not supported */#defineEafnosupport/* Address family not supported by protocol */#defineEaddrinuse 98/* Address already in use */#defineEaddrnotavail/* Cannot assign requested address * *#defineEnetdown/* Network is down */#defineEnetunreach 101/* Network is unreachable */#defineEnetreset 102/* Network dropped connection because of reset */#defineEconnaborted 103/* Software caused connection abort */#defineEconnreset 104/* Connection Reset by Peer */#defineENOBUFS * * No buffer space Available */#defineEisconn 106/* Transport endpoint is already connected * *#defineEnotconn 107/* Transport endpoint is not connected */#defineEshutdown 108/* Cannot send after transport endpoint shutdown */#defineEtoomanyrefs 109/* Too many references:cannot splice * *#defineEtimedout */Connection timed out */#defineEconnrefused 111/* Connection refused */#defineEhostdown * * * Host is down */#defineEhostunreach 113/* No route to host */#defineEalready */Operation already in progress */#defineEinprogress-*/Operation now in progress */#defineEstale */* Stale NFS file handle */#defineEuclean 117/* Structure needs cleaning * *#defineEnotnam 118/* Not a XENIX named type file */#defineEnavail 119 */No XENIX semaphores Available * *#defineEisnam/* is a named type file */#defineEremoteio 121/* Remote I/O error */#defineEdquot 122/* Quota exceeded */#defineEnomedium 123 */No medium found */#defineEmediumtype 124/* Wrong medium type */#defineecanceled/* Operation Canceled */#defineEnokey 126/* Required key not available */#defineEkeyexpired 127/* Key has expired */#defineekeyrevoked/* Key has been revoked */#defineEkeyrejected 129/* Key was rejected by service *//*For robust mutexes*/#defineEownerdead/* Owner died */#defineEnotrecoverable 131/* State not recoverable */#defineErfkill */Operation not possible due to Rf-kill * *#defineEhwpoison 133/* Memory page has hardware error */

4. Non-blocking IO read terminal

5.lseek used to move the file pointer, open the file when the file pointer at the beginning of the file, there are three parameters of the first open file descriptor, the second parameter is the file pointer position offset number of bytes, the third parameter is a relative offset reference can take three reference value Seek_set file start, Seek_ Cur file current location, end of Seek_end file

# # # #lseek拓展文件大小代码, to expand the file must have a write operation

#include <sys/types.h>#include<unistd.h>#include<errno.h>#include<sys/stat.h>#include<fcntl.h>#include<stdlib.h>intMainvoid){        intFD = open ("AB", O_RDWR); if(FD <0) {perror ("Open File ab"); Exit (-1); } lseek (FD,0x1000, Seek_set); Write (FD,"a",1);        Close (FD); return 0;}

Run effect view 0x1000 is 4KB offset that is 4096 plus 1 bytes is the file size 4097

Lseek can also be used to measure the file size, pointing the file pointer at the end of the file, and the Lseek return value is the offset from the beginning of the file to the file pointer

The 6.FCNTL function changes the way the file is accessed, gets the file open tag flag for the open file descriptor, or sets the flag

Fcntl The second parameter can choose the following two values, respectively, to get access to files, set the file access mode

7.ioctl used to control the device, set the device parameters, set or get the physical characteristics of the device file using the IOCTL function, the first parameter is an open file descriptor, the second parameter is the device request code, the third is a variable parameter

# #3例子第二个参数request要去驱动找, get screen size in size

Blocking and non-blocking IO and error handling for Linux functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.