summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-04-29 00:21:47 -0700
committerAdam Jackson <ajax@redhat.com>2017-09-25 15:34:10 -0400
commit7a2525fba60a04a95a4a8b26c2b628dc8fdfdeff (patch)
tree312ac730ca4aa799f75384b23acf982775d4677a /os
parentb3de3ebcf450fd4ab1543dd2f133e45e9c0b9e7e (diff)
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> (cherry picked from commit a82971b07035ee9a4e3ed01326e7c1eab34b5a19)
Diffstat (limited to 'os')
-rw-r--r--os/io.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/os/io.c b/os/io.c
index 234c0f33f..714516ee3 100644
--- a/os/io.c
+++ b/os/io.c
@@ -634,6 +634,24 @@ SetCriticalOutputPending(void)
}
/*****************
+ * 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
* Copies buf into ClientPtr.buf if it fits (with padding), else
* flushes ClientPtr.buf and buf to client. As of this writing,
@@ -708,11 +726,7 @@ WriteToClient(ClientPtr who, int count, const void *__buf)
FreeOutputs = oco->next;
}
else if (!(oco = AllocateOutputBuffer())) {
- if (oc->trans_conn) {
- _XSERVTransDisconnect(oc->trans_conn);
- _XSERVTransClose(oc->trans_conn);
- oc->trans_conn = NULL;
- }
+ AbortClient(who);
MarkClientException(who);
return -1;
}
@@ -893,9 +907,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount)
obuf = realloc(oco->buf, notWritten + BUFSIZE);
}
if (!obuf) {
- _XSERVTransDisconnect(oc->trans_conn);
- _XSERVTransClose(oc->trans_conn);
- oc->trans_conn = NULL;
+ AbortClient(who);
MarkClientException(who);
oco->count = 0;
return -1;
@@ -922,11 +934,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, const void *__extraBuf, int extraCount)
}
#endif
else {
- if (oc->trans_conn) {
- _XSERVTransDisconnect(oc->trans_conn);
- _XSERVTransClose(oc->trans_conn);
- oc->trans_conn = NULL;
- }
+ AbortClient(who);
MarkClientException(who);
oco->count = 0;
return -1;