From ac7444023eeb2ca998947ca65b0a904f550f2404 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 15 Dec 2017 16:39:30 +0100 Subject: [PATCH] Move windows networking class to drivers/windows/ Also rename stream_peer_winsock.* to stream_peer_tcp_winsock.* and StreamPeerWinsock to StreamPeerTCPWinsock. --- .../windows/packet_peer_udp_winsock.cpp | 4 ++ .../windows/packet_peer_udp_winsock.h | 4 ++ .../windows/stream_peer_tcp_winsock.cpp | 52 +++++++++---------- .../windows/stream_peer_tcp_winsock.h | 12 ++--- .../windows/tcp_server_winsock.cpp | 8 ++- .../windows/tcp_server_winsock.h | 4 ++ platform/uwp/SCsub | 3 -- platform/uwp/os_uwp.cpp | 8 +-- platform/windows/SCsub | 3 -- platform/windows/os_windows.cpp | 10 ++-- 10 files changed, 59 insertions(+), 49 deletions(-) rename {platform => drivers}/windows/packet_peer_udp_winsock.cpp (99%) rename {platform => drivers}/windows/packet_peer_udp_winsock.h (99%) rename platform/windows/stream_peer_winsock.cpp => drivers/windows/stream_peer_tcp_winsock.cpp (81%) rename platform/windows/stream_peer_winsock.h => drivers/windows/stream_peer_tcp_winsock.h (94%) rename {platform => drivers}/windows/tcp_server_winsock.cpp (97%) rename {platform => drivers}/windows/tcp_server_winsock.h (98%) diff --git a/platform/windows/packet_peer_udp_winsock.cpp b/drivers/windows/packet_peer_udp_winsock.cpp similarity index 99% rename from platform/windows/packet_peer_udp_winsock.cpp rename to drivers/windows/packet_peer_udp_winsock.cpp index 68ea9e8408b..119ee68bd23 100644 --- a/platform/windows/packet_peer_udp_winsock.cpp +++ b/drivers/windows/packet_peer_udp_winsock.cpp @@ -27,6 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#ifdef WINDOWS_ENABLED + #include "packet_peer_udp_winsock.h" #include @@ -291,3 +293,5 @@ PacketPeerUDPWinsock::~PacketPeerUDPWinsock() { close(); } + +#endif diff --git a/platform/windows/packet_peer_udp_winsock.h b/drivers/windows/packet_peer_udp_winsock.h similarity index 99% rename from platform/windows/packet_peer_udp_winsock.h rename to drivers/windows/packet_peer_udp_winsock.h index eccf9442d42..8ce2cff7417 100644 --- a/platform/windows/packet_peer_udp_winsock.h +++ b/drivers/windows/packet_peer_udp_winsock.h @@ -27,6 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#ifdef WINDOWS_ENABLED + #ifndef PACKET_PEER_UDP_WINSOCK_H #define PACKET_PEER_UDP_WINSOCK_H @@ -82,3 +84,5 @@ public: ~PacketPeerUDPWinsock(); }; #endif // PACKET_PEER_UDP_WINSOCK_H + +#endif diff --git a/platform/windows/stream_peer_winsock.cpp b/drivers/windows/stream_peer_tcp_winsock.cpp similarity index 81% rename from platform/windows/stream_peer_winsock.cpp rename to drivers/windows/stream_peer_tcp_winsock.cpp index 8b832153252..f4cd38079d7 100644 --- a/platform/windows/stream_peer_winsock.cpp +++ b/drivers/windows/stream_peer_tcp_winsock.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* stream_peer_winsock.cpp */ +/* stream_peer_tcp_winsock.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -29,7 +29,7 @@ /*************************************************************************/ #ifdef WINDOWS_ENABLED -#include "stream_peer_winsock.h" +#include "stream_peer_tcp_winsock.h" #include #include @@ -38,14 +38,14 @@ int winsock_refcount = 0; -StreamPeerTCP *StreamPeerWinsock::_create() { +StreamPeerTCP *StreamPeerTCPWinsock::_create() { - return memnew(StreamPeerWinsock); + return memnew(StreamPeerTCPWinsock); }; -void StreamPeerWinsock::make_default() { +void StreamPeerTCPWinsock::make_default() { - StreamPeerTCP::_create = StreamPeerWinsock::_create; + StreamPeerTCP::_create = StreamPeerTCPWinsock::_create; if (winsock_refcount == 0) { WSADATA data; @@ -54,7 +54,7 @@ void StreamPeerWinsock::make_default() { ++winsock_refcount; }; -void StreamPeerWinsock::cleanup() { +void StreamPeerTCPWinsock::cleanup() { --winsock_refcount; if (winsock_refcount == 0) { @@ -63,7 +63,7 @@ void StreamPeerWinsock::cleanup() { }; }; -Error StreamPeerWinsock::_block(int p_sockfd, bool p_read, bool p_write) const { +Error StreamPeerTCPWinsock::_block(int p_sockfd, bool p_read, bool p_write) const { fd_set read, write; FD_ZERO(&read); @@ -78,7 +78,7 @@ Error StreamPeerWinsock::_block(int p_sockfd, bool p_read, bool p_write) const { return ret < 0 ? FAILED : OK; }; -Error StreamPeerWinsock::_poll_connection() const { +Error StreamPeerTCPWinsock::_poll_connection() const { ERR_FAIL_COND_V(status != STATUS_CONNECTING || sockfd == INVALID_SOCKET, FAILED); @@ -108,7 +108,7 @@ Error StreamPeerWinsock::_poll_connection() const { return OK; }; -Error StreamPeerWinsock::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) { +Error StreamPeerTCPWinsock::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) { if (status == STATUS_NONE || status == STATUS_ERROR) { @@ -166,7 +166,7 @@ Error StreamPeerWinsock::write(const uint8_t *p_data, int p_bytes, int &r_sent, return OK; }; -Error StreamPeerWinsock::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { +Error StreamPeerTCPWinsock::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { if (!is_connected_to_host()) { @@ -224,29 +224,29 @@ Error StreamPeerWinsock::read(uint8_t *p_buffer, int p_bytes, int &r_received, b return OK; }; -Error StreamPeerWinsock::put_data(const uint8_t *p_data, int p_bytes) { +Error StreamPeerTCPWinsock::put_data(const uint8_t *p_data, int p_bytes) { int total; return write(p_data, p_bytes, total, true); }; -Error StreamPeerWinsock::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { +Error StreamPeerTCPWinsock::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { return write(p_data, p_bytes, r_sent, false); }; -Error StreamPeerWinsock::get_data(uint8_t *p_buffer, int p_bytes) { +Error StreamPeerTCPWinsock::get_data(uint8_t *p_buffer, int p_bytes) { int total; return read(p_buffer, p_bytes, total, true); }; -Error StreamPeerWinsock::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { +Error StreamPeerTCPWinsock::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { return read(p_buffer, p_bytes, r_received, false); }; -StreamPeerTCP::Status StreamPeerWinsock::get_status() const { +StreamPeerTCP::Status StreamPeerTCPWinsock::get_status() const { if (status == STATUS_CONNECTING) { _poll_connection(); @@ -255,7 +255,7 @@ StreamPeerTCP::Status StreamPeerWinsock::get_status() const { return status; }; -bool StreamPeerWinsock::is_connected_to_host() const { +bool StreamPeerTCPWinsock::is_connected_to_host() const { if (status == STATUS_NONE || status == STATUS_ERROR) { @@ -268,7 +268,7 @@ bool StreamPeerWinsock::is_connected_to_host() const { return (sockfd != INVALID_SOCKET); }; -void StreamPeerWinsock::disconnect_from_host() { +void StreamPeerTCPWinsock::disconnect_from_host() { if (sockfd != INVALID_SOCKET) closesocket(sockfd); @@ -281,7 +281,7 @@ void StreamPeerWinsock::disconnect_from_host() { peer_port = 0; }; -void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_sock_type) { +void StreamPeerTCPWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, IP::Type p_sock_type) { sockfd = p_sockfd; sock_type = p_sock_type; @@ -290,7 +290,7 @@ void StreamPeerWinsock::set_socket(int p_sockfd, IP_Address p_host, int p_port, peer_port = p_port; }; -Error StreamPeerWinsock::connect_to_host(const IP_Address &p_host, uint16_t p_port) { +Error StreamPeerTCPWinsock::connect_to_host(const IP_Address &p_host, uint16_t p_port) { ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); @@ -331,13 +331,13 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address &p_host, uint16_t p_po return OK; }; -void StreamPeerWinsock::set_nodelay(bool p_enabled) { +void StreamPeerTCPWinsock::set_nodelay(bool p_enabled) { ERR_FAIL_COND(!is_connected_to_host()); int flag = p_enabled ? 1 : 0; setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); } -int StreamPeerWinsock::get_available_bytes() const { +int StreamPeerTCPWinsock::get_available_bytes() const { unsigned long len; int ret = ioctlsocket(sockfd, FIONREAD, &len); @@ -345,17 +345,17 @@ int StreamPeerWinsock::get_available_bytes() const { return len; } -IP_Address StreamPeerWinsock::get_connected_host() const { +IP_Address StreamPeerTCPWinsock::get_connected_host() const { return peer_host; }; -uint16_t StreamPeerWinsock::get_connected_port() const { +uint16_t StreamPeerTCPWinsock::get_connected_port() const { return peer_port; }; -StreamPeerWinsock::StreamPeerWinsock() { +StreamPeerTCPWinsock::StreamPeerTCPWinsock() { sock_type = IP::TYPE_NONE; sockfd = INVALID_SOCKET; @@ -363,7 +363,7 @@ StreamPeerWinsock::StreamPeerWinsock() { peer_port = 0; }; -StreamPeerWinsock::~StreamPeerWinsock() { +StreamPeerTCPWinsock::~StreamPeerTCPWinsock() { disconnect_from_host(); }; diff --git a/platform/windows/stream_peer_winsock.h b/drivers/windows/stream_peer_tcp_winsock.h similarity index 94% rename from platform/windows/stream_peer_winsock.h rename to drivers/windows/stream_peer_tcp_winsock.h index 26e2a3e4c91..fef457c43f2 100644 --- a/platform/windows/stream_peer_winsock.h +++ b/drivers/windows/stream_peer_tcp_winsock.h @@ -29,15 +29,15 @@ /*************************************************************************/ #ifdef WINDOWS_ENABLED -#ifndef STREAM_PEER_WINSOCK_H -#define STREAM_PEER_WINSOCK_H +#ifndef STREAM_PEER_TCP_WINSOCK_H +#define STREAM_PEER_TCP_WINSOCK_H #include "error_list.h" #include "core/io/ip_address.h" #include "core/io/stream_peer_tcp.h" -class StreamPeerWinsock : public StreamPeerTCP { +class StreamPeerTCPWinsock : public StreamPeerTCP { protected: mutable Status status; @@ -82,10 +82,10 @@ public: virtual void set_nodelay(bool p_enabled); - StreamPeerWinsock(); - ~StreamPeerWinsock(); + StreamPeerTCPWinsock(); + ~StreamPeerTCPWinsock(); }; -#endif // TCP_SOCKET_POSIX_H +#endif // STREAM_PEER_TCP_WINSOCK_H #endif diff --git a/platform/windows/tcp_server_winsock.cpp b/drivers/windows/tcp_server_winsock.cpp similarity index 97% rename from platform/windows/tcp_server_winsock.cpp rename to drivers/windows/tcp_server_winsock.cpp index de300befa7e..49de279793d 100644 --- a/platform/windows/tcp_server_winsock.cpp +++ b/drivers/windows/tcp_server_winsock.cpp @@ -27,9 +27,11 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#ifdef WINDOWS_ENABLED + #include "tcp_server_winsock.h" -#include "stream_peer_winsock.h" +#include "stream_peer_tcp_winsock.h" #include #include @@ -151,7 +153,7 @@ Ref TCPServerWinsock::take_connection() { int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &sin_size); ERR_FAIL_COND_V(fd == INVALID_SOCKET, NULL); - Ref conn = memnew(StreamPeerWinsock); + Ref conn = memnew(StreamPeerTCPWinsock); IP_Address ip; int port; _set_ip_addr_port(ip, port, &their_addr); @@ -181,3 +183,5 @@ TCPServerWinsock::~TCPServerWinsock() { stop(); }; + +#endif diff --git a/platform/windows/tcp_server_winsock.h b/drivers/windows/tcp_server_winsock.h similarity index 98% rename from platform/windows/tcp_server_winsock.h rename to drivers/windows/tcp_server_winsock.h index a3e01098eda..fd164801674 100644 --- a/platform/windows/tcp_server_winsock.h +++ b/drivers/windows/tcp_server_winsock.h @@ -27,6 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#ifdef WINDOWS_ENABLED + #ifndef TCP_SERVER_WINSOCK_H #define TCP_SERVER_WINSOCK_H @@ -54,3 +56,5 @@ public: }; #endif + +#endif diff --git a/platform/uwp/SCsub b/platform/uwp/SCsub index f0d69fef336..fb0c4a92ae2 100644 --- a/platform/uwp/SCsub +++ b/platform/uwp/SCsub @@ -4,9 +4,6 @@ Import('env') files = [ 'thread_uwp.cpp', - '#platform/windows/tcp_server_winsock.cpp', - '#platform/windows/packet_peer_udp_winsock.cpp', - '#platform/windows/stream_peer_winsock.cpp', '#platform/windows/key_mapping_win.cpp', '#platform/windows/windows_terminal_logger.cpp', 'joypad_uwp.cpp', diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 659f162724c..3018ac0befd 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -34,13 +34,13 @@ #include "drivers/windows/dir_access_windows.h" #include "drivers/windows/file_access_windows.h" #include "drivers/windows/mutex_windows.h" +#include "drivers/windows/packet_peer_udp_winsock.h" #include "drivers/windows/rw_lock_windows.h" #include "drivers/windows/semaphore_windows.h" +#include "drivers/windows/stream_peer_tcp_winsock.h" +#include "drivers/windows/tcp_server_winsock.h" #include "io/marshalls.h" #include "main/main.h" -#include "platform/windows/packet_peer_udp_winsock.h" -#include "platform/windows/stream_peer_winsock.h" -#include "platform/windows/tcp_server_winsock.h" #include "platform/windows/windows_terminal_logger.h" #include "project_settings.h" #include "servers/audio_server.h" @@ -163,7 +163,7 @@ void OSUWP::initialize_core() { DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); TCPServerWinsock::make_default(); - StreamPeerWinsock::make_default(); + StreamPeerTCPWinsock::make_default(); PacketPeerUDPWinsock::make_default(); // We need to know how often the clock is updated diff --git a/platform/windows/SCsub b/platform/windows/SCsub index 135ccd902a6..5030f4b3e0c 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -19,9 +19,6 @@ common_win = [ "os_windows.cpp", "ctxgl_procaddr.cpp", "key_mapping_win.cpp", - "tcp_server_winsock.cpp", - "packet_peer_udp_winsock.cpp", - "stream_peer_winsock.cpp", "joypad.cpp", "power_windows.cpp", "windows_terminal_logger.cpp" diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 5916c8f06c6..6cab683e837 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -34,19 +34,19 @@ #include "drivers/windows/dir_access_windows.h" #include "drivers/windows/file_access_windows.h" #include "drivers/windows/mutex_windows.h" +#include "drivers/windows/packet_peer_udp_winsock.h" #include "drivers/windows/rw_lock_windows.h" #include "drivers/windows/semaphore_windows.h" +#include "drivers/windows/stream_peer_tcp_winsock.h" +#include "drivers/windows/tcp_server_winsock.h" #include "drivers/windows/thread_windows.h" #include "io/marshalls.h" #include "joypad.h" #include "lang_table.h" #include "main/main.h" -#include "packet_peer_udp_winsock.h" #include "servers/audio_server.h" #include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_wrap_mt.h" -#include "stream_peer_winsock.h" -#include "tcp_server_winsock.h" #include "version_generated.gen.h" #include "windows_terminal_logger.h" @@ -196,7 +196,7 @@ void OS_Windows::initialize_core() { DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); TCPServerWinsock::make_default(); - StreamPeerWinsock::make_default(); + StreamPeerTCPWinsock::make_default(); PacketPeerUDPWinsock::make_default(); // We need to know how often the clock is updated @@ -1253,7 +1253,7 @@ void OS_Windows::finalize_core() { memdelete(process_map); TCPServerWinsock::cleanup(); - StreamPeerWinsock::cleanup(); + StreamPeerTCPWinsock::cleanup(); } void OS_Windows::alert(const String &p_alert, const String &p_title) {