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>
This commit is contained in:
parent
65fca55884
commit
e2b14a1d3b
65
os/io.c
65
os/io.c
|
@ -206,6 +206,32 @@ YieldControlDeath(void)
|
||||||
timesThisConnection = 0;
|
timesThisConnection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
if (AvailableInput) {
|
||||||
|
if (AvailableInput != oc) {
|
||||||
|
ConnectionInputPtr aci = AvailableInput->input;
|
||||||
|
|
||||||
|
if (aci->size > BUFWATERMARK) {
|
||||||
|
free(aci->buffer);
|
||||||
|
free(aci);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aci->next = FreeInputs;
|
||||||
|
FreeInputs = aci;
|
||||||
|
}
|
||||||
|
AvailableInput->input = NULL;
|
||||||
|
}
|
||||||
|
AvailableInput = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ReadRequestFromClient(ClientPtr client)
|
ReadRequestFromClient(ClientPtr client)
|
||||||
{
|
{
|
||||||
|
@ -218,28 +244,7 @@ ReadRequestFromClient(ClientPtr client)
|
||||||
Bool need_header;
|
Bool need_header;
|
||||||
Bool move_header;
|
Bool move_header;
|
||||||
|
|
||||||
/* If an input buffer was empty, either free it if it is too big
|
NextAvailableInput(oc);
|
||||||
* 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;
|
|
||||||
|
|
||||||
if (aci->size > BUFWATERMARK) {
|
|
||||||
free(aci->buffer);
|
|
||||||
free(aci);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
aci->next = FreeInputs;
|
|
||||||
FreeInputs = aci;
|
|
||||||
}
|
|
||||||
AvailableInput->input = (ConnectionInputPtr) NULL;
|
|
||||||
}
|
|
||||||
AvailableInput = (OsCommPtr) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* make sure we have an input buffer */
|
/* make sure we have an input buffer */
|
||||||
|
|
||||||
|
@ -494,22 +499,8 @@ InsertFakeRequest(ClientPtr client, char *data, int count)
|
||||||
int fd = oc->fd;
|
int fd = oc->fd;
|
||||||
int gotnow, moveup;
|
int gotnow, moveup;
|
||||||
|
|
||||||
if (AvailableInput) {
|
NextAvailableInput(oc);
|
||||||
if (AvailableInput != oc) {
|
|
||||||
ConnectionInputPtr aci = AvailableInput->input;
|
|
||||||
|
|
||||||
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) {
|
||||||
if ((oci = FreeInputs))
|
if ((oci = FreeInputs))
|
||||||
FreeInputs = oci->next;
|
FreeInputs = oci->next;
|
||||||
|
|
Loading…
Reference in New Issue