Linux下zeromq write函数变更
文件tcp_socket.cpp中write函数发生变更,可以去github上看master版本的src/tcp_socket.cpp 点这里前往github
说下影响,在之前2.2.0版本,其实write函数是这样的
- int zmq::tcp_socket_t::write (const void *data, int size)
- {
- ssize_t nbytes = send (s, data, size, 0);
- // Several errors are OK. When speculative write is being done we may not
- // be able to write a single byte to the socket. Also, SIGSTOP issued
- // by a debugging tool can result in EINTR error.
- if (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK ||
- errno == EINTR))
- return 0;
- // Signalise peer failure.
- if (nbytes == -1 && (errno == ECONNRESET || errno == EPIPE))
- return -1;
- errno_assert (nbytes != -1);
- return (size_t) nbytes;
- }
最近有碰到在write的时候发生Connection refused 错误也就是errno是ECONNREFUSED,还正在想自己加个过滤算了,不过去了github上看了下最新代码,发现代码变更了
对错误处理的更加友好,而不会向之前对一些比较容易发生的错误直接中断。
下面这部分是直接文本copy过来的。
if (nbytes == -1
&& (errno == ECONNRESET
|| errno == EPIPE
|| errno == ETIMEDOUT))
if (nbytes == -1) {
errno_assert (errno != EACCES
&& errno != EBADF
&& errno != EDESTADDRREQ
&& errno != EFAULT
&& errno != EINVAL
&& errno != EISCONN
&& errno != EMSGSIZE
&& errno != ENOMEM
&& errno != ENOTSOCK
&& errno != EOPNOTSUPP);
return -1;
}
errno_assert (nbytes != -1);
return (size_t) nbytes;
}