提交 494c302c 编写于 作者: P Peter Krempa

rpc: socket: Add possibility to suppress errors on read hangup

In some cases a read error due to connection hangup is expected. This
patch adds a flag that removes the logging of a virError in such case.
上级 77ca2f6d
......@@ -82,6 +82,7 @@ struct _virNetSocket {
int errfd;
bool client;
bool ownsFd;
bool quietEOF;
/* Event callback fields */
virNetSocketIOFunc func;
......@@ -1792,13 +1793,22 @@ static ssize_t virNetSocketReadWire(virNetSocketPtr sock, char *buf, size_t len)
_("Cannot recv data"));
ret = -1;
} else if (ret == 0) {
if (errout)
virReportSystemError(EIO,
_("End of file while reading data: %s"), errout);
else
virReportSystemError(EIO, "%s",
_("End of file while reading data"));
ret = -1;
if (sock->quietEOF) {
VIR_DEBUG("socket='%p' EOF while reading: errout='%s'",
socket, NULLSTR(errout));
ret = -2;
} else {
if (errout)
virReportSystemError(EIO,
_("End of file while reading data: %s"),
errout);
else
virReportSystemError(EIO, "%s",
_("End of file while reading data"));
ret = -1;
}
}
VIR_FREE(errout);
......@@ -2233,3 +2243,17 @@ void virNetSocketClose(virNetSocketPtr sock)
virObjectUnlock(sock);
}
/**
* virNetSocketSetQuietEOF:
* @sock: socket object pointer
*
* Disables reporting I/O errors as a virError when @socket is closed while
* reading data.
*/
void
virNetSocketSetQuietEOF(virNetSocketPtr sock)
{
sock->quietEOF = true;
}
......@@ -143,6 +143,8 @@ int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
int virNetSocketSetBlocking(virNetSocketPtr sock,
bool blocking);
void virNetSocketSetQuietEOF(virNetSocketPtr sock);
ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len);
ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册