Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
udpsocket_open_limit.cpp
00001 /* 00002 * Copyright (c) 2018, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "greentea-client/test_env.h" 00019 #include "mbed.h" 00020 #include "udp_tests.h" 00021 #include "UDPSocket.h" 00022 #include "unity/unity.h" 00023 #include "utest.h" 00024 00025 using namespace utest::v1; 00026 00027 namespace { 00028 typedef struct UDPSocketItem { 00029 UDPSocket *sock; 00030 UDPSocketItem *next; 00031 } SocketItem; 00032 } 00033 00034 void UDPSOCKET_OPEN_LIMIT() 00035 { 00036 int open_sockets[2] = {0}; 00037 00038 for (int i = 0; i < 2; i++) { 00039 UDPSocketItem *socket_list_head = NULL; 00040 UDPSocketItem *it; 00041 00042 UDPSocket *sock; 00043 int ret; 00044 while (true) { 00045 sock = new UDPSocket; 00046 if (!sock) { 00047 break; 00048 } 00049 ret = sock->open(get_interface()); 00050 if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET ) { 00051 printf("[round#%02d] unable to open new socket, error: %d\n", i, ret); 00052 delete sock; 00053 break; 00054 } 00055 00056 // Hopefully this doesn't interfere when trying to allocate more sockets 00057 it = new UDPSocketItem; 00058 if (!it) { 00059 delete sock; 00060 break; 00061 } 00062 00063 it->sock = sock; 00064 // Order of items in the list doesn't matter 00065 it->next = socket_list_head; 00066 socket_list_head = it; 00067 } 00068 00069 if (!socket_list_head) { 00070 break; 00071 } 00072 00073 UDPSocketItem *tmp; 00074 for (UDPSocketItem *it = socket_list_head; it;) { 00075 ++open_sockets[i]; 00076 tmp = it; 00077 it = it->next; 00078 socket_list_head = it; 00079 delete tmp->sock; 00080 delete tmp; 00081 } 00082 printf("[round#%02d] %d sockets opened\n", i, open_sockets[i]); 00083 } 00084 TEST_ASSERT_EQUAL(open_sockets[0], open_sockets[1]); 00085 // In case of lwIP one is taken by DHCP -> reduction by one to three 00086 TEST_ASSERT(open_sockets[0] >= 3); 00087 }
Generated on Tue Aug 9 2022 00:37:24 by
1.7.2