hstrerror() 的替换函数
replacement function for hstrerror()
我正在将Linux套接字库转换为Windows,但winsock没有hstrerror()
函数。 hstrerror()
会拿h_errno
并吐出一个错误字符串。我认为类似于斯特里夫。我环顾四周,但实际上没有人说用什么代替它。除了"它已被弃用,改用getaddrinfo()
或getnameinfo()
"之外,我没有找到任何关于hstrerror被替换的提及。具体来说,我有一个使用它的异常类。代码如下:
//
// class socket_h_error
// subclass to record status of extern int h_errno variable
//
class socket_h_error : public socket_error {
public:
int host_errno;
//TODO: replace hstrerror()
explicit socket_h_error(const string& what) :
socket_error(what + ": " + hstrerror(h_errno)),
host_errno(h_errno) {}
};
我确实必须更换strerror()
,但我没有看到提到这是hstrerror()
的可能替代品。它在 winsock2 库中也不存在,所以我没有来自 MS 的建议。
使用 WSAGetLastError(( 和 FormatMessage((。
WSAGetLastError(( 在 MSDN 中所有与 winsock 相关的函数中都明确提及。
相关文章:
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 用符号版本替换对函数的所有调用
- 我可以在这里替换什么,因为我不能在 C# 中使用隐式变量的 lambda 函数?
- 用矩阵将函数中的整数值替换定义的常量
- 函数模板实例化、替换和重载解析的顺序是什么?
- 为表示一个或多个操作的C++函数的int参数寻找类型安全的替换
- 仅当一个参数中未使用 std::function 时,模板函数替换才有效
- 为什么数组中对象的析构函数在被另一个对象替换时不被调用?
- 如何使替换 c 函数的变量名成为错误?
- hstrerror() 的替换函数
- 重新声明时替换函数默认参数
- C++字符串替换函数无限循环
- 如何在c++中替换函数调用的所有实例
- 用C++模板替换函数调用的C宏
- 使用字符串替换函数将字符串的一部分替换为初始化的变量
- 字符串替换函数c++
- 使用默认类型替换c++函数引用模板错误
- 在Std::to_string替换函数中无法识别Std::stringstream对象
- c++中的替换函数
- 替换函数'operator new'不能声明'inline' [-werror,-winline-new-delete]