summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorAdam Jackson <ajax@redhat.com>2012-10-16 14:56:14 -0400
committerAdam Jackson <ajax@redhat.com>2013-09-10 13:28:23 -0400
commite2b14a1d3bb27e86ff1d7aaf59af850d06263ef5 (patch)
tree38ee9978a8868e52442679c4584776ca8f3183d1 /os
parent65fca558848acd907483d3c85c7cd4db5560f1b4 (diff)
os: Factor out some common code in input buffer handling
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'os')
-rw-r--r--os/io.c61
1 files changed, 26 insertions, 35 deletions
diff --git a/os/io.c b/os/io.c
index d34bc39b7..380036664 100644
--- a/os/io.c
+++ b/os/io.c
@@ -206,27 +206,17 @@ YieldControlDeath(void)
timesThisConnection = 0;
}
-int
-ReadRequestFromClient(ClientPtr client)
+/* If an input buffer was empty, either free it if it is too big or link it
+ * into our list of free input buffers. This means that different clients can
+ * share the same input buffer (at different times). This was done to save
+ * memory.
+ */
+static void
+NextAvailableInput(OsCommPtr oc)
{
- OsCommPtr oc = (OsCommPtr) client->osPrivate;
- ConnectionInputPtr oci = oc->input;
- int fd = oc->fd;
- unsigned int gotnow, needed;
- int result;
- register xReq *request;
- Bool need_header;
- Bool move_header;
-
- /* If an input buffer was empty, either free it if it is too big
- * or link it into our list of free input buffers. This means that
- * different clients can share the same input buffer (at different
- * times). This was done to save memory.
- */
-
if (AvailableInput) {
if (AvailableInput != oc) {
- register ConnectionInputPtr aci = AvailableInput->input;
+ ConnectionInputPtr aci = AvailableInput->input;
if (aci->size > BUFWATERMARK) {
free(aci->buffer);
@@ -236,10 +226,25 @@ ReadRequestFromClient(ClientPtr client)
aci->next = FreeInputs;
FreeInputs = aci;
}
- AvailableInput->input = (ConnectionInputPtr) NULL;
+ AvailableInput->input = NULL;
}
- AvailableInput = (OsCommPtr) NULL;
+ AvailableInput = NULL;
}
+}
+
+int
+ReadRequestFromClient(ClientPtr client)
+{
+ OsCommPtr oc = (OsCommPtr) client->osPrivate;
+ ConnectionInputPtr oci = oc->input;
+ int fd = oc->fd;
+ unsigned int gotnow, needed;
+ int result;
+ register xReq *request;
+ Bool need_header;
+ Bool move_header;
+
+ NextAvailableInput(oc);
/* make sure we have an input buffer */
@@ -494,22 +499,8 @@ InsertFakeRequest(ClientPtr client, char *data, int count)
int fd = oc->fd;
int gotnow, moveup;
- if (AvailableInput) {
- if (AvailableInput != oc) {
- ConnectionInputPtr aci = AvailableInput->input;
+ NextAvailableInput(oc);
- if (aci->size > BUFWATERMARK) {
- free(aci->buffer);
- free(aci);
- }
- else {
- aci->next = FreeInputs;
- FreeInputs = aci;
- }
- AvailableInput->input = (ConnectionInputPtr) NULL;
- }
- AvailableInput = (OsCommPtr) NULL;
- }
if (!oci) {
if ((oci = FreeInputs))
FreeInputs = oci->next;