Skip to content

Commit

Permalink
[Web] Implement dummy NetSocketWeb
Browse files Browse the repository at this point in the history
This makes the class available to avoid spam from classes using it, even
if without any actual implementation (since raw sockets are not
available on the web).
  • Loading branch information
Faless committed Dec 3, 2024
1 parent c831f63 commit 14e4e34
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions platform/web/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ web_files = [
"javascript_bridge_singleton.cpp",
"web_main.cpp",
"ip_web.cpp",
"net_socket_web.cpp",
"os_web.cpp",
]

Expand Down
39 changes: 39 additions & 0 deletions platform/web/net_socket_web.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**************************************************************************/
/* net_socket_web.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#include "net_socket_web.h"

NetSocket *NetSocketWeb::_create_func() {
return memnew(NetSocketWeb);
}

void NetSocketWeb::make_default() {
_create = _create_func;
}
72 changes: 72 additions & 0 deletions platform/web/net_socket_web.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**************************************************************************/
/* net_socket_web.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef NET_SOCKET_WEB_H
#define NET_SOCKET_WEB_H

#include "core/io/net_socket.h"

#include <sys/socket.h>

class NetSocketWeb : public NetSocket {
protected:
static NetSocket *_create_func();

public:
static void make_default();

virtual Error open(Type p_sock_type, IP::Type &ip_type) override { return ERR_UNAVAILABLE; }
virtual void close() override {}
virtual Error bind(IPAddress p_addr, uint16_t p_port) override { return ERR_UNAVAILABLE; }
virtual Error listen(int p_max_pending) override { return ERR_UNAVAILABLE; }
virtual Error connect_to_host(IPAddress p_host, uint16_t p_port) override { return ERR_UNAVAILABLE; }
virtual Error poll(PollType p_type, int timeout) const override { return ERR_UNAVAILABLE; }
virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read) override { return ERR_UNAVAILABLE; }
virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IPAddress &r_ip, uint16_t &r_port, bool p_peek = false) override { return ERR_UNAVAILABLE; }
virtual Error send(const uint8_t *p_buffer, int p_len, int &r_sent) override { return ERR_UNAVAILABLE; }
virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) override { return ERR_UNAVAILABLE; }
virtual Ref<NetSocket> accept(IPAddress &r_ip, uint16_t &r_port) override { return Ref<NetSocket>(); }

virtual bool is_open() const override { return false; }
virtual int get_available_bytes() const override { return -1; }
virtual Error get_socket_address(IPAddress *r_ip, uint16_t *r_port) const override { return ERR_UNAVAILABLE; }

virtual Error set_broadcasting_enabled(bool p_enabled) override { return ERR_UNAVAILABLE; }
virtual void set_blocking_enabled(bool p_enabled) override {}
virtual void set_ipv6_only_enabled(bool p_enabled) override {}
virtual void set_tcp_no_delay_enabled(bool p_enabled) override {}
virtual void set_reuse_address_enabled(bool p_enabled) override {}
virtual Error join_multicast_group(const IPAddress &p_multi_address, const String &p_if_name) override { return ERR_UNAVAILABLE; }
virtual Error leave_multicast_group(const IPAddress &p_multi_address, const String &p_if_name) override { return ERR_UNAVAILABLE; }

NetSocketWeb() {}
};

#endif // NET_SOCKET_WEB_H
2 changes: 2 additions & 0 deletions platform/web/os_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "display_server_web.h"
#include "godot_js.h"
#include "ip_web.h"
#include "net_socket_web.h"

#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
Expand All @@ -55,6 +56,7 @@ void OS_Web::alert(const String &p_alert, const String &p_title) {
void OS_Web::initialize() {
OS_Unix::initialize_core();
IPWeb::make_default();
NetSocketWeb::make_default();
DisplayServerWeb::register_web_driver();
}

Expand Down

0 comments on commit 14e4e34

Please sign in to comment.