diff options
Diffstat (limited to 'drivers/unix/net_socket_posix.cpp')
-rw-r--r-- | drivers/unix/net_socket_posix.cpp | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/drivers/unix/net_socket_posix.cpp b/drivers/unix/net_socket_posix.cpp index 957a00703b..15ad187ab4 100644 --- a/drivers/unix/net_socket_posix.cpp +++ b/drivers/unix/net_socket_posix.cpp @@ -196,12 +196,15 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const { print_verbose("Socket error: " + itos(err)); return ERR_NET_OTHER; #else - if (errno == EISCONN) + if (errno == EISCONN) { return ERR_NET_IS_CONNECTED; - if (errno == EINPROGRESS || errno == EALREADY) + } + if (errno == EINPROGRESS || errno == EALREADY) { return ERR_NET_IN_PROGRESS; - if (errno == EAGAIN || errno == EWOULDBLOCK) + } + if (errno == EAGAIN || errno == EWOULDBLOCK) { return ERR_NET_WOULD_BLOCK; + } print_verbose("Socket error: " + itos(errno)); return ERR_NET_OTHER; #endif @@ -238,16 +241,19 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, St IP::get_singleton()->get_local_interfaces(&if_info); for (Map<String, IP::Interface_Info>::Element *E = if_info.front(); E; E = E->next()) { IP::Interface_Info &c = E->get(); - if (c.name != p_if_name) + if (c.name != p_if_name) { continue; + } if_v6id = (uint32_t)c.index.to_int64(); - if (type == IP::TYPE_IPV6) + if (type == IP::TYPE_IPV6) { break; // IPv6 uses index. + } for (List<IP_Address>::Element *F = c.ip_addresses.front(); F; F = F->next()) { - if (!F->get().is_ipv4()) + if (!F->get().is_ipv4()) { continue; // Wrong IP type + } if_ip = F->get(); break; } @@ -361,8 +367,9 @@ Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) { } void NetSocketPosix::close() { - if (_sock != SOCK_EMPTY) + if (_sock != SOCK_EMPTY) { SOCK_CLOSE(_sock); + } _sock = SOCK_EMPTY; _ip_type = IP::TYPE_NONE; @@ -508,8 +515,9 @@ Error NetSocketPosix::poll(PollType p_type, int p_timeout) const { return FAILED; } - if (ret == 0) + if (ret == 0) { return ERR_BUSY; + } return OK; #endif @@ -522,8 +530,9 @@ Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) { if (r_read < 0) { NetError err = _get_socket_error(); - if (err == ERR_NET_WOULD_BLOCK) + if (err == ERR_NET_WOULD_BLOCK) { return ERR_BUSY; + } return FAILED; } @@ -542,8 +551,9 @@ Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Add if (r_read < 0) { NetError err = _get_socket_error(); - if (err == ERR_NET_WOULD_BLOCK) + if (err == ERR_NET_WOULD_BLOCK) { return ERR_BUSY; + } return FAILED; } @@ -569,15 +579,17 @@ Error NetSocketPosix::send(const uint8_t *p_buffer, int p_len, int &r_sent) { int flags = 0; #ifdef MSG_NOSIGNAL - if (_is_stream) + if (_is_stream) { flags = MSG_NOSIGNAL; + } #endif r_sent = ::send(_sock, SOCK_CBUF(p_buffer), p_len, flags); if (r_sent < 0) { NetError err = _get_socket_error(); - if (err == ERR_NET_WOULD_BLOCK) + if (err == ERR_NET_WOULD_BLOCK) { return ERR_BUSY; + } return FAILED; } @@ -594,8 +606,9 @@ Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP if (r_sent < 0) { NetError err = _get_socket_error(); - if (err == ERR_NET_WOULD_BLOCK) + if (err == ERR_NET_WOULD_BLOCK) { return ERR_BUSY; + } return FAILED; } @@ -606,8 +619,9 @@ Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP Error NetSocketPosix::set_broadcasting_enabled(bool p_enabled) { ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED); // IPv6 has no broadcast support. - if (_ip_type == IP::TYPE_IPV6) + if (_ip_type == IP::TYPE_IPV6) { return ERR_UNAVAILABLE; + } int par = p_enabled ? 1 : 0; if (setsockopt(_sock, SOL_SOCKET, SO_BROADCAST, SOCK_CBUF(&par), sizeof(int)) != 0) { @@ -626,14 +640,16 @@ void NetSocketPosix::set_blocking_enabled(bool p_enabled) { ret = SOCK_IOCTL(_sock, FIONBIO, &par); #else int opts = fcntl(_sock, F_GETFL); - if (p_enabled) + if (p_enabled) { ret = fcntl(_sock, F_SETFL, opts & ~O_NONBLOCK); - else + } else { ret = fcntl(_sock, F_SETFL, opts | O_NONBLOCK); + } #endif - if (ret != 0) + if (ret != 0) { WARN_PRINT("Unable to change non-block mode"); + } } void NetSocketPosix::set_ipv6_only_enabled(bool p_enabled) { |