diff --git a/os/io.c b/os/io.c index 234c0f33f..714516ee3 100644 --- a/os/io.c +++ b/os/io.c @@ -633,6 +633,24 @@ SetCriticalOutputPending(void) 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 * Copies buf into ClientPtr.buf if it fits (with padding), else @@ -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;