From b7c66f80b8764c0b56e4dcf300f38a0ec1b85bb9 Mon Sep 17 00:00:00 2001 From: Sunghyun Park Date: Wed, 13 Dec 2023 19:42:08 +0000 Subject: [PATCH 1/9] wip --- src/support/pipe.h | 53 ++++++++++++++++++++++++++++++++++++++++++-- src/support/socket.h | 8 +++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/support/pipe.h b/src/support/pipe.h index d869504dc4e9..ef6ad65348f1 100644 --- a/src/support/pipe.h +++ b/src/support/pipe.h @@ -40,6 +40,14 @@ namespace tvm { namespace support { +static int GetLastErrorCode() { +#ifdef _WIN32 + return WSAGetLastError(); +#else + return errno; +#endif + } + /*! \brief Platform independent pipe */ class Pipe : public dmlc::Stream { public: @@ -52,6 +60,43 @@ class Pipe : public dmlc::Stream { #endif /*! \brief destructor */ ~Pipe() { Flush(); } + + /*! + * \brief Call a function and retry if an EINTR error is encountered. + * + * Socket operations can return EINTR when the interrupt handler + * is registered by the execution environment(e.g. python). + * We should retry if there is no KeyboardInterrupt recorded in + * the environment. + * + * \note This function is needed to avoid rare interrupt event + * in long running server code. + * + * \param func The function to retry. + * \return The return code returned by function f or error_value on retry failure. + */ + template + ssize_t RetryCallOnEINTR(FuncType func) { + ssize_t ret = func(); + // common path + if (ret != -1) return ret; + // less common path + do { + if (GetLastErrorCode() == EINTR) { + // Call into env check signals to see if there are + // environment specific(e.g. python) signal exceptions. + // This function will throw an exception if there is + // if the process received a signal that requires TVM to return immediately (e.g. SIGINT). + runtime::EnvCheckSignals(); + } else { + // other errors + return ret; + } + ret = func(); + } while (ret == -1); + return ret; + } + using Stream::Read; using Stream::Write; /*! @@ -68,7 +113,10 @@ class Pipe : public dmlc::Stream { << "Read Error: " << GetLastError(); #else ssize_t nread; - nread = read(handle_, ptr, size); + //nread = read(handle_, ptr, size); + + nread = RetryCallOnEINTR( + [&]() { return read(handle_, ptr, size); }); ICHECK_GE(nread, 0) << "Write Error: " << strerror(errno); #endif return static_cast(nread); @@ -88,7 +136,8 @@ class Pipe : public dmlc::Stream { << "Write Error: " << GetLastError(); #else ssize_t nwrite; - nwrite = write(handle_, ptr, size); + nwrite = RetryCallOnEINTR( + [&]() { return write(handle_, ptr, size); }); ICHECK_EQ(static_cast(nwrite), size) << "Write Error: " << strerror(errno); #endif } diff --git a/src/support/socket.h b/src/support/socket.h index f62702bbc445..009df42e6d2e 100644 --- a/src/support/socket.h +++ b/src/support/socket.h @@ -310,7 +310,7 @@ class Socket { /*! * \return last error of socket operation */ - static int GetLastError() { + static int GetLastErrorCode() { #ifdef _WIN32 return WSAGetLastError(); #else @@ -319,7 +319,7 @@ class Socket { } /*! \return whether last error was would block */ static bool LastErrorWouldBlock() { - int errsv = GetLastError(); + int errsv = GetLastErrorCode(); #ifdef _WIN32 return errsv == WSAEWOULDBLOCK; #else @@ -355,7 +355,7 @@ class Socket { * \param msg The error message. */ static void Error(const char* msg) { - int errsv = GetLastError(); + int errsv = GetLastErrorCode(); #ifdef _WIN32 LOG(FATAL) << "Socket " << msg << " Error:WSAError-code=" << errsv; #else @@ -384,7 +384,7 @@ class Socket { if (ret != -1) return ret; // less common path do { - if (GetLastError() == EINTR) { + if (GetLastErrorCode() == EINTR) { // Call into env check signals to see if there are // environment specific(e.g. python) signal exceptions. // This function will throw an exception if there is From 3dcf2962abe20178c714b9cc54ab256538069823 Mon Sep 17 00:00:00 2001 From: Sunghyun Park Date: Wed, 13 Dec 2023 21:03:37 +0000 Subject: [PATCH 2/9] done --- src/support/err_handling.h | 77 ++++++++++++++++++++++++++++++++++++++ src/support/pipe.h | 45 +--------------------- src/support/socket.h | 49 +----------------------- 3 files changed, 80 insertions(+), 91 deletions(-) create mode 100644 src/support/err_handling.h diff --git a/src/support/err_handling.h b/src/support/err_handling.h new file mode 100644 index 000000000000..46b089cccbc6 --- /dev/null +++ b/src/support/err_handling.h @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file err_handling.h + * \brief Common error handling functions for socket.h and pipe.h + */ +#ifndef TVM_SUPPORT_ERR_HANDLING_H_ +#define TVM_SUPPORT_ERR_HANDLING_H_ +#include + +namespace tvm { +namespace support { + /*! + * \return last error of socket operation + */ + static int GetLastErrorCode() { +#ifdef _WIN32 + return WSAGetLastError(); +#else + return errno; +#endif + } + /*! + * \brief Call a function and retry if an EINTR error is encountered. + * + * Socket operations can return EINTR when the interrupt handler + * is registered by the execution environment(e.g. python). + * We should retry if there is no KeyboardInterrupt recorded in + * the environment. + * + * \note This function is needed to avoid rare interrupt event + * in long running server code. + * + * \param func The function to retry. + * \return The return code returned by function f or error_value on retry failure. + */ + template + inline ssize_t RetryCallOnEINTR(FuncType func) { + ssize_t ret = func(); + // common path + if (ret != -1) return ret; + // less common path + do { + if (GetLastErrorCode() == EINTR) { + // Call into env check signals to see if there are + // environment specific(e.g. python) signal exceptions. + // This function will throw an exception if there is + // if the process received a signal that requires TVM to return immediately (e.g. SIGINT). + runtime::EnvCheckSignals(); + } else { + // other errors + return ret; + } + ret = func(); + } while (ret == -1); + return ret; + } +} // namespace support +} // namespace tvm +#endif // TVM_SUPPORT_ERR_HANDLING_H_ diff --git a/src/support/pipe.h b/src/support/pipe.h index ef6ad65348f1..f35cdab55fbe 100644 --- a/src/support/pipe.h +++ b/src/support/pipe.h @@ -36,18 +36,11 @@ #include #include #endif +#include "../support/err_handling.h" namespace tvm { namespace support { -static int GetLastErrorCode() { -#ifdef _WIN32 - return WSAGetLastError(); -#else - return errno; -#endif - } - /*! \brief Platform independent pipe */ class Pipe : public dmlc::Stream { public: @@ -61,42 +54,6 @@ class Pipe : public dmlc::Stream { /*! \brief destructor */ ~Pipe() { Flush(); } - /*! - * \brief Call a function and retry if an EINTR error is encountered. - * - * Socket operations can return EINTR when the interrupt handler - * is registered by the execution environment(e.g. python). - * We should retry if there is no KeyboardInterrupt recorded in - * the environment. - * - * \note This function is needed to avoid rare interrupt event - * in long running server code. - * - * \param func The function to retry. - * \return The return code returned by function f or error_value on retry failure. - */ - template - ssize_t RetryCallOnEINTR(FuncType func) { - ssize_t ret = func(); - // common path - if (ret != -1) return ret; - // less common path - do { - if (GetLastErrorCode() == EINTR) { - // Call into env check signals to see if there are - // environment specific(e.g. python) signal exceptions. - // This function will throw an exception if there is - // if the process received a signal that requires TVM to return immediately (e.g. SIGINT). - runtime::EnvCheckSignals(); - } else { - // other errors - return ret; - } - ret = func(); - } while (ret == -1); - return ret; - } - using Stream::Read; using Stream::Write; /*! diff --git a/src/support/socket.h b/src/support/socket.h index 009df42e6d2e..a348c8b73332 100644 --- a/src/support/socket.h +++ b/src/support/socket.h @@ -39,7 +39,6 @@ #endif #else #include -#include #include #include #include @@ -58,6 +57,7 @@ #include "../support/ssize.h" #include "../support/utils.h" +#include "../support/err_handling.h" #if defined(_WIN32) static inline int poll(struct pollfd* pfd, int nfds, int timeout) { @@ -307,16 +307,7 @@ class Socket { Error("Socket::Close double close the socket or close without create"); } } - /*! - * \return last error of socket operation - */ - static int GetLastErrorCode() { -#ifdef _WIN32 - return WSAGetLastError(); -#else - return errno; -#endif - } + /*! \return whether last error was would block */ static bool LastErrorWouldBlock() { int errsv = GetLastErrorCode(); @@ -363,42 +354,6 @@ class Socket { #endif } - /*! - * \brief Call a function and retry if an EINTR error is encountered. - * - * Socket operations can return EINTR when the interrupt handler - * is registered by the execution environment(e.g. python). - * We should retry if there is no KeyboardInterrupt recorded in - * the environment. - * - * \note This function is needed to avoid rare interrupt event - * in long running server code. - * - * \param func The function to retry. - * \return The return code returned by function f or error_value on retry failure. - */ - template - ssize_t RetryCallOnEINTR(FuncType func) { - ssize_t ret = func(); - // common path - if (ret != -1) return ret; - // less common path - do { - if (GetLastErrorCode() == EINTR) { - // Call into env check signals to see if there are - // environment specific(e.g. python) signal exceptions. - // This function will throw an exception if there is - // if the process received a signal that requires TVM to return immediately (e.g. SIGINT). - runtime::EnvCheckSignals(); - } else { - // other errors - return ret; - } - ret = func(); - } while (ret == -1); - return ret; - } - protected: explicit Socket(SockType sockfd) : sockfd(sockfd) {} }; From f0befc94a6d871761df052e85a96df17add4abb9 Mon Sep 17 00:00:00 2001 From: Sunghyun Park Date: Wed, 13 Dec 2023 21:15:24 +0000 Subject: [PATCH 3/9] done --- src/support/{err_handling.h => error_handling.h} | 0 src/support/pipe.h | 10 +++------- src/support/socket.h | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) rename src/support/{err_handling.h => error_handling.h} (100%) diff --git a/src/support/err_handling.h b/src/support/error_handling.h similarity index 100% rename from src/support/err_handling.h rename to src/support/error_handling.h diff --git a/src/support/pipe.h b/src/support/pipe.h index f35cdab55fbe..098b327625b9 100644 --- a/src/support/pipe.h +++ b/src/support/pipe.h @@ -36,7 +36,7 @@ #include #include #endif -#include "../support/err_handling.h" +#include "error_handling.h" namespace tvm { namespace support { @@ -69,10 +69,7 @@ class Pipe : public dmlc::Stream { ICHECK(ReadFile(handle_, static_cast(ptr), size, &nread, nullptr)) << "Read Error: " << GetLastError(); #else - ssize_t nread; - //nread = read(handle_, ptr, size); - - nread = RetryCallOnEINTR( + ssize_t nread = RetryCallOnEINTR( [&]() { return read(handle_, ptr, size); }); ICHECK_GE(nread, 0) << "Write Error: " << strerror(errno); #endif @@ -92,8 +89,7 @@ class Pipe : public dmlc::Stream { static_cast(nwrite) == size) << "Write Error: " << GetLastError(); #else - ssize_t nwrite; - nwrite = RetryCallOnEINTR( + ssize_t nwrite = RetryCallOnEINTR( [&]() { return write(handle_, ptr, size); }); ICHECK_EQ(static_cast(nwrite), size) << "Write Error: " << strerror(errno); #endif diff --git a/src/support/socket.h b/src/support/socket.h index a348c8b73332..9a645db83e75 100644 --- a/src/support/socket.h +++ b/src/support/socket.h @@ -55,9 +55,9 @@ #include #include -#include "../support/ssize.h" -#include "../support/utils.h" -#include "../support/err_handling.h" +#include "ssize.h" +#include "utils.h" +#include "error_handling.h" #if defined(_WIN32) static inline int poll(struct pollfd* pfd, int nfds, int timeout) { From 565cda21d9afbe86ffb2f1fe4ca849a73bd9730c Mon Sep 17 00:00:00 2001 From: Lesheng Jin Date: Thu, 14 Dec 2023 16:26:02 +0000 Subject: [PATCH 4/9] fix lint --- src/support/error_handling.h | 90 ++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/support/error_handling.h b/src/support/error_handling.h index 46b089cccbc6..66f327add814 100644 --- a/src/support/error_handling.h +++ b/src/support/error_handling.h @@ -21,57 +21,57 @@ * \file err_handling.h * \brief Common error handling functions for socket.h and pipe.h */ -#ifndef TVM_SUPPORT_ERR_HANDLING_H_ -#define TVM_SUPPORT_ERR_HANDLING_H_ +#ifndef TVM_SUPPORT_ERROR_HANDLING_H_ +#define TVM_SUPPORT_ERROR_HANDLING_H_ #include namespace tvm { namespace support { - /*! - * \return last error of socket operation - */ - static int GetLastErrorCode() { +/*! + * \return last error of socket operation + */ +static int GetLastErrorCode() { #ifdef _WIN32 - return WSAGetLastError(); + return WSAGetLastError(); #else - return errno; + return errno; #endif - } - /*! - * \brief Call a function and retry if an EINTR error is encountered. - * - * Socket operations can return EINTR when the interrupt handler - * is registered by the execution environment(e.g. python). - * We should retry if there is no KeyboardInterrupt recorded in - * the environment. - * - * \note This function is needed to avoid rare interrupt event - * in long running server code. - * - * \param func The function to retry. - * \return The return code returned by function f or error_value on retry failure. - */ - template - inline ssize_t RetryCallOnEINTR(FuncType func) { - ssize_t ret = func(); - // common path - if (ret != -1) return ret; - // less common path - do { - if (GetLastErrorCode() == EINTR) { - // Call into env check signals to see if there are - // environment specific(e.g. python) signal exceptions. - // This function will throw an exception if there is - // if the process received a signal that requires TVM to return immediately (e.g. SIGINT). - runtime::EnvCheckSignals(); - } else { - // other errors - return ret; - } - ret = func(); - } while (ret == -1); - return ret; - } +} +/*! + * \brief Call a function and retry if an EINTR error is encountered. + * + * Socket operations can return EINTR when the interrupt handler + * is registered by the execution environment(e.g. python). + * We should retry if there is no KeyboardInterrupt recorded in + * the environment. + * + * \note This function is needed to avoid rare interrupt event + * in long running server code. + * + * \param func The function to retry. + * \return The return code returned by function f or error_value on retry failure. + */ +template +inline ssize_t RetryCallOnEINTR(FuncType func) { + ssize_t ret = func(); + // common path + if (ret != -1) return ret; + // less common path + do { + if (GetLastErrorCode() == EINTR) { + // Call into env check signals to see if there are + // environment specific(e.g. python) signal exceptions. + // This function will throw an exception if there is + // if the process received a signal that requires TVM to return immediately (e.g. SIGINT). + runtime::EnvCheckSignals(); + } else { + // other errors + return ret; + } + ret = func(); + } while (ret == -1); + return ret; +} } // namespace support } // namespace tvm -#endif // TVM_SUPPORT_ERR_HANDLING_H_ +#endif // TVM_SUPPORT_ERROR_HANDLING_H_ From 311aca2bea00ab3e16bc52f86ddb62258d0b8d33 Mon Sep 17 00:00:00 2001 From: Lesheng Jin Date: Fri, 15 Dec 2023 15:49:09 +0000 Subject: [PATCH 5/9] windows-side support --- src/support/error_handling.h | 16 +++------------ src/support/pipe.h | 40 ++++++++++++++++++++++++++---------- src/support/socket.h | 30 +++++++++++++++++++-------- 3 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/support/error_handling.h b/src/support/error_handling.h index 66f327add814..2a8e98f8c56b 100644 --- a/src/support/error_handling.h +++ b/src/support/error_handling.h @@ -27,16 +27,6 @@ namespace tvm { namespace support { -/*! - * \return last error of socket operation - */ -static int GetLastErrorCode() { -#ifdef _WIN32 - return WSAGetLastError(); -#else - return errno; -#endif -} /*! * \brief Call a function and retry if an EINTR error is encountered. * @@ -51,14 +41,14 @@ static int GetLastErrorCode() { * \param func The function to retry. * \return The return code returned by function f or error_value on retry failure. */ -template -inline ssize_t RetryCallOnEINTR(FuncType func) { +template +inline ssize_t RetryCallOnEINTR(FuncType func, GetErrorCodeFuncType fgeterrorcode) { ssize_t ret = func(); // common path if (ret != -1) return ret; // less common path do { - if (GetLastErrorCode() == EINTR) { + if (fgeterrorcode() == EINTR) { // Call into env check signals to see if there are // environment specific(e.g. python) signal exceptions. // This function will throw an exception if there is diff --git a/src/support/pipe.h b/src/support/pipe.h index 098b327625b9..b73a55268afe 100644 --- a/src/support/pipe.h +++ b/src/support/pipe.h @@ -56,6 +56,18 @@ class Pipe : public dmlc::Stream { using Stream::Read; using Stream::Write; + + /*! + * \return last error of pipe operation + */ + static int GetLastErrorCode() { +#ifdef _WIN32 + return GetLastError(); +#else + return errno; +#endif + } + /*! * \brief reads data from a file descriptor * \param ptr pointer to a memory buffer @@ -65,12 +77,15 @@ class Pipe : public dmlc::Stream { size_t Read(void* ptr, size_t size) final { if (size == 0) return 0; #ifdef _WIN32 - DWORD nread; - ICHECK(ReadFile(handle_, static_cast(ptr), size, &nread, nullptr)) - << "Read Error: " << GetLastError(); + auto fread = [&]() { + DWORD nread; + if (!ReadFile(handle_, static_cast(ptr), size, &nread, nullptr)) return -1; + return nread; + }; + DWORD nread = RetryCallOnEINTR(fread, GetLastErrorCode); + ICHECK_EQ(static_cast(nread), size) << "Read Error: " << GetLastError(); #else - ssize_t nread = RetryCallOnEINTR( - [&]() { return read(handle_, ptr, size); }); + ssize_t nread = RetryCallOnEINTR([&]() { return read(handle_, ptr, size); }, GetLastErrorCode); ICHECK_GE(nread, 0) << "Write Error: " << strerror(errno); #endif return static_cast(nread); @@ -84,13 +99,16 @@ class Pipe : public dmlc::Stream { void Write(const void* ptr, size_t size) final { if (size == 0) return; #ifdef _WIN32 - DWORD nwrite; - ICHECK(WriteFile(handle_, static_cast(ptr), size, &nwrite, nullptr) && - static_cast(nwrite) == size) - << "Write Error: " << GetLastError(); + auto fwrite = [&]() { + DWORD nwrite; + if (!WriteFile(handle_, static_cast(ptr), size, &nwrite, nullptr)) return -1; + return nwrite; + }; + DWORD nwrite = RetryCallOnEINTR(fwrite, GetLastErrorCode); + ICHECK_EQ(static_cast(nwrite), size) << "Write Error: " << GetLastError(); #else - ssize_t nwrite = RetryCallOnEINTR( - [&]() { return write(handle_, ptr, size); }); + ssize_t nwrite = + RetryCallOnEINTR([&]() { return write(handle_, ptr, size); }, GetLastErrorCode); ICHECK_EQ(static_cast(nwrite), size) << "Write Error: " << strerror(errno); #endif } diff --git a/src/support/socket.h b/src/support/socket.h index 9a645db83e75..06c7bba53337 100644 --- a/src/support/socket.h +++ b/src/support/socket.h @@ -55,9 +55,9 @@ #include #include +#include "error_handling.h" #include "ssize.h" #include "utils.h" -#include "error_handling.h" #if defined(_WIN32) static inline int poll(struct pollfd* pfd, int nfds, int timeout) { @@ -307,7 +307,16 @@ class Socket { Error("Socket::Close double close the socket or close without create"); } } - + /*! + * \return last error of socket operation + */ + static int GetLastErrorCode() { +#ifdef _WIN32 + return WSAGetLastError(); +#else + return errno; +#endif + } /*! \return whether last error was would block */ static bool LastErrorWouldBlock() { int errsv = GetLastErrorCode(); @@ -400,7 +409,8 @@ class TCPSocket : public Socket { * \return The accepted socket connection. */ TCPSocket Accept() { - SockType newfd = RetryCallOnEINTR([&]() { return accept(sockfd, nullptr, nullptr); }); + SockType newfd = + RetryCallOnEINTR([&]() { return accept(sockfd, nullptr, nullptr); }, GetLastErrorCode); if (newfd == INVALID_SOCKET) { Socket::Error("Accept"); } @@ -414,7 +424,8 @@ class TCPSocket : public Socket { TCPSocket Accept(SockAddr* addr) { socklen_t addrlen = sizeof(addr->addr); SockType newfd = RetryCallOnEINTR( - [&]() { return accept(sockfd, reinterpret_cast(&addr->addr), &addrlen); }); + [&]() { return accept(sockfd, reinterpret_cast(&addr->addr), &addrlen); }, + GetLastErrorCode); if (newfd == INVALID_SOCKET) { Socket::Error("Accept"); } @@ -455,7 +466,7 @@ class TCPSocket : public Socket { ssize_t Send(const void* buf_, size_t len, int flag = 0) { const char* buf = reinterpret_cast(buf_); return RetryCallOnEINTR( - [&]() { return send(sockfd, buf, static_cast(len), flag); }); + [&]() { return send(sockfd, buf, static_cast(len), flag); }, GetLastErrorCode); } /*! * \brief receive data using the socket @@ -468,7 +479,8 @@ class TCPSocket : public Socket { ssize_t Recv(void* buf_, size_t len, int flags = 0) { char* buf = reinterpret_cast(buf_); return RetryCallOnEINTR( - [&]() { return recv(sockfd, buf, static_cast(len), flags); }); + [&]() { return recv(sockfd, buf, static_cast(len), flags); }, + GetLastErrorCode); } /*! * \brief perform block write that will attempt to send all data out @@ -482,7 +494,8 @@ class TCPSocket : public Socket { size_t ndone = 0; while (ndone < len) { ssize_t ret = RetryCallOnEINTR( - [&]() { return send(sockfd, buf, static_cast(len - ndone), 0); }); + [&]() { return send(sockfd, buf, static_cast(len - ndone), 0); }, + GetLastErrorCode); if (ret == -1) { if (LastErrorWouldBlock()) return ndone; Socket::Error("SendAll"); @@ -504,7 +517,8 @@ class TCPSocket : public Socket { size_t ndone = 0; while (ndone < len) { ssize_t ret = RetryCallOnEINTR( - [&]() { return recv(sockfd, buf, static_cast(len - ndone), MSG_WAITALL); }); + [&]() { return recv(sockfd, buf, static_cast(len - ndone), MSG_WAITALL); }, + GetLastErrorCode); if (ret == -1) { if (LastErrorWouldBlock()) { LOG(FATAL) << "would block"; From d49bed4f7b4b9bd1d288d90345fd2cdd2dfe8d0e Mon Sep 17 00:00:00 2001 From: Lesheng Jin Date: Fri, 15 Dec 2023 15:51:01 +0000 Subject: [PATCH 6/9] rename to errno_handling.h --- src/support/{error_handling.h => errno_handling.h} | 0 src/support/pipe.h | 2 +- src/support/socket.h | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/support/{error_handling.h => errno_handling.h} (100%) diff --git a/src/support/error_handling.h b/src/support/errno_handling.h similarity index 100% rename from src/support/error_handling.h rename to src/support/errno_handling.h diff --git a/src/support/pipe.h b/src/support/pipe.h index b73a55268afe..cf7fa6d76011 100644 --- a/src/support/pipe.h +++ b/src/support/pipe.h @@ -36,7 +36,7 @@ #include #include #endif -#include "error_handling.h" +#include "errno_handling.h" namespace tvm { namespace support { diff --git a/src/support/socket.h b/src/support/socket.h index 06c7bba53337..ac13cd3f2d35 100644 --- a/src/support/socket.h +++ b/src/support/socket.h @@ -55,7 +55,7 @@ #include #include -#include "error_handling.h" +#include "errno_handling.h" #include "ssize.h" #include "utils.h" From 10ab861683e1b5ba22c5e37c3edf7bc6f309b144 Mon Sep 17 00:00:00 2001 From: Lesheng Jin Date: Sat, 16 Dec 2023 17:57:33 +0000 Subject: [PATCH 7/9] rename --- src/support/errno_handling.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/support/errno_handling.h b/src/support/errno_handling.h index 2a8e98f8c56b..f84492f99425 100644 --- a/src/support/errno_handling.h +++ b/src/support/errno_handling.h @@ -18,11 +18,11 @@ */ /*! - * \file err_handling.h - * \brief Common error handling functions for socket.h and pipe.h + * \file errno_handling.h + * \brief Common error number handling functions for socket.h and pipe.h */ -#ifndef TVM_SUPPORT_ERROR_HANDLING_H_ -#define TVM_SUPPORT_ERROR_HANDLING_H_ +#ifndef TVM_SUPPORT_ERROR_NUMBER_HANDLING_H_ +#define TVM_SUPPORT_ERROR_NUMBER_HANDLING_H_ #include namespace tvm { @@ -64,4 +64,4 @@ inline ssize_t RetryCallOnEINTR(FuncType func, GetErrorCodeFuncType fgeterrorcod } } // namespace support } // namespace tvm -#endif // TVM_SUPPORT_ERROR_HANDLING_H_ +#endif // TVM_SUPPORT_ERROR_NUMBER_HANDLING_H_ From d32e1bc41efda5a17abdb80e72d63f24933194cf Mon Sep 17 00:00:00 2001 From: Lesheng Jin Date: Sat, 16 Dec 2023 18:56:11 +0000 Subject: [PATCH 8/9] fix lint --- src/support/errno_handling.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/support/errno_handling.h b/src/support/errno_handling.h index f84492f99425..4ca53b4e12f0 100644 --- a/src/support/errno_handling.h +++ b/src/support/errno_handling.h @@ -21,8 +21,8 @@ * \file errno_handling.h * \brief Common error number handling functions for socket.h and pipe.h */ -#ifndef TVM_SUPPORT_ERROR_NUMBER_HANDLING_H_ -#define TVM_SUPPORT_ERROR_NUMBER_HANDLING_H_ +#ifndef TVM_SUPPORT_ERRNO_HANDLING_H_ +#define TVM_SUPPORT_ERRNO_HANDLING_H_ #include namespace tvm { @@ -64,4 +64,4 @@ inline ssize_t RetryCallOnEINTR(FuncType func, GetErrorCodeFuncType fgeterrorcod } } // namespace support } // namespace tvm -#endif // TVM_SUPPORT_ERROR_NUMBER_HANDLING_H_ +#endif // TVM_SUPPORT_ERRNO_HANDLING_H_ From 5611f331314fc2952a71bbd284e7a541563da505 Mon Sep 17 00:00:00 2001 From: Lesheng Jin Date: Tue, 19 Dec 2023 05:56:23 +0000 Subject: [PATCH 9/9] include ssize_t --- src/support/errno_handling.h | 2 ++ src/support/pipe.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/support/errno_handling.h b/src/support/errno_handling.h index 4ca53b4e12f0..0bdfdfdf022c 100644 --- a/src/support/errno_handling.h +++ b/src/support/errno_handling.h @@ -25,6 +25,8 @@ #define TVM_SUPPORT_ERRNO_HANDLING_H_ #include +#include "ssize.h" + namespace tvm { namespace support { /*! diff --git a/src/support/pipe.h b/src/support/pipe.h index cf7fa6d76011..557fe89e4670 100644 --- a/src/support/pipe.h +++ b/src/support/pipe.h @@ -82,7 +82,7 @@ class Pipe : public dmlc::Stream { if (!ReadFile(handle_, static_cast(ptr), size, &nread, nullptr)) return -1; return nread; }; - DWORD nread = RetryCallOnEINTR(fread, GetLastErrorCode); + DWORD nread = static_cast(RetryCallOnEINTR(fread, GetLastErrorCode)); ICHECK_EQ(static_cast(nread), size) << "Read Error: " << GetLastError(); #else ssize_t nread = RetryCallOnEINTR([&]() { return read(handle_, ptr, size); }, GetLastErrorCode); @@ -104,7 +104,7 @@ class Pipe : public dmlc::Stream { if (!WriteFile(handle_, static_cast(ptr), size, &nwrite, nullptr)) return -1; return nwrite; }; - DWORD nwrite = RetryCallOnEINTR(fwrite, GetLastErrorCode); + DWORD nwrite = static_cast(RetryCallOnEINTR(fwrite, GetLastErrorCode)); ICHECK_EQ(static_cast(nwrite), size) << "Write Error: " << GetLastError(); #else ssize_t nwrite =