Random fixes, disabled debug in vterm, random crash disappeared, also doing fixes...
authorJohn Hodge <[email protected]>
Wed, 21 Apr 2010 04:29:04 +0000 (12:29 +0800)
committerJohn Hodge <[email protected]>
Wed, 21 Apr 2010 04:29:04 +0000 (12:29 +0800)
Kernel/Makefile.BuildNum
Kernel/arch/x86/proc.c
Kernel/debug.c
Kernel/drv/vga.c
Kernel/drv/vterm.c
Kernel/modules.c
Kernel/vfs/open.c
Modules/Display/VESA/main.c
Modules/IPStack/tcp.c

index bb3445a..bacdc56 100644 (file)
@@ -1 +1 @@
-BUILD_NUM = 1868
+BUILD_NUM = 1933
index 3b5ceb2..6298067 100644 (file)
@@ -779,6 +779,14 @@ void Proc_Scheduler(int CPU)
        #else
                __asm__ __volatile__ ("mov %0, %%cr3"::"a"(thread->MemState.CR3));
        #endif
+       
+       #if 0
+       if(thread->SavedState.ESP > 0xC0000000
+       && thread->SavedState.ESP < thread->KernelStack-0x2000) {
+               Log_Warning("Proc", "Possible bad ESP %p (PID %i)", thread->SavedState.ESP);
+       }
+       #endif
+       
        // Switch threads
        __asm__ __volatile__ (
                "mov %1, %%esp\n\t"     // Restore ESP
index 4b3aeb7..e8e181d 100644 (file)
@@ -52,11 +52,14 @@ int getDebugChar()
        return inb(GDB_SERIAL_PORT);
 }
 
+volatile int   gbInPutChar = 0;
+
 static void Debug_Putchar(char ch)
 {
-       if(giDebug_KTerm != -1)
-               VFS_Write(giDebug_KTerm, 1, &ch);
-
+       #if DEBUG_TO_E9
+       __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) );
+       #endif
+       
        #if DEBUG_TO_SERIAL
        if(!gbDebug_SerialSetup) {
                outb(SERIAL_PORT + 1, 0x00);    // Disable all interrupts
@@ -71,10 +74,12 @@ static void Debug_Putchar(char ch)
        while( (inb(SERIAL_PORT + 5) & 0x20) == 0 );
        outb(SERIAL_PORT, ch);
        #endif
-
-       #if DEBUG_TO_E9
-       __asm__ __volatile__ ( "outb %%al, $0xe9" :: "a"(((Uint8)ch)) );
-       #endif
+       
+       if(gbInPutChar) return ;
+       gbInPutChar = 1;
+       if(giDebug_KTerm != -1)
+               VFS_Write(giDebug_KTerm, 1, &ch);
+       gbInPutChar = 0;
 }
 
 static void Debug_Puts(char *Str)
@@ -272,10 +277,16 @@ void Panic(char *Fmt, ...)
 
 void Debug_SetKTerminal(char *File)
 {
-       if(giDebug_KTerm != -1)
-               VFS_Close(giDebug_KTerm);
-       giDebug_KTerm = VFS_Open(File, VFS_OPENFLAG_WRITE);
-       Log_Log("Debug", "Opened '%s' as 0x%x", File, giDebug_KTerm);
+        int    tmp;
+       if(giDebug_KTerm != -1) {
+               tmp = giDebug_KTerm;
+               giDebug_KTerm = -1;
+               VFS_Close(tmp);
+       }
+       tmp = VFS_Open(File, VFS_OPENFLAG_WRITE);
+       Log_Log("Debug", "Opened '%s' as 0x%x", File, tmp);
+       giDebug_KTerm = tmp;
+       Log_Log("Debug", "Returning to %p", __builtin_return_address(0));
 }
 
 void Debug_Enter(char *FuncName, char *ArgTypes, ...)
index b0c9662..700eae9 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Acess2 VGA Controller Driver
  */
+#define DEBUG  0
 #include <acess.h>
 #include <fs_devfs.h>
 #include <tpl_drv_video.h>
