Soc and artic_bass: gcc 13+ compatibility fix.

This commit is contained in:
kongfl888 2024-06-01 16:32:38 +08:00
parent de1f082e75
commit ae7c83794b
3 changed files with 10 additions and 13 deletions

View file

@ -2236,18 +2236,15 @@ std::optional<SOC_U::InterfaceInfo> SOC_U::GetDefaultInterfaceInfo() {
}
InterfaceInfo ret;
#ifdef _WIN32
SOCKET sock_fd = -1;
#else
int sock_fd = -1;
#endif
SocketHolder::SOCKET sock_fd = -1;
bool interface_found = false;
struct sockaddr_in s_in = {.sin_family = AF_INET, .sin_port = htons(53), .sin_addr = {}};
s_in.sin_addr.s_addr = inet_addr("8.8.8.8");
socklen_t s_info_len = sizeof(struct sockaddr_in);
sockaddr_in s_info;
if (static_cast<int>(sock_fd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
if ((sock_fd = ::socket(AF_INET, SOCK_STREAM, 0)) == static_cast<SocketHolder::SOCKET>(-1)) {
return std::nullopt;
}
@ -2265,7 +2262,7 @@ std::optional<SOC_U::InterfaceInfo> SOC_U::GetDefaultInterfaceInfo() {
#ifdef _WIN32
sock_fd = WSASocket(AF_INET, SOCK_DGRAM, 0, 0, 0, 0);
if (static_cast<int>(sock_fd) == SOCKET_ERROR) {
if (sock_fd == static_cast<SocketHolder::SOCKET>(SOCKET_ERROR)) {
return std::nullopt;
}

View file

@ -25,11 +25,11 @@ namespace Service::SOC {
struct SocketHolder {
#ifdef _WIN32
using SOCKET = unsigned long long;
SOCKET socket_fd; ///< The socket descriptor
#else
int socket_fd; ///< The socket descriptor
using SOCKET = int;
#endif // _WIN32
SOCKET socket_fd; ///< The socket descriptor
bool blocking = true; ///< Whether the socket is blocking or not.
bool isGlobal = false;
bool shutdown_rd = false;

View file

@ -163,7 +163,7 @@ bool Client::Connect() {
}
main_socket = ::socket(AF_INET, SOCK_STREAM, 0);
if (main_socket == -1) {
if (main_socket == static_cast<SocketHolder>(-1)) {
LOG_ERROR(Network, "Failed to create socket");
SignalCommunicationError();
return false;
@ -249,7 +249,7 @@ bool Client::Connect() {
std::stringstream ss_port(worker_ports.value());
while (std::getline(ss_port, str_port, ',')) {
int port = str_to_int(str_port);
if (port < 0 || port > USHRT_MAX) {
if (port < 0 || port > static_cast<int>(USHRT_MAX)) {
shutdown(main_socket, SHUT_RDWR);
closesocket(main_socket);
LOG_ERROR(Network, "Couldn't parse server worker ports");
@ -518,7 +518,7 @@ std::optional<ArticBaseCommon::DataPacket> Client::SendRequestPacket(
const std::chrono::nanoseconds& read_timeout) {
std::scoped_lock<std::mutex> l(send_mutex);
if (main_socket == -1) {
if (main_socket == static_cast<SocketHolder>(-1)) {
return std::nullopt;
}
@ -586,7 +586,7 @@ Client::Handler::Handler(Client& _client, u32 _addr, u16 _port, int _id)
void Client::Handler::RunLoop() {
handler_socket = ::socket(AF_INET, SOCK_STREAM, 0);
if (handler_socket == -1) {
if (handler_socket == static_cast<SocketHolder>(-1)) {
LOG_ERROR(Network, "Failed to create socket");
return;
}