Keywords: TCP/IP, socket, errno
The following lists several Socket errors that are common in the connection between the customer and the service process, and analyzes the causes. I will try again later.
ECONNABORTED
This error is described as "software caused connection abort", that is, "software-caused connection suspension ". The reason is that when the service and the customer process complete the "three-way handshake" for the TCP connection, the customer TCP sends an RST (reset) shard. In the view of the service process, the connection is queued by TCP, but the RST is reached when the service process calls accept. POSIX specifies that the errno value at this time must be ECONNABORTED. The implementation originating from Berkeley completely processes the aborted connection in the kernel, and the service process will never know the occurrence of the aborted connection. Generally, the server process can ignore this error and directly call accept again.
C code
- /* Linux system */
- Include/asm-alpha/errno. h: # define ECONNABORTED 53/* Software caused connection
- Abort */
- Include/asm-generic/errno. h: # define ECONNABORTED 103/* Software caused
- Connection abort */
- Include/asm-mips/errno. h: # define ECONNABORTED 130/* Software caused connection
- Abort */
Accept (2) man page writes [ECONNABORTED] A connection arrived, but it was closed while waiting on the listen queue.
ECONNRESET
This error is described as "connection reset by peer", that is, "reset connection of the other party". This usually occurs when the service process is terminated earlier than the customer process. When a service process is terminated, it will send a FIN Shard to the customer TCP. The customer TCP responds to ACK and the service TCP will be transferred to the FIN_WAIT2 status. At this time, if the customer process does not process the FIN (such as blocking other calls without closing the Socket), the customer TCP will be in the CLOSE_WAIT state. When the customer process sends data to the FIN_WAIT2 service TCP again, the Service TCP will immediately respond to the RST. In general, this situation can also lead to another application exception. After a customer process sends data, it often waits for the network IO to receive data, such as read or readline calls, in this case, due to the execution sequence, if the call is executed before the RST node is received, the customer process will receive an unexpected EOF error. In this case, the error "server terminated prematurely"-"server premature termination" is usually output.
EPIPE
The error is described as "broken pipe", that is, "pipeline cracking". This usually happens when the customer process ignores (or fails to handle it in time) the Socket error, when more data is written to the service TCP, the kernel sends the SIGPIPE signal to the client process. By default, the process is terminated (at this time, the front-end process does not perform core dump ). According to the preceding ECONNRESET error, writing data to a FIN_WAIT2 service TCP (with an ACK response to the FIN shard) is not a problem, but writing a Socket that has received the RST is an error.
ETIMEDOUT
The error is described as "connect time out", that is, "connection timeout". This usually occurs when the server host crashes. At this time, the customer TCP will continuously resend the data shard within a certain period of time (according to the specific implementation), trying to get an ACK shard from the service TCP. After the attempt is finally abandoned (the server is not restarted at this time), the kernel will return the ETIMEDOUT error to the client process. If an intermediate router determines that the server host is no longer reachable, it will generally respond to the ICMP message of "destination unreachable"-"destination inaccessible, the error returned by the corresponding customer process is EHOSTUNREACH or ENETUNREACH. After the server is restarted, all the previous connection information does not exist because the TCP status is lost. In this case, the client will respond to the RST request. If the customer process is necessary to detect whether the server host is crashed and requires that the customer process detect the failure even if the customer process does not actively send data, other technologies are required, such as configuring the SO_KEEPALIVE Socket option, or implement some heartbeat functions.
Author: lzy. je
Source: http://lzy.javaeye.com
This article is copyrighted by the author and can only be reproduced in the abstract and full text formats. Text cropping is not allowed. This statement must be retained without the author's consent, and the original article connection is clearly provided on the article page; otherwise, the right to pursue legal liability will be retained.
// 2009.05.20 add ////
ENOPROTOOPT
This error is not related to a Socket connection. Errno indicates this value. This error may occur if an option parameter that is not supported by the system is found when the system calls getsockopt to obtain the current option status of a socket.
Getsockopt/setsockopt (2) man page writes getsockopt, setsockopt -- get and set options on sockets.
# Include <sys/socket. h>
Int getsockopt (INT socket, int level, int option_name,
Void * restrict option_value, socklen_t * restrict option_len );
Int setsockopt (INT socket, int level, int option_name,
Const void * option_value, socklen_t option_len );
Getsockopt () and setsockopt () Manipulate the options associated with a socket. Options may exist at multiple Protocol levels; they are always present at the uppermost "socket" level.
In addition, getsockopt and setsockopt may cause the following errors:
Getsockopt/setsockopt (2) man page writes ERRORS
The getsockopt () and setsockopt () system CILS will succeed unless:
[Ebadf] The argument socket is not a valid file descriptor.
[Efault] The address pointed to by option_value is not in a valid part of the Process dress space. for getsockopt (), this error may also be returned if option_len is not in a valid part of the process address space.
[Einval] the option is invalid at the level indicated.
[Enobufs] insufficient memory buffers are available.
[Enoprotoopt] the option is unknown at the level indicated.
[Enotsock] The argument socket is not a socket (e.g., a plain file ).
The setsockopt () System Call will succeed unless:
[Edom] The argument option_value is out of bounds.
[Eisconn] socket is already connected and a specified option cannot be set while this is the case.