一些最常见的 TCP/IP 错误原因代码 (errno) 列表
对于在基于 UNIX 的环境中的 TCP/IP 用户,下表列出了某些最常见的错误原因码 (errno)。它不是完整的错误列表。可以在文件 /usr/include/sys/errno.h 中找到 Errno。针对每一种操作系统给出了errno 号码。
Errno |
|
说明 |
---|
EINTR | 4 | 4 | 4 | 4 | 4 | 系统调用中断。 |
EAGAIN | 11 | 11 | 11 | 11 | 11 | 资源临时不可用。 |
EBUSY | 16 | 16 | 16 | 16 | 16 | 资源正忙。 |
EMFILE | 24 | 24 | 24 | 24 | 24 | 每个进程文件描述符表已满。 |
EPIPE | 32 | 32 | 32 | 32 | 32 | 管道断开。 |
EADDRINUSE | 67 | 226 | 125 | 125 | 98 | 已经在使用指定的地址。 |
ENETDOWN | 69 | 228 | 127 | 127 | 100 | 网络已停止。 |
ENETUNREACH | 70 | 229 | 128 | 128 | 101 | 没有到达网络的可用路由。 |
ENETRESET | 71 | 230 | 129 | 129 | 102 | 重设时网络已卸下了连接。 |
ECONNRESET | 73 | 232 | 131 | 131 | 104 | 伙伴已重设了连接。 |
ENOBUFS | 74 | 233 | 132 | 132 | 105 | 系统中没有足够的缓冲区空间资源可用来完成调用。 |
ENOTCONN | 76 | 235 | 134 | 134 | 107 | 未连接套接字。 |
ETIMEDOUT | 78 | 238 | 145 | 145 | 110 | 连接超时。 |
ECONNREFUSED | 79 | 239 | 146 | 146 | 111 | 连接已被拒绝。若您正在尝试与数据库相连,则检查是否已成功启动了服务器上的数据库管理程序和 TCP/IP 协议支持。 若使用 SOCKS 协议支持,则还要确保在 SOCKS 服务器上已成功启动了 TCP/IP 协议支持。 |
EHOSTDOWN | 80 | 241 | 147 | 147 | 147 | 主机已停机。 |
EHOSTUNREACH | 81 | 242 | 148 | 148 | 113 | 没有到达主机的可用路由。 |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
对 于 OS/2 环境中的 TCP/IP 用户,下面的列表显示了最常见的 errno。它不是完整的错误列表。可以在文件 nerrno.h 中找到 Errno。此文件是 TCP/IP 产品包含文件的一部分。若尚未安装这些文件,则在您的系统上可能不会出现。errno 号码本身是用括号括起来的。
SOCEINTR (10003):系统调用被中断。 |
SOCEMFILE (10024):打开的文件太多。 |
SOCEPIPE (10032):管道被断开。 |
EADDRINUSE (10048):已经在使用指定的地址。 |
ENETDOWN (10050):网络已停止。 |
ENETUNREACH (10051):没有到达网络的可用路由。 |
ENETRESET (10052):重设时网络已卸下了连接。 |
SOCECONNABORTED (10053):软件导致连接异常中止。 |
ECONNRESET (10054):伙伴已重设了连接。 |
ENOBUFS (10055):无缓冲区空间可用。 |
ENOTCONN (10057):未连接套接字。 |
ETIMEDOUT (10060): 在进行连接之前,建立连接超时。 |
ECONNREFUSED (10061):连接已被拒绝。若您正在尝试与数据库相连,则检查是否已成功启动了服务器上的数据库管理程序和 TCP/IP 协议支持。 |
若使用 SOCKS 协议支持,则还要确保在 SOCKS 服务器上已成功启动了 TCP/IP 协议支持。 |
EHOSTDOWN (10064):主机已停机。 |
EHOSTUNREACH (10065):没有到达主机的可用路由。 |
SOCEOS2ERR (10100):OS/2 错误。 |
有关 OS/2 TCP/IP 通信错误的详情,参考 OS/2 TCP/IP 文档。 |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
对 于 Windows 95、Windows 98 或 Windows NT 下的 TCP/IP 或 IPX/SPX 用户,下面的列表显示了最常见的错误码。它不是完整的错误列表。可以在文件 winsock.h 中找到由 WSAGetLastError() 返回的错误。
WSAEINVAL (10022):若在函数 WSASTARTUP 上接收到此错误,则此 DLL 不支持应用程序所支持的 Windows Sockets 版本。 |
WSAEMFILE (10024):没有可用的文件描述符。 |
WSAEWOULDBLOCK (10035):套接字标记为未分块,而操作将分块。 |
WSAEINPROGRESS (10036):正在进行分块 Windows Sockets 操作。 |
WSAENOPROTOOPT (10042):该选项是未知的或不受支持的。 |
WSAEADDRINUSE (10048):已经在使用指定的地址。 |
WSAENETDOWN (10050):网络子系统已失败。 |
WSAENETUNREACH (10051):此时不能从此主机到达网络。 |
WSAENETRESET (10052):由于重设了远程主机,所以连接已断开。 |
WSAECONNABORTED (10053):由于超时或其他故障,导致虚拟电路异常中止。重设时网络已卸下了连接。 |
WSAECONNRESET (10054):伙伴已重设了连接。 |
WSAENOBUFS (10055):无缓冲区空间可用,连接太多。 |
WSAENOTCONN (10057):未连接套接字。 |
WSAETIMEDOUT (10060):在进行连接之前,建立连接超时。 |
WSAECONNREFUSED (10061):连接已被拒绝。若您正在尝试与数据库相连,则检查在服务器上是否已成功启动了数据库管理程序和 TCP/IP 协议支持。 |
WSAEHOSTUNREACH (10065):此时不能从此主机到达网络。 |
WSASYSNOTREADY (10091):基础网络子系统未准备好进行网络通信。 |
WSAVERNOTSUPPORTED (10092):此特定的 Windows Sockets 实现未提供请求的 Windows Sockets API 支持的版本。 |
WSAHOST_NOT_FOUND (11001):找不到主机。 |
WSATRY_AGAIN (11002):找不到主机。请求从名称服务器中检索主机名的 IP 地址失败。 |
WSANO_DATA (11004):名称无效,没有请求的类型的数据记录。名称服务器或 hosts 文件不识别主机名,或者在 services 文件中未指定服务名。 |
有关 Windows 下的 TCP/IP 通信错误的详情,参考 Windows Sockets 文档。 |
而我们可以通过以下代码来查看errno错误:
#include <errno.h> printf ("errno is: %d\n", errno);
strerror(errno):获取errno对应的错误
/****************************获取错误代码描述**************/
#include <string.h> /* for strerror */
#include <errno.h>
#include <stdio.h>
int main(int argc, char ** argv) {
int i = 0;
for(i = 0; i < 256; i++)
printf("errno.%02d is: %s/n", i, strerror(i));
return 0;
}
/*****************************************************************/
errno.00 is: Success
errno.01 is: Operation not permitted
errno.02 is: No such file or directory
errno.03 is: No such process
errno.04 is: Interrupted system call
errno.05 is: Input/output error
errno.06 is: No such device or address
errno.07 is: Argument list too long
errno.08 is: Exec format error
errno.09 is: Bad file descriptor
errno.10 is: No child processes
errno.11 is: Resource temporarily unavailable[资源临时不可用](连续发送数据时候回出此错,加延时)
errno.12 is: Cannot allocate memory
errno.13 is: Permission denied
errno.14 is: Bad address
errno.15 is: Block device required
errno.16 is: Device or resource busy
errno.17 is: File exists
errno.18 is: Invalid cross-device link
errno.19 is: No such device
errno.20 is: Not a directory
errno.21 is: Is a directory
errno.22 is: Invalid argument
errno.23 is: Too many open files in system
errno.24 is: Too many open files
errno.25 is: Inappropriate ioctl for device
errno.26 is: Text file busy
errno.27 is: File too large
errno.28 is: No space left on device
errno.29 is: Illegal seek
errno.30 is: Read-only file system
errno.31 is: Too many links
errno.32 is: Broken pipe[断开的管道](原因:the broken pipe error occurs if one end of the
TCP socket closes connection(using disconnect) or gets killed and the other
end tries to still write to it. An indication of a closed/terminated
connection is a return value of 0 when you try to read from that socket
using recv. After receiving such an error, if you try to still write to the
socket, your process gets sent the SIGPIPE signal which kills it.
)
errno.33 is: Numerical argument out of domain
errno.34 is: Numerical result out of range
errno.35 is: Resource deadlock avoided
errno.36 is: File name too long
errno.37 is: No locks available
errno.38 is: Function not implemented
errno.39 is: Directory not empty
errno.40 is: Too many levels of symbolic links
errno.41 is: Unknown error 41
errno.42 is: No message of desired type
errno.43 is: Identifier removed
errno.44 is: Channel number out of range
errno.45 is: Level 2 not synchronized
errno.46 is: Level 3 halted
errno.47 is: Level 3 reset
errno.48 is: Link number out of range
errno.49 is: Protocol driver not attached
errno.50 is: No CSI structure available
errno.51 is: Level 2 halted
errno.52 is: Invalid exchange
errno.53 is: Invalid request descriptor
errno.54 is: Exchange full
errno.55 is: No anode
errno.56 is: Invalid request code
errno.57 is: Invalid slot
errno.58 is: Unknown error 58
errno.59 is: Bad font file format
errno.60 is: Device not a stream
errno.61 is: No data available
errno.62 is: Timer expired
errno.63 is: Out of streams resources
errno.64 is: Machine is not on the network
errno.65 is: Package not installed
errno.66 is: Object is remote
errno.67 is: Link has been severed
errno.68 is: Advertise error
errno.69 is: Srmount error
errno.70 is: Communication error on send
errno.71 is: Protocol error
errno.72 is: Multihop attempted
errno.73 is: RFS specific error
errno.74 is: Bad message
errno.75 is: Value too large for defined data type
errno.76 is: Name not unique on network
errno.77 is: File descriptor in bad state
errno.78 is: Remote address changed
errno.79 is: Can not access a needed shared library
errno.80 is: Accessing a corrupted shared library
errno.81 is: .lib section in a.out corrupted
errno.82 is: Attempting to link in too many shared libraries
errno.83 is: Cannot exec a shared library directly
errno.84 is: Invalid or incomplete multibyte or wide character
errno.85 is: Interrupted system call should be restarted
errno.86 is: Streams pipe error
errno.87 is: Too many users
errno.88 is: Socket operation on non-socket
errno.89 is: Destination address required
errno.90 is: Message too long
errno.91 is: Protocol wrong type for socket
errno.92 is: Protocol not available
errno.93 is: Protocol not supported
errno.94 is: Socket type not supported
errno.95 is: Operation not supported
errno.96 is: Protocol family not supported
errno.97 is: Address family not supported by protocol
errno.98 is: Address already in use
errno.99 is: Cannot assign requested address
errno.100 is: Network is down
errno.101 is: Network is unreachable
errno.102 is: Network dropped connection on reset
errno.103 is: Software caused connection abort
errno.104 is: Connection reset by peer[l连接被对端重置]
errno.105 is: No buffer space available
errno.106 is: Transport endpoint is already connected
errno.107 is: Transport endpoint is not connected
errno.108 is: Cannot send after transport endpoint shutdown
errno.109 is: Too many references: cannot splice
errno.110 is: Connection timed out
errno.111 is: Connection refused
errno.112 is: Host is down
errno.113 is: No route to host
errno.114 is: Operation already in progress
errno.115 is: Operation now in progress
errno.116 is: Stale NFS file handle
errno.117 is: Structure needs cleaning
errno.118 is: Not a XENIX named type file
errno.119 is: No XENIX semaphores available
errno.120 is: Is a named type file
errno.121 is: Remote I/O error
errno.122 is: Disk quota exceeded
errno.123 is: No medium found
errno.124 is: Wrong medium type
errno.125 is: Operation canceled
errno.126 is: Required key not available
errno.127 is: Key has expired
errno.128 is: Key has been revoked
errno.129 is: Key was rejected by service
errno.130 is: Owner died
errno.131 is: State not recoverable
errno.132 is: Unknown error 132
132-255 全是Unknown error
下一篇: eStation 应用程序分辨率错误
推荐阅读
-
一些最常见的 TCP/IP 错误原因代码 (errno) 列表
-
F#探险之旅(二):函数式编程(上)-函数式编程范式简介 F#主要支持三种编程范式:函数式编程(Functional Programming,FP)、命令式编程(Imperative Programming)和面向对象(Object-Oriented,OO)的编程。回顾它们的历史,FP是最早的一种范式,第一种FP语言是IPL,产生于1955年,大约在Fortran一年之前。第二种FP语言是Lisp,产生于1958,早于Cobol一年。Fortan和Cobol都是命令式编程语言,它们在科学和商业领域的迅速成功使得命令式编程在30多年的时间里独领风骚。而产生于1970年代的面向对象编程则不断成熟,至今已是最流行的编程范式。有道是“*代有语言出,各领风骚数十年”。 尽管强大的FP语言(SML,Ocaml,Haskell及Clean等)和类FP语言(APL和Lisp是现实世界中最成功的两个)在1950年代就不断发展,FP仍停留在学院派的“象牙塔”里;而命令式编程和面向对象编程则分别凭着在商业领域和企业级应用的需要占据领先。今天,FP的潜力终被认识——它是用来解决更复杂的问题的(当然更简单的问题也不在话下)。 纯粹的FP将程序看作是接受参数并返回值的函数的集合,它不允许有副作用(side effect,即改变了状态),使用递归而不是循环进行迭代。FP中的函数很像数学中的函数,它们都不改变程序的状态。举个简单的例子,一旦将一个值赋给一个标识符,它就不会改变了,函数不改变参数的值,返回值是全新的值。 FP的数学基础使得它很是优雅,FP的程序看起来往往简洁、漂亮。但它无状态和递归的天性使得它在处理很多通用的编程任务时没有其它的编程范式来得方便。但对F#来说这不是问题,它的优势之一就是融合了多种编程范式,允许开发人员按照需要采用最好的范式。 关于FP的更多内容建议阅读一下这篇文章:Why Functional Programming Matters(中文版)。F#中的函数式编程 从现在开始,我将对F#中FP相关的主要语言结构逐一进行介绍。标识符(Identifier) 在F#中,我们通过标识符给值(value)取名字,这样就可以在后面的程序中引用它。通过关键字let定义标识符,如: let x = 42 这看起来像命令式编程语言中的赋值语句,两者有着关键的不同。在纯粹的FP中,一旦值赋给了标识符就不能改变了,这也是把它称为标识符而非变量(variable)的原因。另外,在某些条件下,我们可以重定义标识符;在F#的命令式编程范式下,在某些条件下标识符的值是可以修改的。 标识符也可用于引用函数,在F#中函数本质上也是值。也就是说,F#中没有真正的函数名和参数名的概念,它们都是标识符。定义函数的方式与定义值是类似的,只是会有额外的标识符表示参数: let add x y = x + y 这里共有三个标识符,add表示函数名,x和y表示它的参数。关键字和保留字关键字是指语言中一些标记,它们被编译器保留作特殊之用。在F#中,不能用作标识符或类型的名称(后面会讨论“定义类型”)。它们是: abstract and as asr assert begin class default delegate do donedowncast downto elif else end exception extern false finally forfun function if in inherit inline interface internal land lazy letlor lsr lxor match member mod module mutable namespace new nullof open or override private public rec return sig static structthen to true try type upcast use val void when while with yield 保留字是指当前还不是关键字,但被F#保留做将来之用。可以用它们来定义标识符或类型名称,但编译器会报告一个警告。如果你在意程序与未来版本编译器的兼容性,最好不要使用。它们是: atomic break checked component const constraint constructor continue eager event external fixed functor global include method mixinobject parallel process protected pure sealed trait virtual volatile 文字值(Literals) 文字值表示常数值,在构建计算代码块时很有用,F#提供了丰富的文字值集。与C#类似,这些文字值包括了常见的字符串、字符、布尔值、整型数、浮点数等,在此不再赘述,详细信息请查看F#手册。 与C#一样,F#中的字符串常量表示也有两种方式。一是常规字符串(regular string),其中可包含转义字符;二是逐字字符串(verbatim string),其中的(")被看作是常规的字符,而两个双引号作为双引号的转义表示。下面这个简单的例子演示了常见的文字常量表示: let message = "Hello World"r"n!" // 常规字符串let dir = @"C:"FS"FP" // 逐字字符串let bytes = "bytes"B // byte 数组let xA = 0xFFy // sbyte, 16进制表示let xB = 0o777un // unsigned native-sized integer,8进制表示let print x = printfn "%A" xlet main = print message; print dir; print bytes; print xA; print xB; main Printf函数通过F#的反射机制和.NET的ToString方法来解析“%A”模式,适用于任何类型的值,也可以通过F#中的print_any和print_to_string函数来完成类似的功能。值和函数(Values and Functions) 在F#中函数也是值,F#处理它们的语法也是类似的。 let n = 10let add a b = a + blet addFour = add 4let result = addFour n printfn "result = %i" result 可以看到定义值n和函数add的语法很类似,只不过add还有两个参数。对于add来说a + b的值自动作为其返回值,也就是说在F#中我们不需要显式地为函数定义返回值。对于函数addFour来说,它定义在add的基础上,它只向add传递了一个参数,这样对于不同的参数addFour将返回不同的值。考虑数学中的函数概念,F(x, y) = x + y,G(y) = F(4, y),实际上G(y) = 4 + y,G也是一个函数,它接收一个参数,这个地方是不是很类似?这种只向函数传递部分参数的特性称为函数的柯里化(curried function)。 当然对某些函数来说,传递部分参数是无意义的,此时需要强制提供所有参数,可是将参数括起来,将它们转换为元组(tuple)。下面的例子将不能编译通过: let sub(a, b) = a - blet subFour = sub 4 必须为sub提供两个参数,如sub(4, 5),这样就很像C#中的方法调用了。 对于这两种方式来说,前者具有更高的灵活性,一般可优先考虑。 如果函数的计算过程中需要定义一些中间值,我们应当将这些行进行缩进: let halfWay a b = let dif = b - a let mid = dif / 2 mid + a 需要注意的是,缩进时要用空格而不是Tab,如果你不想每次都按几次空格键,可以在VS中设置,将Tab字符自动转换为空格;虽然缩进的字符数没有限制,但一般建议用4个空格。而且此时一定要用在文件开头添加#light指令。作用域(Scope)作用域是编程语言中的一个重要的概念,它表示在何处可以访问(使用)一个标识符或类型。所有标识符,不管是函数还是值,其作用域都从其声明处开始,结束自其所处的代码块。对于一个处于最顶层的标识符而言,一旦为其赋值,它的值就不能修改或重定义了。标识符在定义之后才能使用,这意味着在定义过程中不能使用自身的值。 let defineMessage = let message = "Help me" print_endline message // error 对于在函数内部定义的标识符,一般而言,它们的作用域会到函数的结束处。 但可使用let关键字重定义它们,有时这会很有用,对于某些函数来说,计算过程涉及多个中间值,因为值是不可修改的,所以我们就需要定义多个标识符,这就要求我们去维护这些标识符的名称,其实是没必要的,这时可以使用重定义标识符。但这并不同于可以修改标识符的值。你甚至可以修改标识符的类型,但F#仍能确保类型安全。所谓类型安全,其基本意义是F#会避免对值的错误操作,比如我们不能像对待字符串那样对待整数。这个跟C#也是类似的。 let changeType = let x = 1 let x = "change me" let x = x + 1 print_string x 在本例的函数中,第一行和第二行都没问题,第三行就有问题了,在重定义x的时候,赋给它的值是x + 1,而x是字符串,与1相加在F#中是非法的。 另外,如果在嵌套函数中重定义标识符就更有趣了。 let printMessages = let message = "fun value" printfn "%s" message; let innerFun = let message = "inner fun value" printfn "%s" message innerFun printfn "%s" message printMessages 打印结果: fun value inner fun valuefun value 最后一次不是inner fun value,因为在innerFun仅仅将值重新绑定而不是赋值,其有效范围仅仅在innerFun内部。递归(Recursion)递归是编程中的一个极为重要的概念,它表示函数通过自身进行定义,亦即在定义处调用自身。在FP中常用于表达命令式编程的循环。很多人认为使用递归表示的算法要比循环更易理解。 使用rec关键字进行递归函数的定义。看下面的计算阶乘的函数: let rec factorial x = match x with | x when x < 0 -> failwith "value must be greater than or equal to 0" | 0 -> 1 | x -> x * factorial(x - 1) 这里使用了模式匹配(F#的一个很棒的特性),其C#版本为: public static long Factorial(int n) { if (n < 0) { throw new ArgumentOutOfRangeException("value must be greater than or equal to 0"); } if (n == 0) { return 1; } return n * Factorial (n - 1); } 递归在解决阶乘、Fibonacci数列这样的问题时尤为适合。但使用的时候要当心,可能会写出不能终止的递归。匿名函数(Anonymous Function) 定义函数的时候F#提供了第二种方式:使用关键字fun。有时我们没必要给函数起名,这种函数就是所谓的匿名函数,有时称为lambda函数,这也是C#3.0的一个新特性。比如有的函数仅仅作为一个参数传给另一个函数,通常就不需要起名。在后面的“列表”一节中你会看到这样的例子。除了fun,我们还可以使用function关键字定义匿名函数,它们的区别在于后者可以使用模式匹配(本文后面将做介绍)特性。看下面的例子: let x = (fun x y -> x + y) 1 2let x1 = (function x -> function y -> x + y) 1 2let x2 = (function (x, y) -> x + y) (1, 2) 我们可优先考虑fun,因为它更为紧凑,在F#类库中你能看到很多这样的例子。 注意:本文中的代码均在F# 1.9.4.17版本下编写,在F# CTP 1.9.6.0版本下可能不能通过编译。 F#系列随笔索引页面