mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
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.
This commit is contained in:
parent
77ca2f6d8f
commit
494c302c7f
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user