index 92fb6f9..fe2ccd9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Acess2 Virtual Terminal Driver
  */
-#define DEBUG  1
+#define DEBUG  0
 #include <acess.h>
 #include <fs_devfs.h>
 #include <modules.h>
@@ -104,7 +104,6 @@ tVTerm      *gpVT_CurTerm = &gVT_Terminals[0];
 // --- Video State ---
 short  giVT_RealWidth; //!< Real Width
 short  giVT_RealHeight;        //!< Real Height
- int   gbVT_TextMode = 1;
 // --- Driver Handles ---
 char   *gsVT_OutputDevice = NULL;
 char   *gsVT_InputDevice = NULL;
@@ -152,7 +151,6 @@ int VT_Install(char **Arguments)
                                strcpy(gsVT_InputDevice, args[1]);
                                args ++;
                                break;
-                       
                        }
                }
        }
@@ -194,6 +192,7 @@ int VT_Install(char **Arguments)
        // Set kernel output to VT0
        Debug_SetKTerminal("/Devices/VTerm/0");
        
+       Log_Log("VTerm", "Returning %i", MODULE_ERR_OK);
        return MODULE_ERR_OK;
 }
 
@@ -237,7 +236,7 @@ tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name)
 {
         int    num;
        
-       //ENTER("pNode sName", Node, Name);
+       ENTER("pNode sName", Node, Name);
        
        // Open the input and output files if needed
        if(giVT_OutputDevHandle == -2)  VT_InitOutput();
@@ -255,7 +254,7 @@ tVFS_Node *VT_FindDir(tVFS_Node *Node, char *Name)
                return NULL;
        }
        // Return node
-       //LEAVE('p', &gVT_Terminals[num].Node);
+       LEAVE('p', &gVT_Terminals[num].Node);
        return &gVT_Terminals[num].Node;
 }
 
@@ -321,8 +320,8 @@ Uint64 VT_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                }
                break;
        
-       case TERM_MODE_FB:
-       //case TERM_MODE_:
+       //case TERM_MODE_FB:
+       default:
                while(pos < Length)
                {
                        while(term->InputRead == term->InputWrite)      Threads_Yield();
@@ -344,8 +343,6 @@ Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
 {
        tVTerm  *term = &gVT_Terminals[ Node->Inode ];
        
-       //ENTER("pNode XOffset XLength pBuffer",  Node, Offset, Length, Buffer);
-       
        // Write
        switch( term->Mode )
        {
@@ -376,7 +373,6 @@ Uint64 VT_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                }
        }
        
-       //LEAVE('i', 0);
        return 0;
 }
 
@@ -905,7 +901,7 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
                memcpy(
                        Term->Text,
                        &Term->Text[Term->Width],
-                       Term->Width*(Term->Height-1)*VT_SCROLLBACK*sizeof(tVT_Char)
+                       (Term->Width*Term->Height*VT_SCROLLBACK-Term->Width)*sizeof(tVT_Char)
                        );
                
                // Clear last row
@@ -915,11 +911,13 @@ void VT_int_PutChar(tVTerm *Term, Uint32 Ch)
                        Term->Text[ base + i ].Colour = Term->CurColour;
                }
                
+               //LOG("Scrolled buffer");
                VT_int_UpdateScreen( Term, 1 );
        }
        else if(Term->WritePos > Term->Width*Term->Height+Term->ViewPos)
        {
                Term->ViewPos += Term->Width;
+               //LOG("Scrolled screen");
                VT_int_UpdateScreen( Term, 1 );
        }
        else
