diff --git a/examples/platform/nrfconnect/util/test/TestInetCommon.cpp b/examples/platform/nrfconnect/util/test/TestInetCommon.cpp index fd9b20fb9d429a..817250157ed7a6 100644 --- a/examples/platform/nrfconnect/util/test/TestInetCommon.cpp +++ b/examples/platform/nrfconnect/util/test/TestInetCommon.cpp @@ -127,7 +127,7 @@ void ServiceEvents(struct ::timeval & aSleepTime) int selectRes = select(numFDs, &readFDs, &writeFDs, &exceptFDs, &aSleepTime); if (selectRes < 0) { - LOG_INF("select failed: %s", ErrorStr(System::MapErrorPOSIX(errno))); + LOG_INF("select failed: %s", ErrorStr(CHIP_ERROR_POSIX(errno))); return; } #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 2fc3fb98f55b7e..6e45bf338c0136 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -179,7 +179,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved) // Create and start the IO thread. sShutdown = false; pthreadErr = pthread_create(&sIOThread, NULL, IOThreadMain, NULL); - VerifyOrExit(pthreadErr == 0, err = System::MapErrorPOSIX(pthreadErr)); + VerifyOrExit(pthreadErr == 0, err = CHIP_ERROR_POSIX(pthreadErr)); exit: if (err != CHIP_NO_ERROR) diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp index 70b6e096ef583d..45262a8871b10e 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl_POSIX.cpp @@ -64,10 +64,10 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX::_InitChipStack() mShouldRunEventLoop.store(true, std::memory_order_relaxed); int ret = pthread_cond_init(&mEventQueueStoppedCond, nullptr); - VerifyOrReturnError(ret == 0, System::MapErrorPOSIX(ret)); + VerifyOrReturnError(ret == 0, CHIP_ERROR_POSIX(ret)); ret = pthread_mutex_init(&mStateLock, nullptr); - VerifyOrReturnError(ret == 0, System::MapErrorPOSIX(ret)); + VerifyOrReturnError(ret == 0, CHIP_ERROR_POSIX(ret)); mHasValidChipTask = false; @@ -211,11 +211,11 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX::_StartEventLoopTask() { int err; err = pthread_attr_init(&mChipTaskAttr); - VerifyOrReturnError(err == 0, System::MapErrorPOSIX(err)); + VerifyOrReturnError(err == 0, CHIP_ERROR_POSIX(err)); err = pthread_attr_getschedparam(&mChipTaskAttr, &mChipTaskSchedParam); - VerifyOrReturnError(err == 0, System::MapErrorPOSIX(err)); + VerifyOrReturnError(err == 0, CHIP_ERROR_POSIX(err)); err = pthread_attr_setschedpolicy(&mChipTaskAttr, SCHED_RR); - VerifyOrReturnError(err == 0, System::MapErrorPOSIX(err)); + VerifyOrReturnError(err == 0, CHIP_ERROR_POSIX(err)); // // We need to grab the lock here since we have to protect setting @@ -233,7 +233,7 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX::_StartEventLoopTask() pthread_mutex_unlock(&mStateLock); - return System::MapErrorPOSIX(err); + return CHIP_ERROR_POSIX(err); } template @@ -290,7 +290,7 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX::_StopEventLoopTask() exit: mHasValidChipTask = false; - return System::MapErrorPOSIX(err); + return CHIP_ERROR_POSIX(err); } template diff --git a/src/inet/DNSResolver.cpp b/src/inet/DNSResolver.cpp index 3f3047a6d62fca..d7ba426773e04e 100644 --- a/src/inet/DNSResolver.cpp +++ b/src/inet/DNSResolver.cpp @@ -477,7 +477,7 @@ CHIP_ERROR DNSResolver::ProcessGetAddrInfoResult(int returnCode, struct addrinfo err = INET_ERROR_DNS_TRY_AGAIN; break; case EAI_SYSTEM: - err = chip::System::MapErrorPOSIX(errno); + err = CHIP_ERROR_POSIX(errno); break; default: err = INET_ERROR_DNS_NO_RECOVERY; diff --git a/src/inet/IPEndPointBasis.cpp b/src/inet/IPEndPointBasis.cpp index fdb47db8976ef7..58511770563845 100644 --- a/src/inet/IPEndPointBasis.cpp +++ b/src/inet/IPEndPointBasis.cpp @@ -198,7 +198,7 @@ static CHIP_ERROR SocketsSetMulticastLoopback(int aSocket, bool aLoopback, int a const unsigned int lValue = aLoopback; if (setsockopt(aSocket, aProtocol, aOption, &lValue, sizeof(lValue)) != 0) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } return CHIP_NO_ERROR; @@ -265,7 +265,7 @@ static CHIP_ERROR SocketsIPv4JoinLeaveMulticastGroup(int aSocket, InterfaceId aI if (setsockopt(aSocket, IPPROTO_IP, aCommand, &lMulticastRequest, sizeof(lMulticastRequest)) != 0) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } return CHIP_NO_ERROR; } @@ -287,7 +287,7 @@ static CHIP_ERROR SocketsIPv6JoinLeaveMulticastGroup(int aSocket, InterfaceId aI if (setsockopt(aSocket, IPPROTO_IPV6, aCommand, &lMulticastRequest, sizeof(lMulticastRequest)) != 0) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } return CHIP_NO_ERROR; } @@ -684,7 +684,7 @@ CHIP_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, const IPAddress & a sa.sin6_scope_id = static_cast(aInterfaceId); if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) - lRetval = chip::System::MapErrorPOSIX(errno); + lRetval = CHIP_ERROR_POSIX(errno); // Instruct the kernel that any messages to multicast destinations should be // sent down the interface specified by the caller. @@ -713,7 +713,7 @@ CHIP_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, const IPAddress & a sa.sin_addr = aAddress.ToIPv4(); if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) - lRetval = chip::System::MapErrorPOSIX(errno); + lRetval = CHIP_ERROR_POSIX(errno); // Instruct the kernel that any messages to multicast destinations should be // sent down the interface to which the specified IPv4 address is bound. @@ -750,7 +750,7 @@ CHIP_ERROR IPEndPointBasis::BindInterface(IPAddressType aAddressType, InterfaceI // Stop interface-based filtering. if (setsockopt(mSocket, SOL_SOCKET, SO_BINDTODEVICE, "", 0) == -1) { - lRetval = chip::System::MapErrorPOSIX(errno); + lRetval = CHIP_ERROR_POSIX(errno); } } else @@ -760,13 +760,13 @@ CHIP_ERROR IPEndPointBasis::BindInterface(IPAddressType aAddressType, InterfaceI if (if_indextoname(aInterfaceId, lInterfaceName) == NULL) { - lRetval = chip::System::MapErrorPOSIX(errno); + lRetval = CHIP_ERROR_POSIX(errno); } if (lRetval == CHIP_NO_ERROR && setsockopt(mSocket, SOL_SOCKET, SO_BINDTODEVICE, lInterfaceName, socklen_t(strlen(lInterfaceName))) == -1) { - lRetval = chip::System::MapErrorPOSIX(errno); + lRetval = CHIP_ERROR_POSIX(errno); } } @@ -899,7 +899,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: // Send IP packet. const ssize_t lenSent = sendmsg(mSocket, &msgHeader, 0); if (lenSent == -1) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); if (lenSent != aBuffer->DataLength()) return CHIP_ERROR_OUTBOUND_MESSAGE_TOO_BIG; return CHIP_NO_ERROR; @@ -930,13 +930,13 @@ CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int mSocket = ::socket(family, aType, aProtocol); if (mSocket == -1) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); ReturnErrorOnFailure(static_cast(Layer().SystemLayer())->StartWatchingSocket(mSocket, &mWatch)); mAddrType = aAddressType; // NOTE WELL: the errors returned by setsockopt() here are not - // returned as Inet layer chip::System::MapErrorPOSIX(errno) + // returned as Inet layer CHIP_ERROR_POSIX(errno) // codes because they are normally expected to fail on some // platforms where the socket option code is defined in the // header files but not [yet] implemented. Certainly, there is @@ -1052,7 +1052,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort) if (rcvLen < 0) { - lStatus = chip::System::MapErrorPOSIX(errno); + lStatus = CHIP_ERROR_POSIX(errno); } else if (rcvLen > lBuffer->AvailableDataLength()) { @@ -1131,7 +1131,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort) } else { - if (OnReceiveError != nullptr && lStatus != chip::System::MapErrorPOSIX(EAGAIN)) + if (OnReceiveError != nullptr && lStatus != CHIP_ERROR_POSIX(EAGAIN)) { OnReceiveError(this, lStatus, nullptr); } @@ -1227,7 +1227,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System: nw_connection_send(mConnection, content, NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, true, ^(nw_error_t error) { if (error) { - res = chip::System::MapErrorPOSIX(nw_error_get_error_code(error)); + res = CHIP_ERROR_POSIX(nw_error_get_error_code(error)); } else { @@ -1258,7 +1258,7 @@ void IPEndPointBasis::HandleDataReceived(const nw_connection_t & aConnection) errno = nw_error_get_error_code(receive_error); if (!(error_domain == nw_error_domain_posix && errno == ECANCELED)) { - CHIP_ERROR error = chip::System::MapErrorPOSIX(errno); + CHIP_ERROR error = CHIP_ERROR_POSIX(errno); IPPacketInfo packetInfo; GetPacketInfo(aConnection, packetInfo); dispatch_async(mDispatchQueue, ^{ @@ -1402,7 +1402,7 @@ CHIP_ERROR IPEndPointBasis::StartListener() case nw_listener_state_failed: ChipLogDetail(Inet, "Listener: Failed"); - res = chip::System::MapErrorPOSIX(nw_error_get_error_code(error)); + res = CHIP_ERROR_POSIX(nw_error_get_error_code(error)); break; case nw_listener_state_ready: @@ -1458,7 +1458,7 @@ CHIP_ERROR IPEndPointBasis::StartConnection(nw_connection_t & aConnection) case nw_connection_state_failed: ChipLogDetail(Inet, "Connection: Failed"); - res = chip::System::MapErrorPOSIX(nw_error_get_error_code(error)); + res = CHIP_ERROR_POSIX(nw_error_get_error_code(error)); break; case nw_connection_state_ready: diff --git a/src/inet/InetInterface.cpp b/src/inet/InetInterface.cpp index 6933fc98276834..42e431106a962f 100644 --- a/src/inet/InetInterface.cpp +++ b/src/inet/InetInterface.cpp @@ -99,7 +99,7 @@ DLL_EXPORT CHIP_ERROR GetInterfaceName(InterfaceId intfId, char * nameBuf, size_ #if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS char intfName[IF_NAMESIZE]; if (if_indextoname(intfId, intfName) == nullptr) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); if (strlen(intfName) >= nameBufSize) return CHIP_ERROR_NO_MEMORY; strcpy(nameBuf, intfName); @@ -172,7 +172,7 @@ DLL_EXPORT CHIP_ERROR InterfaceNameToId(const char * intfName, InterfaceId & int #if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS intfId = if_nametoindex(intfName); if (intfId == 0) - return (errno == ENXIO) ? INET_ERROR_UNKNOWN_INTERFACE : chip::System::MapErrorPOSIX(errno); + return (errno == ENXIO) ? INET_ERROR_UNKNOWN_INTERFACE : CHIP_ERROR_POSIX(errno); return CHIP_NO_ERROR; #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS diff --git a/src/inet/InetLayer.cpp b/src/inet/InetLayer.cpp index 0f3c1980aefac5..14357b97a589b2 100644 --- a/src/inet/InetLayer.cpp +++ b/src/inet/InetLayer.cpp @@ -184,7 +184,7 @@ CHIP_ERROR InetLayer::InitQueueLimiter(void) { if (sem_init(&mDroppableEvents, 0, INET_CONFIG_MAX_DROPPABLE_EVENTS) != 0) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } return CHIP_NO_ERROR; } diff --git a/src/inet/TCPEndPoint.cpp b/src/inet/TCPEndPoint.cpp index fbc644fd573e79..9ed434decde1ae 100644 --- a/src/inet/TCPEndPoint.cpp +++ b/src/inet/TCPEndPoint.cpp @@ -223,7 +223,7 @@ CHIP_ERROR TCPEndPoint::Bind(IPAddressType addrType, const IPAddress & addr, uin sa.sin6_scope_id = 0; if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) - res = chip::System::MapErrorPOSIX(errno); + res = CHIP_ERROR_POSIX(errno); } #if INET_CONFIG_ENABLE_IPV4 else if (addrType == kIPAddressType_IPv4) @@ -235,7 +235,7 @@ CHIP_ERROR TCPEndPoint::Bind(IPAddressType addrType, const IPAddress & addr, uin sa.sin_addr = addr.ToIPv4(); if (bind(mSocket, reinterpret_cast(&sa), static_cast(sizeof(sa))) != 0) - res = chip::System::MapErrorPOSIX(errno); + res = CHIP_ERROR_POSIX(errno); } #endif // INET_CONFIG_ENABLE_IPV4 else @@ -299,7 +299,7 @@ CHIP_ERROR TCPEndPoint::Listen(uint16_t backlog) if (listen(mSocket, backlog) != 0) { - res = chip::System::MapErrorPOSIX(errno); + res = CHIP_ERROR_POSIX(errno); } else { @@ -450,7 +450,7 @@ CHIP_ERROR TCPEndPoint::Connect(const IPAddress & addr, uint16_t port, Interface int r = setsockopt(mSocket, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)); if (r < 0 && errno != EACCES) { - return res = chip::System::MapErrorPOSIX(errno); + return res = CHIP_ERROR_POSIX(errno); } if (r < 0) @@ -516,7 +516,7 @@ CHIP_ERROR TCPEndPoint::Connect(const IPAddress & addr, uint16_t port, Interface if (conRes == -1 && errno != EINPROGRESS) { - res = chip::System::MapErrorPOSIX(errno); + res = CHIP_ERROR_POSIX(errno); DoClose(res, true); return res; } @@ -633,7 +633,7 @@ CHIP_ERROR TCPEndPoint::GetPeerInfo(IPAddress * retAddr, uint16_t * retPort) con socklen_t saLen = sizeof(sa); if (getpeername(mSocket, &sa.any, &saLen) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); if (sa.any.sa_family == AF_INET6) { @@ -704,7 +704,7 @@ CHIP_ERROR TCPEndPoint::GetLocalInfo(IPAddress * retAddr, uint16_t * retPort) socklen_t saLen = sizeof(sa); if (getsockname(mSocket, &sa.any, &saLen) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); if (sa.any.sa_family == AF_INET6) { @@ -754,7 +754,7 @@ CHIP_ERROR TCPEndPoint::GetInterfaceId(InterfaceId * retInterface) if (getpeername(mSocket, &sa.any, &saLen) != 0) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } if (sa.any.sa_family == AF_INET6) @@ -879,7 +879,7 @@ CHIP_ERROR TCPEndPoint::EnableNoDelay() // Disable TCP Nagle buffering by setting TCP_NODELAY socket option to true val = 1; if (setsockopt(mSocket, TCP_SOCKOPT_LEVEL, TCP_NODELAY, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); #endif // defined(TCP_NODELAY) } @@ -937,22 +937,22 @@ CHIP_ERROR TCPEndPoint::EnableKeepAlive(uint16_t interval, uint16_t timeoutCount // Set the idle interval val = interval; if (setsockopt(mSocket, TCP_SOCKOPT_LEVEL, TCP_IDLE_INTERVAL_OPT_NAME, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); // Set the probe retransmission interval. val = interval; if (setsockopt(mSocket, TCP_SOCKOPT_LEVEL, TCP_KEEPINTVL, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); // Set the probe timeout count val = timeoutCount; if (setsockopt(mSocket, TCP_SOCKOPT_LEVEL, TCP_KEEPCNT, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); // Enable keepalives for the connection. val = 1; // enable if (setsockopt(mSocket, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -1013,7 +1013,7 @@ CHIP_ERROR TCPEndPoint::DisableKeepAlive() // Disable keepalives on the connection. val = 0; // disable if (setsockopt(mSocket, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS @@ -1063,7 +1063,7 @@ CHIP_ERROR TCPEndPoint::SetUserTimeout(uint32_t userTimeoutMillis) // Set the user timeout uint32_t val = userTimeoutMillis; if (setsockopt(mSocket, TCP_SOCKOPT_LEVEL, TCP_USER_TIMEOUT, &val, sizeof(val)) != 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); #else // TCP_USER_TIMEOUT res = CHIP_ERROR_NOT_IMPLEMENTED; #endif // defined(TCP_USER_TIMEOUT) @@ -1379,7 +1379,7 @@ CHIP_ERROR TCPEndPoint::DriveSending() // Pretend send() fails in the while loop below INET_FAULT_INJECT(FaultInjection::kFault_Send, { - err = chip::System::MapErrorPOSIX(EIO); + err = CHIP_ERROR_POSIX(EIO); DoClose(err, false); return err; }); @@ -1393,7 +1393,7 @@ CHIP_ERROR TCPEndPoint::DriveSending() if (lenSentRaw == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK) - err = (errno == EPIPE) ? INET_ERROR_PEER_DISCONNECTED : chip::System::MapErrorPOSIX(errno); + err = (errno == EPIPE) ? INET_ERROR_PEER_DISCONNECTED : CHIP_ERROR_POSIX(errno); break; } @@ -1473,7 +1473,7 @@ CHIP_ERROR TCPEndPoint::DriveSending() if (State == kState_SendShutdown && mSendQueue.IsNull()) { if (shutdown(mSocket, SHUT_WR) != 0) - err = chip::System::MapErrorPOSIX(errno); + err = CHIP_ERROR_POSIX(errno); } } @@ -2425,7 +2425,7 @@ CHIP_ERROR TCPEndPoint::GetSocket(IPAddressType addrType) return INET_ERROR_WRONG_ADDRESS_TYPE; mSocket = ::socket(family, SOCK_STREAM | SOCK_FLAGS, 0); if (mSocket == -1) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); ReturnErrorOnFailure(static_cast(Layer().SystemLayer())->StartWatchingSocket(mSocket, &mWatch)); mAddrType = addrType; @@ -2498,7 +2498,7 @@ void TCPEndPoint::HandlePendingIO(System::SocketEvents events) // The socket option SO_ERROR is not available. int osConRes = 0; #endif - CHIP_ERROR conRes = chip::System::MapErrorPOSIX(osConRes); + CHIP_ERROR conRes = CHIP_ERROR_POSIX(osConRes); // Process the connection result. HandleConnectComplete(conRes); @@ -2601,7 +2601,7 @@ void TCPEndPoint::ReceiveData() return; } - DoClose(chip::System::MapErrorPOSIX(systemErrno), false); + DoClose(CHIP_ERROR_POSIX(systemErrno), false); } else @@ -2680,7 +2680,7 @@ void TCPEndPoint::HandleIncomingConnection() } else { - err = chip::System::MapErrorPOSIX(errno); + err = CHIP_ERROR_POSIX(errno); } } @@ -2776,7 +2776,7 @@ CHIP_ERROR TCPEndPoint::CheckConnectionProgress(bool & isProgressing) if (ioctl(mSocket, TIOCOUTQ, &currPendingBytesRaw) < 0) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } if (!CanCastTo(currPendingBytesRaw)) diff --git a/src/inet/tests/TestInetEndPoint.cpp b/src/inet/tests/TestInetEndPoint.cpp index f9390ab64115c2..9e80a769d97150 100644 --- a/src/inet/tests/TestInetEndPoint.cpp +++ b/src/inet/tests/TestInetEndPoint.cpp @@ -210,7 +210,7 @@ static void TestInetError(nlTestSuite * inSuite, void * inContext) { CHIP_ERROR err = CHIP_NO_ERROR; - err = MapErrorPOSIX(EPERM); + err = CHIP_ERROR_POSIX(EPERM); NL_TEST_ASSERT(inSuite, DescribeErrorPOSIX(err)); NL_TEST_ASSERT(inSuite, err.IsRange(ChipError::Range::kPOSIX)); } diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h index fed85a0e588d6e..f7f3100fba048e 100644 --- a/src/lib/core/CHIPConfig.h +++ b/src/lib/core/CHIPConfig.h @@ -2038,8 +2038,8 @@ #if CHIP_SYSTEM_CONFIG_USE_SOCKETS #define _CHIP_CONFIG_IsPlatformPOSIXErrorNonCritical(CODE) \ - ((CODE) == chip::System::MapErrorPOSIX(EHOSTUNREACH) || (CODE) == chip::System::MapErrorPOSIX(ENETUNREACH) || \ - (CODE) == chip::System::MapErrorPOSIX(EADDRNOTAVAIL) || (CODE) == chip::System::MapErrorPOSIX(EPIPE)) + ((CODE) == CHIP_ERROR_POSIX(EHOSTUNREACH) || (CODE) == CHIP_ERROR_POSIX(ENETUNREACH) || \ + (CODE) == CHIP_ERROR_POSIX(EADDRNOTAVAIL) || (CODE) == CHIP_ERROR_POSIX(EPIPE)) #else // !CHIP_SYSTEM_CONFIG_USE_SOCKETS #define _CHIP_CONFIG_IsPlatformPOSIXErrorNonCritical(CODE) 0 #endif // !CHIP_SYSTEM_CONFIG_USE_SOCKETS diff --git a/src/messaging/ErrorCategory.cpp b/src/messaging/ErrorCategory.cpp index d213cf734a3d14..f0dca6cd795e47 100644 --- a/src/messaging/ErrorCategory.cpp +++ b/src/messaging/ErrorCategory.cpp @@ -37,7 +37,7 @@ bool IsIgnoredMulticastSendError(CHIP_ERROR err) #if CHIP_SYSTEM_CONFIG_USE_LWIP err == System::MapErrorLwIP(ERR_RTE) #else - err == System::MapErrorPOSIX(ENETUNREACH) || err == System::MapErrorPOSIX(EADDRNOTAVAIL) + err == CHIP_ERROR_POSIX(ENETUNREACH) || err == CHIP_ERROR_POSIX(EADDRNOTAVAIL) #endif ; } @@ -57,7 +57,7 @@ CHIP_ERROR FilterUDPSendError(CHIP_ERROR err, bool isMulticast) #endif // CHIP_SYSTEM_CONFIG_USE_LWIP #if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK - if (err == System::MapErrorPOSIX(ENETUNREACH) || err == System::MapErrorPOSIX(EADDRNOTAVAIL)) + if (err == CHIP_ERROR_POSIX(ENETUNREACH) || err == CHIP_ERROR_POSIX(EADDRNOTAVAIL)) { err = CHIP_NO_ERROR; } diff --git a/src/system/SystemError.cpp b/src/system/SystemError.cpp index 6c80774a346d1f..6b79bc14d35b68 100644 --- a/src/system/SystemError.cpp +++ b/src/system/SystemError.cpp @@ -47,6 +47,7 @@ namespace chip { namespace System { +namespace Internal { /** * This implements a mapping function for CHIP System Layer errors that allows mapping integers in the number space of the * underlying POSIX network and OS stack errors into a platform- or system-specific range. Error codes beyond those currently @@ -61,6 +62,13 @@ DLL_EXPORT CHIP_ERROR MapErrorPOSIX(int aError) return (aError == 0 ? CHIP_NO_ERROR : CHIP_ERROR(ChipError::Range::kPOSIX, static_cast(aError))); } +DLL_EXPORT CHIP_ERROR MapErrorPOSIX(int aError, const char * file, unsigned int line) +{ + return (aError == 0 ? CHIP_NO_ERROR + : CHIP_ERROR(ChipError::Range::kPOSIX, static_cast(aError), file, line)); +} +} // namespace Internal + /** * This implements a function to return an NULL-terminated OS-specific descriptive C string, associated with the specified, mapped * OS error. @@ -124,7 +132,7 @@ bool FormatPOSIXError(char * buf, uint16_t bufSize, CHIP_ERROR err) */ DLL_EXPORT CHIP_ERROR MapErrorZephyr(int aError) { - return MapErrorPOSIX(-aError); + return Internal::MapErrorPOSIX(-aError); } #if CHIP_SYSTEM_CONFIG_USE_LWIP diff --git a/src/system/SystemError.h b/src/system/SystemError.h index 2a76843518325e..37abd6c0b2257a 100644 --- a/src/system/SystemError.h +++ b/src/system/SystemError.h @@ -41,10 +41,20 @@ #ifdef __cplusplus +#if CHIP_CONFIG_ERROR_SOURCE +#define CHIP_ERROR_POSIX(code) chip::System::Internal::MapErrorPOSIX(code, __FILE__, __LINE__) +#else // CHIP_CONFIG_ERROR_SOURCE +#define CHIP_ERROR_POSIX(code) chip::System::Internal::MapErrorPOSIX(code) +#endif // CHIP_CONFIG_ERROR_SOURCE + namespace chip { namespace System { +namespace Internal { extern CHIP_ERROR MapErrorPOSIX(int code); +extern CHIP_ERROR MapErrorPOSIX(int code, const char * file, unsigned int line); +} // namespace Internal + extern const char * DescribeErrorPOSIX(CHIP_ERROR code); extern void RegisterPOSIXErrorFormatter(); extern bool FormatPOSIXError(char * buf, uint16_t bufSize, CHIP_ERROR err); diff --git a/src/system/SystemLayerImplLibevent.cpp b/src/system/SystemLayerImplLibevent.cpp index 883cefe59fe72b..8c690d63912f9b 100644 --- a/src/system/SystemLayerImplLibevent.cpp +++ b/src/system/SystemLayerImplLibevent.cpp @@ -345,7 +345,7 @@ CHIP_ERROR LayerImplLibevent::UpdateWatch(SocketWatch * watch, short eventFlags) if ((flags & O_NONBLOCK) == 0) { int status = ::fcntl(watch->mFD, F_SETFL, flags | O_NONBLOCK); - VerifyOrReturnError(status == 0, chip::System::MapErrorPOSIX(errno)); + VerifyOrReturnError(status == 0, CHIP_ERROR_POSIX(errno)); } watch->mEvent = event_new(mEventBase, watch->mFD, eventFlags, SocketCallbackHandler, watch); VerifyOrReturnError(watch->mEvent != nullptr, CHIP_ERROR_NO_MEMORY); diff --git a/src/system/SystemLayerImplSelect.cpp b/src/system/SystemLayerImplSelect.cpp index 48900f3a21248b..29e9761af24070 100644 --- a/src/system/SystemLayerImplSelect.cpp +++ b/src/system/SystemLayerImplSelect.cpp @@ -375,7 +375,7 @@ void LayerImplSelect::HandleEvents() if (mSelectResult < 0) { - ChipLogError(DeviceLayer, "select failed: %s\n", ErrorStr(System::MapErrorPOSIX(errno))); + ChipLogError(DeviceLayer, "select failed: %s\n", ErrorStr(CHIP_ERROR_POSIX(errno))); return; } diff --git a/src/system/WakeEvent.cpp b/src/system/WakeEvent.cpp index f01d874e399d64..8c6cda1aa8fa87 100644 --- a/src/system/WakeEvent.cpp +++ b/src/system/WakeEvent.cpp @@ -64,13 +64,13 @@ CHIP_ERROR WakeEvent::Open(LayerSockets & systemLayer) int fds[2]; if (::pipe(fds) < 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); if (SetNonBlockingMode(fds[FD_READ]) < 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); if (SetNonBlockingMode(fds[FD_WRITE]) < 0) - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); mReadFD = fds[FD_READ]; mWriteFD = fds[FD_WRITE]; @@ -101,7 +101,7 @@ void WakeEvent::Confirm() res = ::read(mReadFD, buffer, sizeof(buffer)); if (res < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { - ChipLogError(chipSystemLayer, "System wake event confirm failed: %s", ErrorStr(chip::System::MapErrorPOSIX(errno))); + ChipLogError(chipSystemLayer, "System wake event confirm failed: %s", ErrorStr(CHIP_ERROR_POSIX(errno))); return; } } while (res == sizeof(buffer)); @@ -113,7 +113,7 @@ CHIP_ERROR WakeEvent::Notify() if (::write(mWriteFD, &byte, 1) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } return CHIP_NO_ERROR; @@ -126,7 +126,7 @@ CHIP_ERROR WakeEvent::Open(LayerSockets & systemLayer) mReadFD = ::eventfd(0, 0); if (mReadFD == -1) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } ReturnErrorOnFailure(systemLayer.StartWatchingSocket(mReadFD, &mReadWatch)); @@ -149,7 +149,7 @@ void WakeEvent::Confirm() if (::read(mReadFD, &value, sizeof(value)) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { - ChipLogError(chipSystemLayer, "System wake event confirm failed: %s", ErrorStr(chip::System::MapErrorPOSIX(errno))); + ChipLogError(chipSystemLayer, "System wake event confirm failed: %s", ErrorStr(CHIP_ERROR_POSIX(errno))); } } @@ -159,7 +159,7 @@ CHIP_ERROR WakeEvent::Notify() if (::write(mReadFD, &value, sizeof(value)) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { - return chip::System::MapErrorPOSIX(errno); + return CHIP_ERROR_POSIX(errno); } return CHIP_NO_ERROR; diff --git a/src/transport/raw/tests/TestTCP.cpp b/src/transport/raw/tests/TestTCP.cpp index 31324bd457a71f..b5a4a8cbf0848e 100644 --- a/src/transport/raw/tests/TestTCP.cpp +++ b/src/transport/raw/tests/TestTCP.cpp @@ -132,7 +132,7 @@ class MockTransportMgrDelegate : public chip::TransportMgrDelegate // Should be able to send a message to itself by just calling send. err = tcp.SendMessage(Transport::PeerAddress::TCP(addr), std::move(buffer)); - if (err == System::MapErrorPOSIX(EADDRNOTAVAIL)) + if (err == CHIP_ERROR_POSIX(EADDRNOTAVAIL)) { // TODO(#2698): the underlying system does not support IPV6. This early return // should be removed and error should be made fatal. diff --git a/src/transport/raw/tests/TestUDP.cpp b/src/transport/raw/tests/TestUDP.cpp index 85bb9e8ae2d441..a2bbf912babaf7 100644 --- a/src/transport/raw/tests/TestUDP.cpp +++ b/src/transport/raw/tests/TestUDP.cpp @@ -140,7 +140,7 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext, const IPAddress & // Should be able to send a message to itself by just calling send. err = udp.SendMessage(Transport::PeerAddress::UDP(addr, udp.GetBoundPort()), std::move(buffer)); - if (err == System::MapErrorPOSIX(EADDRNOTAVAIL)) + if (err == CHIP_ERROR_POSIX(EADDRNOTAVAIL)) { // TODO(#2698): the underlying system does not support IPV6. This early return // should be removed and error should be made fatal.