Skip to content

Commit

Permalink
NetSocket set_broadcast_enabled returns Error enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Faless committed Dec 10, 2019
1 parent c868baf commit ab1bfb9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/io/net_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class NetSocket : public Reference {
virtual bool is_open() const = 0;
virtual int get_available_bytes() const = 0;

virtual void set_broadcasting_enabled(bool p_enabled) = 0;
virtual Error set_broadcasting_enabled(bool p_enabled) = 0; // Returns OK if the socket option has been set successfully.
virtual void set_blocking_enabled(bool p_enabled) = 0;
virtual void set_ipv6_only_enabled(bool p_enabled) = 0;
virtual void set_tcp_no_delay_enabled(bool p_enabled) = 0;
Expand Down
8 changes: 5 additions & 3 deletions drivers/unix/net_socket_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,17 @@ Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP
return OK;
}

void NetSocketPosix::set_broadcasting_enabled(bool p_enabled) {
ERR_FAIL_COND(!is_open());
Error NetSocketPosix::set_broadcasting_enabled(bool p_enabled) {
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
// IPv6 has no broadcast support.
ERR_FAIL_COND(_ip_type == IP::TYPE_IPV6);
ERR_FAIL_COND_V(_ip_type == IP::TYPE_IPV6, ERR_UNAVAILABLE);

int par = p_enabled ? 1 : 0;
if (setsockopt(_sock, SOL_SOCKET, SO_BROADCAST, SOCK_CBUF(&par), sizeof(int)) != 0) {
WARN_PRINT("Unable to change broadcast setting");
return FAILED;
}
return OK;
}

void NetSocketPosix::set_blocking_enabled(bool p_enabled) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/unix/net_socket_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class NetSocketPosix : public NetSocket {
virtual bool is_open() const;
virtual int get_available_bytes() const;

virtual void set_broadcasting_enabled(bool p_enabled);
virtual Error set_broadcasting_enabled(bool p_enabled);
virtual void set_blocking_enabled(bool p_enabled);
virtual void set_ipv6_only_enabled(bool p_enabled);
virtual void set_tcp_no_delay_enabled(bool p_enabled);
Expand Down

0 comments on commit ab1bfb9

Please sign in to comment.