@@ -939,41 +937,27 @@ void VT_int_UpdateScreen( tVTerm *Term, int UpdateAll )
        
        if( Term->Mode == TERM_MODE_TEXT )
        {
-               if(gbVT_TextMode)
-               {
-                       if(UpdateAll) {
-                               VFS_WriteAt(
-                                       giVT_OutputDevHandle,
-                                       0,
-                                       Term->Width*Term->Height*sizeof(tVT_Char),
-                                       &Term->Text[Term->ViewPos]
-                                       );
-                       } else {
-                                int    pos = Term->WritePos - Term->WritePos % Term->Width;
-                               VFS_WriteAt(
-                                       giVT_OutputDevHandle,
-                                       (pos - Term->ViewPos)*sizeof(tVT_Char),
-                                       Term->Width*sizeof(tVT_Char),
-                                       &Term->Text[pos]
-                                       );
-                       }
-               }
-               else
-               {
-                       //TODO: Do VT Rendered Text
-                       #if 0
-                       if( UpdateAll ) {
-                               VT_RenderText(0, Term->Width*Term->Height, &Term->Text[Term->ViewPos]);
-                       }
-                       else {
-                                int    pos = Term->WritePos - Term->WritePos % Term->Width;
-                               VT_RenderText(
-                                       pos - Term->ViewPos,
-                                       Term->Width,
-                                       &Term->Text[pos]
-                                       );
-                       }
-                       #endif
+               if(UpdateAll) {
+                       //LOG("UpdateAll = 1");
+                       //LOG("VFS_WriteAt(0x%x, 0, %i*sizeof(tVT_Char), &Term->Text[%i])",
+                       //      giVT_OutputDevHandle, Term->Width*Term->Height, Term->ViewPos);
+                       VFS_WriteAt(
+                               giVT_OutputDevHandle,
+                               0,
+                               Term->Width*Term->Height*sizeof(tVT_Char),
+                               &Term->Text[Term->ViewPos]
+                               );
+               } else {
+                        int    pos = Term->WritePos - Term->WritePos % Term->Width;
+                       //LOG("UpdateAll = 0");
+                       //LOG("VFS_WriteAt(0x%x, %i*sizeof(tVT_Char), %i*sizeof(tVT_Char), &Term->Text[%i])",
+                       //      giVT_OutputDevHandle, (pos - Term->ViewPos), Term->Width, pos);
+                       VFS_WriteAt(
+                               giVT_OutputDevHandle,
+                               (pos - Term->ViewPos)*sizeof(tVT_Char),
+                               Term->Width*sizeof(tVT_Char),
+                               &Term->Text[pos]
+                               );
                }
        }
        else
index eb742d4..68d5ba0 100644 (file)
@@ -136,6 +136,7 @@ int Module_int_Initialise(tModule *Module)
                LEAVE_RET('i', ret);
                return ret;
        }
+       LOG("ret = %i", ret);
        
        // Remove from loading list
        gLoadingModules = gLoadingModules->Next;
index d203571..d5e940e 100644 (file)
@@ -759,6 +759,8 @@ tVFS_Handle *VFS_GetHandle(int FD)
 {
        tVFS_Handle     *h;
        
+       //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
+       
        if(FD < 0)      return NULL;
        
        if(FD & VFS_KERNEL_FLAG) {
@@ -771,6 +773,7 @@ tVFS_Handle *VFS_GetHandle(int FD)
        }
        
        if(h->Node == NULL)     return NULL;
+       //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
        return h;
 }
 
index e87ca05..47bcf63 100644 (file)
@@ -37,7 +37,7 @@ tDevFS_Driver gVesa_DriverStruct = {
 };\r
 tSpinlock      glVesa_Lock;\r
 tVM8086        *gpVesa_BiosState;\r
- int   giVesaCurrentMode = -1;\r
+ int   giVesaCurrentMode = 0;\r
  int   giVesaCurrentFormat = VIDEO_BUFFMT_TEXT;\r
  int   giVesaDriverId = -1;\r
 char   *gVesaFramebuffer = (void*)0xC00A0000;\r
@@ -109,6 +109,7 @@ int Vesa_Install(char **Arguments)
                        gVesa_Modes[i].fbSize = 0;\r
                }\r
                \r
+               gVesa_Modes[i].pitch = modeinfo->pitch;\r
                gVesa_Modes[i].width = modeinfo->Xres;\r
                gVesa_Modes[i].height = modeinfo->Yres;\r
                gVesa_Modes[i].bpp = modeinfo->bpp;\r
