2016-09-25 17:23:39 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
|
|
|
|
/* 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-08-23 01:27:19 -05:00
|
|
|
#include <WinSock2.h>
|
2016-09-25 17:23:39 -07:00
|
|
|
#include <windows.h>
|
|
|
|
|
#else
|
2017-08-23 01:27:19 -05:00
|
|
|
#include <errno.h>
|
2016-09-25 17:23:39 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
#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;
|
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
|
0, code, 0, (LPSTR)&errstr, 0, 0);
|
|
|
|
|
std::string rv(errstr);
|
|
|
|
|
LocalFree(errstr);
|
|
|
|
|
return rv;
|
|
|
|
|
#else
|
|
|
|
|
return strerror(code);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace wpi
|