Author: cgutman
Date: Tue Apr 30 08:16:29 2013
New Revision: 58895
URL:
http://svn.reactos.org/svn/reactos?rev=58895&view=rev
Log:
[LWIP]
- Don't define mem_trim() to realloc() because mem_trim() must never move the buffer
pointer
- Fix realloc() which was completely broken
- Properly handle a TX|RX shutdown
Modified:
trunk/reactos/lib/drivers/lwip/src/include/arch/cc.h
trunk/reactos/lib/drivers/lwip/src/rosmem.c
trunk/reactos/lib/drivers/lwip/src/rostcp.c
Modified: trunk/reactos/lib/drivers/lwip/src/include/arch/cc.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/lwip/src/inclu…
==============================================================================
--- trunk/reactos/lib/drivers/lwip/src/include/arch/cc.h [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/lwip/src/include/arch/cc.h [iso-8859-1] Tue Apr 30 08:16:29
2013
@@ -15,7 +15,9 @@
void *
realloc(void *mem, size_t size);
-#define mem_trim(_m_, _s_) realloc(_m_, _s_)
+/* mem_trim() must trim the buffer without relocating it.
+ * Since we can't do that, we just return the buffer passed in unchanged */
+#define mem_trim(_m_, _s_) (_m_)
/* Unsigned int types */
typedef unsigned char u8_t;
Modified: trunk/reactos/lib/drivers/lwip/src/rosmem.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/lwip/src/rosme…
==============================================================================
--- trunk/reactos/lib/drivers/lwip/src/rosmem.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/lwip/src/rosmem.c [iso-8859-1] Tue Apr 30 08:16:29 2013
@@ -31,9 +31,36 @@
ExFreePoolWithTag(mem, LWIP_TAG);
}
+/* This is only used to trim in lwIP */
void *
realloc(void *mem, size_t size)
{
+ void* new_mem;
+
+ /* realloc() with a NULL mem pointer acts like a call to malloc() */
+ if (mem == NULL) {
+ return malloc(size);
+ }
+
+ /* realloc() with a size 0 acts like a call to free() */
+ if (size == 0) {
+ free(mem);
+ return NULL;
+ }
+
+ /* Allocate the new buffer first */
+ new_mem = malloc(size);
+ if (new_mem == NULL) {
+ /* The old buffer is still intact */
+ return NULL;
+ }
+
+ /* Copy the data over */
+ RtlCopyMemory(new_mem, mem, size);
+
+ /* Deallocate the old buffer */
free(mem);
- return malloc(size);
+
+ /* Return the newly allocated block */
+ return new_mem;
}
Modified: trunk/reactos/lib/drivers/lwip/src/rostcp.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/lwip/src/rostc…
==============================================================================
--- trunk/reactos/lib/drivers/lwip/src/rostcp.c [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/lwip/src/rostcp.c [iso-8859-1] Tue Apr 30 08:16:29 2013
@@ -631,18 +631,8 @@
goto done;
}
- if (pcb->state == CLOSE_WAIT)
- {
- /* This case actually results in a socket closure later (lwIP bug?) */
- msg->Input.Shutdown.Connection->SocketContext = NULL;
- }
-
msg->Output.Shutdown.Error = tcp_shutdown(pcb, msg->Input.Shutdown.shut_rx,
msg->Input.Shutdown.shut_tx);
- if (msg->Output.Shutdown.Error)
- {
- msg->Input.Shutdown.Connection->SocketContext = pcb;
- }
- else
+ if (!msg->Output.Shutdown.Error)
{
if (msg->Input.Shutdown.shut_rx)
{
@@ -652,6 +642,10 @@
if (msg->Input.Shutdown.shut_tx)
msg->Input.Shutdown.Connection->SendShutdown = TRUE;
+
+ /* Shutting down both sides is like a close to LwIP, so clear the context */
+ if (msg->Input.Shutdown.shut_rx && msg->Input.Shutdown.shut_tx)
+ msg->Input.Shutdown.Connection->SocketContext = NULL;
}
done:
@@ -712,6 +706,7 @@
case CLOSED:
case LISTEN:
case SYN_SENT:
+ case CLOSE_WAIT:
msg->Output.Close.Error = tcp_close(pcb);
if (!msg->Output.Close.Error && msg->Input.Close.Callback)
@@ -719,20 +714,8 @@
break;
default:
- if (msg->Input.Close.Connection->SendShutdown &&
- msg->Input.Close.Connection->ReceiveShutdown)
- {
- /* Abort the connection */
- tcp_abort(pcb);
-
- /* Aborts always succeed */
- msg->Output.Close.Error = ERR_OK;
- }
- else
- {
- /* Start the graceful close process (or send RST for pending data) */
- msg->Output.Close.Error = tcp_close(pcb);
- }
+ /* Start the graceful close process (or send RST for pending data) */
+ msg->Output.Close.Error = tcp_close(pcb);
break;
}