fprime/Drv/Ip/test/ut/PortSelector.hpp
M Starch b76d8c9a0c
Update/types refactor as constants (#1623)
* lestarch: adding logical types implementation into Linux/StandardTypes.hpp

* lestarch: removing VxWorks StandardTypes from repository

* updated fprime types for correct compilation with vxworks and baremetal

* lestarch: refactoring types and configuration header w.r.t type design

* lestarch: replacing usages of AssertArg with FwAssertArgType

* lestarch: missspelled configuration

* lestarch: minor compilation fixes

* lestarch: renaming StandardTypes.hpp -> PlatformTypes.hpp

* lestarch: updating PRI tokens

* lestarch: replacing BasicTypes.hpp includes with FpConfig.hpp

* lestarch: UT and compilation fixes for types refactor

* lestarch: sp

* lestarch: fixing RPI issues in PassiveConsoleTextLogger

* lestarch: converting RPI build to debug

* lestarch: removing duplicate config imports

* lestarch: fixing documentation

* lestarch: fixing up multiple definitions and RPI compilation problems

* lestarch: reverting debug build

* lestarch: reverting platform types to class-based constants

* lestarch: reworking basic types

* lestarch: configured types refactor into classes

* lestarch: fixing bugs with static constants in classes

* lestarch: fixing platform types spelling and documentation

* lestarch: adding include guards to types headers

Co-authored-by: Kevin F Ortega <kevin.f.ortega@jpl.nasa.gov>
2022-08-18 13:25:56 -07:00

29 lines
990 B
C++

//
// Created by mstarch on 12/10/20.
//
#include <FpConfig.hpp>
#ifndef DRV_TEST_PORTSELECTOR_HPP
#define DRV_TEST_PORTSELECTOR_HPP
namespace Drv {
namespace Test {
/**
* \brief returns a (currently) unused port
*
* Tests working with TCP often need ports to be unused. This presents a problem when looking to bind to a port that has
* not been used anywhere on the system. This function will walk the process through to the point of getting a bind,
* and use the port 0 to have the OS assign one. At this point, the assigned port will be inspected and the fd will be
* closed without a connection allowing something else to bind to it e.g the test code.
*
* Note: this is test code only as there is a known race condition from the moment of closing the port, to when the
* recipient binds it again.
*
* \param is_udp: is this a UDP port
* \return 0 on error, or a free port on success
*/
U16 get_free_port(bool is_udp = false);
};
};
#endif // DRV_TEST_PORTSELECTOR_HPP