2016-09-25 17:23:39 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-10-21 20:31:20 -07:00
|
|
|
/* Copyright (c) 2015-2017 FIRST. All Rights Reserved. */
|
2016-09-25 17:23:39 -07:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#include "tcpsockets/SocketError.h"
|
|
|
|
|
|
|
|
|
|
#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
|