diff options
Diffstat (limited to 'src/Mayaqua/Memory.c')
-rw-r--r-- | src/Mayaqua/Memory.c | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/src/Mayaqua/Memory.c b/src/Mayaqua/Memory.c index 2d9bd9f5..3f86ef47 100644 --- a/src/Mayaqua/Memory.c +++ b/src/Mayaqua/Memory.c @@ -3,9 +3,9 @@ //
// SoftEther VPN Server, Client and Bridge are free software under GPLv2.
//
-// Copyright (c) 2012-2015 Daiyuu Nobori.
-// Copyright (c) 2012-2015 SoftEther VPN Project, University of Tsukuba, Japan.
-// Copyright (c) 2012-2015 SoftEther Corporation.
+// Copyright (c) 2012-2016 Daiyuu Nobori.
+// Copyright (c) 2012-2016 SoftEther VPN Project, University of Tsukuba, Japan.
+// Copyright (c) 2012-2016 SoftEther Corporation.
//
// All Rights Reserved.
//
@@ -2478,9 +2478,12 @@ UINT ReadFifo(FIFO *f, void *p, UINT size) f->total_read_size += (UINT64)read_size;
- if (f->size == 0)
+ if (f->fixed == false)
{
- f->pos = 0;
+ if (f->size == 0)
+ {
+ f->pos = 0;
+ }
}
ShrinkFifoMemory(f);
@@ -2500,6 +2503,11 @@ void ShrinkFifoMemory(FIFO *f) return;
}
+ if (f->fixed)
+ {
+ return;
+ }
+
// Rearrange the memory
if (f->pos >= FIFO_INIT_MEM_SIZE &&
f->memsize >= fifo_current_realloc_mem_size &&
@@ -2520,6 +2528,25 @@ void ShrinkFifoMemory(FIFO *f) }
}
+// Write data to the front of FIFO
+void WriteFifoFront(FIFO *f, void *p, UINT size)
+{
+ // Validate arguments
+ if (f == NULL || size == 0)
+ {
+ return;
+ }
+
+ if (f->pos < size)
+ {
+ PadFifoFront(f, size - f->pos);
+ }
+
+ Copy(((UCHAR *)f->p) + (f->pos - size), p, size);
+ f->pos -= size;
+ f->size += size;
+}
+
// Write to the FIFO
void WriteFifo(FIFO *f, void *p, UINT size)
{
@@ -2560,6 +2587,20 @@ void WriteFifo(FIFO *f, void *p, UINT size) KS_INC(KS_WRITE_FIFO_COUNT);
}
+// Add a padding before the head of fifo
+void PadFifoFront(FIFO *f, UINT size)
+{
+ // Validate arguments
+ if (f == NULL || size == 0)
+ {
+ return;
+ }
+
+ f->memsize += size;
+
+ f->p = ReAlloc(f->p, f->memsize);
+}
+
// Clear the FIFO
void ClearFifo(FIFO *f)
{
@@ -2679,6 +2720,10 @@ FIFO *NewFifoFast() }
FIFO *NewFifoEx(bool fast)
{
+ return NewFifoEx2(fast, false);
+}
+FIFO *NewFifoEx2(bool fast, bool fixed)
+{
FIFO *f;
// Memory allocation
@@ -2698,6 +2743,7 @@ FIFO *NewFifoEx(bool fast) f->size = f->pos = 0;
f->memsize = FIFO_INIT_MEM_SIZE;
f->p = Malloc(FIFO_INIT_MEM_SIZE);
+ f->fixed = false;
#ifndef DONT_USE_KERNEL_STATUS
// TrackNewObj(POINTER_TO_UINT64(f), "FIFO", 0);
|