@@ -152,8 +153,8 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
        // Default Text mode\r
        if( giVesaCurrentMode == 0 )\r
        {\r
-               Uint8   *fb = (Uint8 *)(KERNEL_BASE|0xB8000);\r
-               Uint32  *buf = Buffer;\r
+               Uint16  *fb = (Uint16*)(KERNEL_BASE|0xB8000);\r
+               tVT_Char        *chars = Buffer;\r
                 int    rem;\r
                \r
                if( giVesaCurrentFormat != VIDEO_BUFFMT_TEXT ) {\r
@@ -162,31 +163,31 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                        return -1;\r
                }\r
                \r
-               if( Offset + Length > 25*80*8 ) {\r
+               if( Offset + Length > 25*80*sizeof(tVT_Char) ) {\r
                        Log_Warning("VESA", "Vesa_Write - Framebuffer Overflow");\r
                        LEAVE('i', 0);\r
                        return 0;\r
                }\r
                \r
-               fb += 2*Offset;\r
-               for(rem = Length / sizeof(tVT_Char); rem --; fb += 2)\r
+               fb += 2*(Offset/sizeof(tVT_Char));\r
+               LOG("fb = %p", fb);\r
+               for(rem = Length / sizeof(tVT_Char); rem --; fb ++, chars++)\r
                {\r
-                       if( *buf < 0x80 )\r
-                               *fb = *buf & 0x7F;\r
+                       if( chars->Ch < 0x80 )\r
+                               *fb = chars->Ch & 0x7F;\r
                        else\r
                                *fb = 0x00;\r
-                       buf ++;\r
                        \r
-                       fb[1] = 0;\r
-                       fb[1] |= (*buf & 0x888) == 0x888 ? 0x8 : 0;\r
-                       fb[1] |= (*buf & 0x700) > 0x300 ? 0x4 : 0;\r
-                       fb[1] |= (*buf & 0x070) > 0x030 ? 0x2 : 0;\r
-                       fb[1] |= (*buf & 0x007) > 0x003 ? 0x1 : 0;\r
-                       fb[1] |= (*buf & 0x888000) == 0x888000 ? 0x80 : 0;\r
-                       fb[1] |= (*buf & 0x700000) > 0x300000 ? 0x40 : 0;\r
-                       fb[1] |= (*buf & 0x070000) > 0x030000 ? 0x20 : 0;\r
-                       fb[1] |= (*buf & 0x007000) > 0x003000 ? 0x10 : 0;\r
-                       buf ++;\r
+                       *fb |= (chars->FGCol & 0x888) == 0x888 ? 0x8 : 0;\r
+                       *fb |= (chars->FGCol & 0x700) > 0x300 ? 0x4 : 0;\r
+                       *fb |= (chars->FGCol & 0x070) > 0x030 ? 0x2 : 0;\r
+                       *fb |= (chars->FGCol & 0x007) > 0x003 ? 0x1 : 0;\r
+                       *fb |= (chars->BGCol & 0x888) == 0x888 ? 0x80 : 0;\r
+                       *fb |= (chars->BGCol & 0x700) > 0x300 ? 0x40 : 0;\r
+                       *fb |= (chars->BGCol & 0x070) > 0x030 ? 0x20 : 0;\r
+                       *fb |= (chars->BGCol & 0x007) > 0x003 ? 0x10 : 0;\r
+                       //LOG("%08x (%03x,%03x) = %04x",\r
+                       //      chars->Ch, chars->BGCol, chars->FGCol, *fb);\r
                }\r
                Length /= sizeof(tVT_Char);\r
                Length *= sizeof(tVT_Char);\r
@@ -213,8 +214,10 @@ Uint64 Vesa_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
                \r
                Offset /= sizeof(tVT_Char);\r
                dest = (void*)gVesaFramebuffer;\r
-               x = (Offset % gVesa_Modes[giVesaCurrentMode].width) * giVT_CharWidth;\r
-               y = (Offset / gVesa_Modes[giVesaCurrentMode].width) * giVT_CharHeight;\r
+               LOG("gVesa_Modes[%i].width = %i", giVesaCurrentMode, gVesa_Modes[giVesaCurrentMode].width);\r
+               x = (Offset % (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharWidth;\r
+               y = (Offset / (gVesa_Modes[giVesaCurrentMode].width/giVT_CharWidth)) * giVT_CharHeight;\r
+               LOG("(x,y) = (%i,%i)", x, y);\r
                \r
                // Sanity Check\r
                if(y > gVesa_Modes[giVesaCurrentMode].height) {\r
index a6fb60e..90f3dc9 100644 (file)
@@ -64,30 +64,6 @@ void TCP_Initialise()
        IPv4_RegisterCallback(IP4PROT_TCP, TCP_GetPacket);
 }
 
-/**
- * \brief Open a connection to another host using TCP
- * \param Conn Connection structure
- */
-void TCP_StartConnection(tTCPConnection *Conn)
-{
-       tTCPHeader      hdr;
-
-       Conn->State = TCP_ST_SYN_SENT;
-
-       hdr.SourcePort = htons(Conn->LocalPort);
-       hdr.DestPort = htons(Conn->RemotePort);
-       Conn->NextSequenceSend = rand();
-       hdr.SequenceNumber = htonl(Conn->NextSequenceSend);
-       hdr.DataOffset = (sizeof(tTCPHeader)/4) << 4;
-       hdr.Flags = TCP_FLAG_SYN;
-       hdr.WindowSize = htons(TCP_WINDOW_SIZE);        // Max
-       hdr.Checksum = 0;       // TODO
-       hdr.UrgentPointer = 0;
-       
-       TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr );
-       return ;
-}
-
 /**
  * \brief Sends a packet from the specified connection, calculating the checksums
  * \param Conn Connection
@@ -302,7 +278,7 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head
        
        if( Connection->State == TCP_ST_SYN_SENT )
        {
-               if( Header->Flags & (TCP_FLAG_SYN|TCP_FLAG_ACK) ) {
+               if( (Header->Flags & (TCP_FLAG_SYN|TCP_FLAG_ACK)) == (TCP_FLAG_SYN|TCP_FLAG_ACK) ) {
                        
                        Header->DestPort = Header->SourcePort;
                        Header->SourcePort = htons(Connection->LocalPort);
@@ -313,8 +289,8 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head
                        Header->DataOffset = (sizeof(tTCPHeader)/4) << 4;
                        Log_Log("TCP", "ACKing SYN-ACK");
                        TCP_SendPacket( Connection, sizeof(tTCPHeader), Header );
+                       Connection->State = TCP_ST_OPEN;
                }
-               Connection->State = TCP_ST_OPEN;
        }
        
        // Get length of data
@@ -329,7 +305,8 @@ void TCP_INT_HandleConnectionPacket(tTCPConnection *Connection, tTCPHeader *Head
        // TODO: Check what to do here
        if(Header->Flags & TCP_FLAG_FIN) {
                if( Connection->State == TCP_ST_FIN_SENT ) {
-                       
+                       Connection->State = TCP_ST_FINISHED;
+                       return ;
                }
                else {
                        Connection->State = TCP_ST_FINISHED;
@@ -730,6 +707,8 @@ tVFS_Node *TCP_Client_Init(tInterface *Interface)
        conn->Node.IOCtl = TCP_Client_IOCtl;
        conn->Node.Close = TCP_Client_Close;
 
+       conn->RecievedBuffer = RingBuffer_Create( TCP_RECIEVE_BUFFER_SIZE );
+
        LOCK(&glTCP_OutbountCons);
        conn->Next = gTCP_OutbountCons;
        gTCP_OutbountCons = conn;
@@ -750,9 +729,12 @@ Uint64 TCP_Client_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buff
        size_t  len;
        
        ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
+       LOG("conn = %p", conn);
+       LOG("conn->State = %i", conn->State);
        
        // Check if connection is open
-       while( conn->State == TCP_ST_HALFOPEN ) Threads_Yield();
+       while( conn->State == TCP_ST_HALFOPEN || conn->State == TCP_ST_SYN_SENT )
+               Threads_Yield();
        if( conn->State != TCP_ST_OPEN ) {
                LEAVE('i', 0);
                return 0;
@@ -794,10 +776,9 @@ void TCP_INT_SendDataPacket(tTCPConnection *Connection, size_t Length, void *Dat
        packet->DataOffset = (sizeof(tTCPHeader)/4)*16;
        packet->WindowSize = TCP_WINDOW_SIZE;
        
-       //packet->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
-       packet->AcknowlegementNumber = 0;
+       packet->AcknowlegementNumber = htonl(Connection->NextSequenceRcv);
        packet->SequenceNumber = htonl(Connection->NextSequenceSend);
-       packet->Flags = TCP_FLAG_PSH;   // Hey, ACK if you can!
+       packet->Flags = TCP_FLAG_PSH|TCP_FLAG_ACK;      // Hey, ACK if you can!
        
        memcpy(packet->Options, Data, Length);
        
@@ -817,7 +798,8 @@ Uint64 TCP_Client_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf
        ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
        
        // Check if connection is open
-       while( conn->State == TCP_ST_HALFOPEN ) Threads_Yield();
+       while( conn->State == TCP_ST_HALFOPEN || conn->State == TCP_ST_SYN_SENT )
+               Threads_Yield();
        if( conn->State != TCP_ST_OPEN ) {
                LEAVE('i', 0);
                return 0;
@@ -835,6 +817,33 @@ Uint64 TCP_Client_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buf
        return Length;
 }
 
+/**
+ * \brief Open a connection to another host using TCP
+ * \param Conn Connection structure
+ */
+void TCP_StartConnection(tTCPConnection *Conn)
+{
+       tTCPHeader      hdr;
+
+       Conn->State = TCP_ST_SYN_SENT;
+
+       hdr.SourcePort = htons(Conn->LocalPort);
+       hdr.DestPort = htons(Conn->RemotePort);
+       Conn->NextSequenceSend = rand();
+       hdr.SequenceNumber = htonl(Conn->NextSequenceSend);
+       hdr.DataOffset = (sizeof(tTCPHeader)/4) << 4;
+       hdr.Flags = TCP_FLAG_SYN;
+       hdr.WindowSize = htons(TCP_WINDOW_SIZE);        // Max
+       hdr.Checksum = 0;       // TODO
+       hdr.UrgentPointer = 0;
+       
+       TCP_SendPacket( Conn, sizeof(tTCPHeader), &hdr );
+       
+       Conn->NextSequenceSend ++;
+       Conn->State = TCP_ST_SYN_SENT;
+       return ;
+}
+
 /**
  * \brief Control a client socket
  */
@@ -881,7 +890,7 @@ int TCP_Client_IOCtl(tVFS_Node *Node, int ID, void *Data)
                return 0;
 
        case 7: // Connect
-               if(conn->LocalPort == -1)
+               if(conn->LocalPort == 0xFFFF)
                        conn->LocalPort = TCP_GetUnusedPort();
                if(conn->RemotePort == -1)
                        return 0;
@@ -895,5 +904,23 @@ int TCP_Client_IOCtl(tVFS_Node *Node, int ID, void *Data)
 
 void TCP_Client_Close(tVFS_Node *Node)
 {
-       free(Node->ImplPtr);
+       tTCPConnection  *conn = Node->ImplPtr;
+       tTCPHeader      packet;
+       
+       packet.SourcePort = htons(conn->LocalPort);
+       packet.DestPort = htons(conn->RemotePort);
+       packet.DataOffset = (sizeof(tTCPHeader)/4)*16;
+       packet.WindowSize = TCP_WINDOW_SIZE;
+       
+       packet.AcknowlegementNumber = 0;
+       packet.SequenceNumber = htonl(conn->NextSequenceSend);
+       packet.Flags = TCP_FLAG_FIN;
+       
+       conn->State = TCP_ST_FIN_SENT;
+       
+       TCP_SendPacket( conn, sizeof(tTCPHeader), &packet );
+       
+       while( conn->State == TCP_ST_FIN_SENT ) Threads_Yield();
+       
+       free(conn);
 }

UCC git Repository :: git.ucc.asn.au