Move windows networking class to drivers/windows/

Also rename stream_peer_winsock.* to stream_peer_tcp_winsock.* and
StreamPeerWinsock to StreamPeerTCPWinsock.
This commit is contained in:
Fabio Alessandrelli 2017-12-15 16:39:30 +01:00
parent 92067b4714
commit ac7444023e
10 changed files with 59 additions and 49 deletions

View File

@ -27,6 +27,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef WINDOWS_ENABLED
#include "packet_peer_udp_winsock.h" #include "packet_peer_udp_winsock.h"
#include <winsock2.h> #include <winsock2.h>
@ -291,3 +293,5 @@ PacketPeerUDPWinsock::~PacketPeerUDPWinsock() {
close(); close();
} }
#endif

View File

@ -27,6 +27,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef WINDOWS_ENABLED
#ifndef PACKET_PEER_UDP_WINSOCK_H #ifndef PACKET_PEER_UDP_WINSOCK_H
#define PACKET_PEER_UDP_WINSOCK_H #define PACKET_PEER_UDP_WINSOCK_H
@ -82,3 +84,5 @@ public:
~PacketPeerUDPWinsock(); ~PacketPeerUDPWinsock();
}; };
#endif // PACKET_PEER_UDP_WINSOCK_H #endif // PACKET_PEER_UDP_WINSOCK_H
#endif

View File

