Fixed number of sockets in TCP_Echo_Server
This commit is contained in:
parent
ae004dd01c
commit
de97de9223
|
|
@ -159,8 +159,7 @@ struct freertos_sockaddr xClient, xBindAddress;
|
|||
Socket_t xListeningSocket, xConnectedSocket;
|
||||
socklen_t xSize = sizeof( xClient );
|
||||
static const TickType_t xReceiveTimeOut = portMAX_DELAY;
|
||||
const BaseType_t xBacklog = 20;
|
||||
|
||||
const BaseType_t xBacklog = 1;
|
||||
|
||||
#if( ipconfigUSE_TCP_WIN == 1 )
|
||||
WinProperties_t xWinProps;
|
||||
|
|
@ -175,6 +174,8 @@ const BaseType_t xBacklog = 20;
|
|||
/* Just to prevent compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
#ifdef DEBUG_LISTEN_SOCK
|
||||
|
||||
/* Attempt to open the socket. */
|
||||
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
|
||||
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
|
@ -221,6 +222,57 @@ const BaseType_t xBacklog = 20;
|
|||
/* Spawn a task to handle the connection. */
|
||||
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY + 1, &prvServerConnectionInstance_Handle );
|
||||
}
|
||||
|
||||
#else /*DEBUG_LISTEN_SOCK*/
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Delete previous suspended EchoServer task if it was created. */
|
||||
if (prvServerConnectionInstance_Handle && eSuspended == eTaskGetState( prvServerConnectionInstance_Handle) )
|
||||
{
|
||||
vTaskDelete( prvServerConnectionInstance_Handle );
|
||||
}
|
||||
/* Attempt to open the socket. */
|
||||
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
|
||||
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* Set a time out so accept() will just wait for a connection. */
|
||||
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
||||
|
||||
/* Set the window and buffer sizes. */
|
||||
#if( ipconfigUSE_TCP_WIN == 1 )
|
||||
{
|
||||
FreeRTOS_setsockopt( xListeningSocket, 0, FREERTOS_SO_WIN_PROPERTIES|FREERTOS_SO_REUSE_LISTEN_SOCKET, ( void * ) &xWinProps, sizeof( xWinProps ) );
|
||||
}
|
||||
#endif /* ipconfigUSE_TCP_WIN */
|
||||
|
||||
/* Bind the socket to the port that the client task will send to, then
|
||||
listen for incoming connections. */
|
||||
xBindAddress.sin_port = tcpechoPORT_NUMBER;
|
||||
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
|
||||
#if (ipconfigUSE_DHCP == 0)
|
||||
xBindAddress.sin_addr = FreeRTOS_htonl(xNetworkAddressing.ulDefaultIPAddress);
|
||||
#endif
|
||||
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
|
||||
FreeRTOS_listen( xListeningSocket, xBacklog );
|
||||
|
||||
|
||||
/* Wait for a client to connect. */
|
||||
xConnectedSocket = FreeRTOS_accept( xListeningSocket, &xClient, &xSize );
|
||||
configASSERT( xConnectedSocket != FREERTOS_INVALID_SOCKET );
|
||||
//FreeRTOS_debug_printf(("Heap size TCP 0 = %d\n", xPortGetFreeHeapSize()));
|
||||
|
||||
#ifdef DEBUG
|
||||
size_t FreeHeapSize = xPortGetFreeHeapSize();
|
||||
if(FreeHeapSize < 25032)//45520)
|
||||
{
|
||||
FreeRTOS_printf(("[LISTEN_TASK] FreeHeapSize = %d\n", FreeHeapSize));
|
||||
}
|
||||
#endif
|
||||
/* Spawn a task to handle the connection. */
|
||||
xTaskCreate( prvServerConnectionInstance, "EchoServer", usUsedStackSize, ( void * ) xConnectedSocket, tskIDLE_PRIORITY + 1, &prvServerConnectionInstance_Handle );
|
||||
}
|
||||
#endif /*DEBUG_LISTEN_SOCK*/
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
@ -256,7 +308,7 @@ uint8_t *pucRxBuffer;
|
|||
lBytes = FreeRTOS_recv( xConnectedSocket, pucRxBuffer, ipconfigTCP_MSS, 0 );
|
||||
|
||||
/* If data was received, echo it back. */
|
||||
if( lBytes >= 0 )
|
||||
if( lBytes > 0 )
|
||||
{
|
||||
RF_OUT_ENUM state = -1;
|
||||
int8_t enable = -1;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -153,40 +153,7 @@
|
|||
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0GD32F10x_CL -FS08000000 -FL040000 -FP0($$Device:GD32F107VC$Flash\GD32F10x_CL.FLM))</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>752</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>.\FreeRTOS\source\FreeRTOS_TCP_IP.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
<Bp>
|
||||
<Number>1</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>760</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>0</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>0</BreakIfRCount>
|
||||
<Filename>.\FreeRTOS\source\FreeRTOS_TCP_IP.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression></Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<Breakpoint/>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
|
|
@ -288,12 +255,22 @@
|
|||
<WinNumber>1</WinNumber>
|
||||
<ItemText>FreeHeapSize</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>20</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>pucRxBuffer</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>21</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>lBytes,0x0A</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<MemoryWindow1>
|
||||
<Mm>
|
||||
<WinNumber>1</WinNumber>
|
||||
<SubType>0</SubType>
|
||||
<ItemText>frame</ItemText>
|
||||
<ItemText>pucRxBuffer</ItemText>
|
||||
<AccSizeX>0</AccSizeX>
|
||||
</Mm>
|
||||
</MemoryWindow1>
|
||||
|
|
|
|||
|
|
@ -339,7 +339,7 @@
|
|||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls>-D DEBUG -Wno-pragma-pack -Wno-macro-redefined</MiscControls>
|
||||
<Define></Define>
|
||||
<Define>DEBUG_LISTEN_SOCK</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>.\FreeRTOS\source\portable\NetworkInterface\include;.\FreeRTOS\source\include;.\FreeRTOS\source\portable\Compiler\Keil;.\DemoTasks\include;..\GigaDevice_test;.\include;.\PHY</IncludePath>
|
||||
</VariousControls>
|
||||
|
|
|
|||
Loading…
Reference in New Issue