Skip to content

Commit

Permalink
fix: don't do name resolution for TCP (fix #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
willeccles committed Aug 6, 2024
1 parent f383292 commit 25964ca
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
38 changes: 18 additions & 20 deletions include/bci/abs/CInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,36 @@ extern "C" {
#define ABS_SCPI_ERR_READ_TIMED_OUT (-8)
/// Not connected
#define ABS_SCPI_ERR_NOT_CONNECTED (-9)
/// Address resolution failed
#define ABS_SCPI_ERR_ADDRESS_RESOLUTION_FAILED (-10)
/// Invalid response from the unit
#define ABS_SCPI_ERR_INVALID_RESPONSE (-11)
#define ABS_SCPI_ERR_INVALID_RESPONSE (-10)
/// Invalid fault type
#define ABS_SCPI_ERR_INVALID_FAULT_TYPE (-12)
#define ABS_SCPI_ERR_INVALID_FAULT_TYPE (-11)
/// Invalid sense range
#define ABS_SCPI_ERR_INVALID_SENSE_RANGE (-13)
#define ABS_SCPI_ERR_INVALID_SENSE_RANGE (-12)
/// Invalid argument
#define ABS_SCPI_ERR_INVALID_ARGUMENT (-14)
#define ABS_SCPI_ERR_INVALID_ARGUMENT (-13)
/// Invalid driver handle
#define ABS_SCPI_ERR_INVALID_DRIVER_HANDLE (-15)
#define ABS_SCPI_ERR_INVALID_DRIVER_HANDLE (-14)
/// Receive not allowed by driver
#define ABS_SCPI_ERR_RECEIVE_NOT_ALLOWED (-16)
#define ABS_SCPI_ERR_RECEIVE_NOT_ALLOWED (-15)
/// Already connected
#define ABS_SCPI_ERR_ALREADY_CONNECTED (-17)
#define ABS_SCPI_ERR_ALREADY_CONNECTED (-16)
/// Unexpected socket error
#define ABS_SCPI_ERR_SOCKET_ERROR (-18)
#define ABS_SCPI_ERR_SOCKET_ERROR (-17)
/// Failed to bind socket
#define ABS_SCPI_ERR_FAILED_TO_BIND_SOCKET (-19)
#define ABS_SCPI_ERR_FAILED_TO_BIND_SOCKET (-18)
/// Failed to open serial port
#define ABS_SCPI_ERR_OPENING_SERIAL_PORT_FAILED (-20)
#define ABS_SCPI_ERR_OPENING_SERIAL_PORT_FAILED (-19)
/// Failed to configure serial port
#define ABS_SCPI_ERR_FAILED_TO_CONFIGURE_PORT (-21)
#define ABS_SCPI_ERR_FAILED_TO_CONFIGURE_PORT (-20)
/// Failed to join multicast group
#define ABS_SCPI_ERR_FAILED_TO_JOIN_GROUP (-22)
#define ABS_SCPI_ERR_FAILED_TO_JOIN_GROUP (-21)
/// Buffer too small
#define ABS_SCPI_ERR_BUFFER_TOO_SMALL (-23)
#define ABS_SCPI_ERR_BUFFER_TOO_SMALL (-22)
/// Allocation failed
#define ABS_SCPI_ERR_ALLOCATION_FAILED (-24)
#define ABS_SCPI_ERR_ALLOCATION_FAILED (-23)
/// Unexpected exception
#define ABS_SCPI_ERR_UNEXPECTED_EXCEPTION (-25)
#define ABS_SCPI_ERR_UNEXPECTED_EXCEPTION (-24)
/** @} */

/**
Expand Down Expand Up @@ -238,9 +236,9 @@ int AbsScpiClient_OpenUdp(AbsScpiClientHandle handle, const char* target_ip,
* @brief Open a TCP connection to the ABS.
*
* @note As a consequence of TCP's design, it is inherently less deterministic
* than UDP. Commanding the ABS over TCP can be much slower and less
* deterministic than UDP, so for time-sensitive applications, it's recommended
* to avoid TCP in favor of UDP.
* than UDP. Commanding the ABS over TCP can be slower and less deterministic
* than UDP, so for time-sensitive applications, it's recommended to avoid TCP
* in favor of UDP.
*
* @param[in] handle SCPI client
* @param[in] target_ip ABS's IP address
Expand Down
31 changes: 15 additions & 16 deletions include/bci/abs/CommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,21 @@ enum class ErrorCode : int {
kReadFailed = -7, ///< Failed to read message
kReadTimedOut = -8, ///< Read timed out
kNotConnected = -9, ///< Not connected
kAddressResolutionFailed = -10, ///< Address resolution failed
kInvalidResponse = -11, ///< Invalid response from the unit
kInvalidFaultType = -12, ///< Invalid fault type
kInvalidSenseRange = -13, ///< Invalid sense range
kInvalidArgument = -14, ///< Invalid argument
kInvalidDriverHandle = -15, ///< Invalid driver handle
kReceiveNotAllowed = -16, ///< Receive not allowed by driver
kAlreadyConnected = -17, ///< Already connected
kSocketError = -18, ///< Unexpected socket error
kFailedToBindSocket = -19, ///< Failed to bind socket
kOpeningSerialPortFailed = -20, ///< Failed to open serial port
kFailedToConfigurePort = -21, ///< Failed to configure serial port
kFailedToJoinGroup = -22, ///< Failed to join multicast group
kBufferTooSmall = -23, ///< Buffer too small
kAllocationFailed = -24, ///< Allocation failed (C only)
kUnexpectedException = -25, ///< Unexpected exception (C only)
kInvalidResponse = -10, ///< Invalid response from the unit
kInvalidFaultType = -11, ///< Invalid fault type
kInvalidSenseRange = -12, ///< Invalid sense range
kInvalidArgument = -13, ///< Invalid argument
kInvalidDriverHandle = -14, ///< Invalid driver handle
kReceiveNotAllowed = -15, ///< Receive not allowed by driver
kAlreadyConnected = -16, ///< Already connected
kSocketError = -17, ///< Unexpected socket error
kFailedToBindSocket = -18, ///< Failed to bind socket
kOpeningSerialPortFailed = -19, ///< Failed to open serial port
kFailedToConfigurePort = -20, ///< Failed to configure serial port
kFailedToJoinGroup = -21, ///< Failed to join multicast group
kBufferTooSmall = -22, ///< Buffer too small
kAllocationFailed = -23, ///< Allocation failed (C only)
kUnexpectedException = -24, ///< Unexpected exception (C only)
};

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const char* ErrorMessage(ErrorCode ec) noexcept {
return "Read timed out";
case ErrorCode::kNotConnected:
return "Not connection";
case ErrorCode::kAddressResolutionFailed:
return "Address resolution failed";
case ErrorCode::kInvalidResponse:
return "Invalid response received from the unit";
case ErrorCode::kInvalidFaultType:
Expand Down
9 changes: 2 additions & 7 deletions src/TcpDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,14 @@ ErrorCode TcpDriver::Impl::Connect(std::string_view ip,

tcp::endpoint endpoint(addr, 5025);

auto iter = tcp::resolver(io_service_).resolve(endpoint, ec);
if (ec) {
return ErrorCode::kAddressResolutionFailed;
}

deadline_.expires_from_now(boost::posix_time::milliseconds(timeout_ms));

// would_block is never set from async_functions, so it's a safe way to signal
// an incomplete async operation
ec = boost::asio::error::would_block;

const auto connect_handler = [&](auto&& e, auto&&) { ec = e; };
boost::asio::async_connect(socket_, iter, connect_handler);
const auto connect_handler = [&](auto&& e) { ec = e; };
socket_.async_connect(endpoint, connect_handler);

do {
io_service_.run_one();
Expand Down

0 comments on commit 25964ca

Please sign in to comment.