@ -1,5 +1,5 @@
/*************************************************************************/ /*************************************************************************/
/* stream_peer_winsock.cpp */ /* stream_peer_tcp_winsock.cpp */
/*************************************************************************/ /*************************************************************************/
/* This file is part of: */ /* This file is part of: */
/* GODOT ENGINE */ /* GODOT ENGINE */
@ -29,7 +29,7 @@
/*************************************************************************/ /*************************************************************************/
#ifdef WINDOWS_ENABLED #ifdef WINDOWS_ENABLED
#include "stream_peer_winsock.h" #include "stream_peer_tcp_winsock.h"
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
@ -38,14 +38,14 @@
int winsock_refcount = 0; 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) { if (winsock_refcount == 0) {
WSADATA data; WSADATA data;
@ -54,7 +54,7 @@ void StreamPeerWinsock::make_default() {
++winsock_refcount; ++winsock_refcount;
}; };
void StreamPeerWinsock::cleanup() { void StreamPeerTCPWinsock::cleanup() {
--winsock_refcount; --winsock_refcount;
if (winsock_refcount == 0) { 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_set read, write;
FD_ZERO(&read); 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; 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); ERR_FAIL_COND_V(status != STATUS_CONNECTING || sockfd == INVALID_SOCKET, FAILED);
@ -108,7 +108,7 @@ Error StreamPeerWinsock::_poll_connection() const {
return OK; 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) { 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; 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()) { 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; 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; int total;
return write(p_data, p_bytes, total, true); 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); 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; int total;
return read(p_buffer, p_bytes, total, true); 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); 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) { if (status == STATUS_CONNECTING) {
_poll_connection(); _poll_connection();
@ -255,7 +255,7 @@ StreamPeerTCP::Status StreamPeerWinsock::get_status() const {
return status; return status;
}; };
bool StreamPeerWinsock::is_connected_to_host() const { bool StreamPeerTCPWinsock::is_connected_to_host() const {
if (status == STATUS_NONE || status == STATUS_ERROR) { if (status == STATUS_NONE || status == STATUS_ERROR) {
@ -268,7 +268,7 @@ bool StreamPeerWinsock::is_connected_to_host() const {
return (sockfd != INVALID_SOCKET); return (sockfd != INVALID_SOCKET);
}; };
void StreamPeerWinsock::disconnect_from_host() { void StreamPeerTCPWinsock::disconnect_from_host() {
if (sockfd != INVALID_SOCKET) if (sockfd != INVALID_SOCKET)
closesocket(sockfd); closesocket(sockfd);
@ -281,7 +281,7 @@ void StreamPeerWinsock::disconnect_from_host() {
peer_port = 0; 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; sockfd = p_sockfd;
sock_type = p_sock_type; 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; 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); 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; return OK;
}; };
void StreamPeerWinsock::set_nodelay(bool p_enabled) { void StreamPeerTCPWinsock::set_nodelay(bool p_enabled) {
ERR_FAIL_COND(!is_connected_to_host()); ERR_FAIL_COND(!is_connected_to_host());
int flag = p_enabled ? 1 : 0; int flag = p_enabled ? 1 : 0;
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); 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; unsigned long len;
int ret = ioctlsocket(sockfd, FIONREAD, &len); int ret = ioctlsocket(sockfd, FIONREAD, &len);
@ -345,17 +345,17 @@ int StreamPeerWinsock::get_available_bytes() const {
return len; return len;
} }
IP_Address StreamPeerWinsock::get_connected_host() const { IP_Address StreamPeerTCPWinsock::get_connected_host() const {
return peer_host; return peer_host;
}; };
uint16_t StreamPeerWinsock::get_connected_port() const { uint16_t StreamPeerTCPWinsock::get_connected_port() const {
return peer_port; return peer_port;
}; };
StreamPeerWinsock::StreamPeerWinsock() { StreamPeerTCPWinsock::StreamPeerTCPWinsock() {
sock_type = IP::TYPE_NONE; sock_type = IP::TYPE_NONE;
sockfd = INVALID_SOCKET; sockfd = INVALID_SOCKET;
@ -363,7 +363,7 @@ StreamPeerWinsock::StreamPeerWinsock() {
peer_port = 0; peer_port = 0;
}; };
StreamPeerWinsock::~StreamPeerWinsock() { StreamPeerTCPWinsock::~StreamPeerTCPWinsock() {
disconnect_from_host(); disconnect_from_host();
}; };

View File

@ -29,15 +29,15 @@
/*************************************************************************/ /*************************************************************************/
#ifdef WINDOWS_ENABLED #ifdef WINDOWS_ENABLED
#ifndef STREAM_PEER_WINSOCK_H #ifndef STREAM_PEER_TCP_WINSOCK_H
#define STREAM_PEER_WINSOCK_H #define STREAM_PEER_TCP_WINSOCK_H
#include "error_list.h" #include "error_list.h"
#include "core/io/ip_address.h" #include "core/io/ip_address.h"
#include "core/io/stream_peer_tcp.h" #include "core/io/stream_peer_tcp.h"
class StreamPeerWinsock : public StreamPeerTCP { class StreamPeerTCPWinsock : public StreamPeerTCP {
protected: protected:
mutable Status status; mutable Status status;
@ -82,10 +82,10 @@ public:
virtual void set_nodelay(bool p_enabled); virtual void set_nodelay(bool p_enabled);
StreamPeerWinsock(); StreamPeerTCPWinsock();
~StreamPeerWinsock(); ~StreamPeerTCPWinsock();
}; };
#endif // TCP_SOCKET_POSIX_H #endif // STREAM_PEER_TCP_WINSOCK_H
#endif #endif

View File

@ -27,9 +27,11 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef WINDOWS_ENABLED
#include "tcp_server_winsock.h" #include "tcp_server_winsock.h"
#include "stream_peer_winsock.h" #include "stream_peer_tcp_winsock.h"
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
@ -151,7 +153,7 @@ Ref<StreamPeerTCP> TCPServerWinsock::take_connection() {
int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &sin_size); int fd = accept(listen_sockfd, (struct sockaddr *)&their_addr, &sin_size);
ERR_FAIL_COND_V(fd == INVALID_SOCKET, NULL); ERR_FAIL_COND_V(fd == INVALID_SOCKET, NULL);
Ref<StreamPeerWinsock> conn = memnew(StreamPeerWinsock); Ref<StreamPeerTCPWinsock> conn = memnew(StreamPeerTCPWinsock);
IP_Address ip; IP_Address ip;
int port; int port;
_set_ip_addr_port(ip, port, &their_addr); _set_ip_addr_port(ip, port, &their_addr);
@ -181,3 +183,5 @@ TCPServerWinsock::~TCPServerWinsock() {
stop(); stop();
}; };
#endif

View File

@ -27,6 +27,8 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/ /*************************************************************************/
#ifdef WINDOWS_ENABLED
#ifndef TCP_SERVER_WINSOCK_H #ifndef TCP_SERVER_WINSOCK_H
#define TCP_SERVER_WINSOCK_H #define TCP_SERVER_WINSOCK_H
@ -54,3 +56,5 @@ public:
}; };
#endif #endif
#endif

View File

@ -4,9 +4,6 @@ Import('env')
files = [ files = [
'thread_uwp.cpp', '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/key_mapping_win.cpp',
'#platform/windows/windows_terminal_logger.cpp', '#platform/windows/windows_terminal_logger.cpp',
'joypad_uwp.cpp', 'joypad_uwp.cpp',

View File

@ -34,13 +34,13 @@
#include "drivers/windows/dir_access_windows.h" #include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h" #include "drivers/windows/file_access_windows.h"
#include "drivers/windows/mutex_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/rw_lock_windows.h"
#include "drivers/windows/semaphore_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 "io/marshalls.h"
#include "main/main.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 "platform/windows/windows_terminal_logger.h"
#include "project_settings.h" #include "project_settings.h"
#include "servers/audio_server.h" #include "servers/audio_server.h"
@ -163,7 +163,7 @@ void OSUWP::initialize_core() {
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM); DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM);
TCPServerWinsock::make_default(); TCPServerWinsock::make_default();
StreamPeerWinsock::make_default(); StreamPeerTCPWinsock::make_default();
PacketPeerUDPWinsock::make_default(); PacketPeerUDPWinsock::make_default();
// We need to know how often the clock is updated // We need to know how often the clock is updated

View File

@ -19,9 +19,6 @@ common_win = [
"os_windows.cpp", "os_windows.cpp",
"ctxgl_procaddr.cpp", "ctxgl_procaddr.cpp",
"key_mapping_win.cpp", "key_mapping_win.cpp",
"tcp_server_winsock.cpp",
"packet_peer_udp_winsock.cpp",
"stream_peer_winsock.cpp",
"joypad.cpp", "joypad.cpp",
"power_windows.cpp", "power_windows.cpp",
"windows_terminal_logger.cpp" "windows_terminal_logger.cpp"

View File

@ -34,19 +34,19 @@
#include "drivers/windows/dir_access_windows.h" #include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h" #include "drivers/windows/file_access_windows.h"
#include "drivers/windows/mutex_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/rw_lock_windows.h"
#include "drivers/windows/semaphore_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 "drivers/windows/thread_windows.h"
#include "io/marshalls.h" #include "io/marshalls.h"
#include "joypad.h" #include "joypad.h"
#include "lang_table.h" #include "lang_table.h"
#include "main/main.h" #include "main/main.h"
#include "packet_peer_udp_winsock.h"
#include "servers/audio_server.h" #include "servers/audio_server.h"
#include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.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 "version_generated.gen.h"
#include "windows_terminal_logger.h" #include "windows_terminal_logger.h"
@ -196,7 +196,7 @@ void OS_Windows::initialize_core() {
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM); DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM);
TCPServerWinsock::make_default(); TCPServerWinsock::make_default();
StreamPeerWinsock::make_default(); StreamPeerTCPWinsock::make_default();
PacketPeerUDPWinsock::make_default(); PacketPeerUDPWinsock::make_default();
// We need to know how often the clock is updated // We need to know how often the clock is updated
@ -1253,7 +1253,7 @@ void OS_Windows::finalize_core() {
memdelete(process_map); memdelete(process_map);
TCPServerWinsock::cleanup(); TCPServerWinsock::cleanup();
StreamPeerWinsock::cleanup(); StreamPeerTCPWinsock::cleanup();
} }
void OS_Windows::alert(const String &p_alert, const String &p_title) { void OS_Windows::alert(const String &p_alert, const String &p_title) {