2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-09-25 17:23:39 -07:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include "wpi/SocketError.h"
|
2016-09-25 17:23:39 -07:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2017-10-21 20:31:20 -07:00
|
|
|
#include <winsock2.h>
|
2016-09-25 17:23:39 -07:00
|
|
|
#else
|
2017-10-21 20:31:20 -07:00
|
|
|
#include <cerrno>
|
|
|
|
|
#include <cstring>
|
2016-09-25 17:23:39 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace wpi {
|
|
|
|
|
|
2017-08-23 01:27:19 -05:00
|
|
|
int SocketErrno() {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
return WSAGetLastError();
|
|
|
|
|
#else
|
|
|
|
|
return errno;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-25 17:23:39 -07:00
|
|
|
std::string SocketStrerror(int code) {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
LPSTR errstr = nullptr;
|
2017-10-21 20:31:20 -07:00
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0,
|
|
|
|
|
code, 0, (LPSTR)&errstr, 0, 0);
|
2016-09-25 17:23:39 -07:00
|
|
|
std::string rv(errstr);
|
|
|
|
|
LocalFree(errstr);
|
|
|
|
|
return rv;
|
|
|
|
|
#else
|
2017-10-21 20:31:20 -07:00
|
|
|
return std::strerror(code);
|
2016-09-25 17:23:39 -07:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace wpi
|