os: un-duplicate code to close client on write failure
There are three copies of the same short sequence of operations to close down a client when a write error occurs. Create a new function, AbortClient, which performs these operations and then call it from the three places. Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-and-Tested-by: Michel Dänzer <michel.daenzer@amd.com>
This commit is contained in:
parent
8475e6360c
commit
a82971b070
34
os/io.c
34
os/io.c
|
@ -632,6 +632,24 @@ SetCriticalOutputPending(void)
|
||||||
CriticalOutputPending = TRUE;
|
CriticalOutputPending = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************
|
||||||
|
* AbortClient:
|
||||||
|
* When a write error occurs to a client, close
|
||||||
|
* the connection and clean things up.
|
||||||
|
*****************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
AbortClient(ClientPtr client)
|
||||||
|
{
|
||||||
|
OsCommPtr oc = client->osPrivate;
|
||||||
|
|
||||||
|
if (oc->trans_conn) {
|
||||||
|
_XSERVTransDisconnect(oc->trans_conn);
|
||||||
|
_XSERVTransClose(oc->trans_conn);
|
||||||
|
oc->trans_conn = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*****************
|
/*****************
|
||||||
* WriteToClient
|
* WriteToClient
|
||||||
* Copies buf into ClientPtr.buf if it fits (with padding), else
|
* Copies buf into ClientPtr.buf if it fits (with padding), else
|
||||||
|
@ -707,11 +725,7 @@ WriteToClient(ClientPtr who, int count, const void *__buf)
|
||||||
FreeOutputs = oco->next;
|
FreeOutputs = oco->next;
|
||||||
}
|
}
|
||||||
else if (!(oco = AllocateOutputBuffer())) {
|
else if (!(oco = AllocateOutputBuffer())) {
|
||||||
if (oc->trans_conn) {
|
AbortClient(who);
|
||||||
_XSERVTransDisconnect(oc->trans_conn);
|
|
||||||
_XSERVTransClose(oc->trans_conn);
|
|
||||||
oc->trans_conn = NULL;
|
|
||||||
}
|
|
||||||
MarkClientException(who);
|
MarkClientException(who);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -892,9 +906,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount)
|
||||||
obuf = realloc(oco->buf, notWritten + BUFSIZE);
|
obuf = realloc(oco->buf, notWritten + BUFSIZE);
|
||||||
}
|
}
|
||||||
if (!obuf) {
|
if (!obuf) {
|
||||||
_XSERVTransDisconnect(oc->trans_conn);
|
AbortClient(who);
|
||||||
_XSERVTransClose(oc->trans_conn);
|
|
||||||
oc->trans_conn = NULL;
|
|
||||||
MarkClientException(who);
|
MarkClientException(who);
|
||||||
oco->count = 0;
|
oco->count = 0;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -921,11 +933,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else {
|
else {
|
||||||
if (oc->trans_conn) {
|
AbortClient(who);
|
||||||
_XSERVTransDisconnect(oc->trans_conn);
|
|
||||||
_XSERVTransClose(oc->trans_conn);
|
|
||||||
oc->trans_conn = NULL;
|
|
||||||
}
|
|
||||||
MarkClientException(who);
|
MarkClientException(who);
|
||||||
oco->count = 0;
|
oco->count = 0;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue