summaryrefslogtreecommitdiff
path: root/platform/windows/stream_peer_winsock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/windows/stream_peer_winsock.cpp')
-rw-r--r--platform/windows/stream_peer_winsock.cpp48
1 files changed, 22 insertions, 26 deletions
diff --git a/platform/windows/stream_peer_winsock.cpp b/platform/windows/stream_peer_winsock.cpp
index 106eb6a5f5..abf182c72a 100644
--- a/platform/windows/stream_peer_winsock.cpp
+++ b/platform/windows/stream_peer_winsock.cpp
@@ -37,7 +37,7 @@
int winsock_refcount = 0;
-StreamPeerTCP* StreamPeerWinsock::_create() {
+StreamPeerTCP *StreamPeerWinsock::_create() {
return memnew(StreamPeerWinsock);
};
@@ -48,7 +48,7 @@ void StreamPeerWinsock::make_default() {
if (winsock_refcount == 0) {
WSADATA data;
- WSAStartup(MAKEWORD(2,2), &data);
+ WSAStartup(MAKEWORD(2, 2), &data);
};
++winsock_refcount;
};
@@ -62,7 +62,6 @@ void StreamPeerWinsock::cleanup() {
};
};
-
Error StreamPeerWinsock::_block(int p_sockfd, bool p_read, bool p_write) const {
fd_set read, write;
@@ -85,7 +84,7 @@ Error StreamPeerWinsock::_poll_connection() const {
struct sockaddr_storage their_addr;
size_t addr_size = _set_sockaddr(&their_addr, peer_host, peer_port, sock_type);
- if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) {
+ if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == SOCKET_ERROR) {
int err = WSAGetLastError();
if (err == WSAEISCONN) {
@@ -108,7 +107,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 StreamPeerWinsock::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) {
if (status == STATUS_NONE || status == STATUS_ERROR) {
@@ -135,7 +134,7 @@ Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, b
while (data_to_send) {
- int sent_amount = send(sockfd, (const char*)offset, data_to_send, 0);
+ int sent_amount = send(sockfd, (const char *)offset, data_to_send, 0);
if (sent_amount == -1) {
@@ -166,7 +165,7 @@ Error StreamPeerWinsock::write(const uint8_t* p_data,int p_bytes, int &r_sent, b
return OK;
};
-Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bool p_block) {
+Error StreamPeerWinsock::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) {
if (!is_connected_to_host()) {
@@ -191,7 +190,7 @@ Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bo
while (to_read) {
- int read = recv(sockfd, (char*)p_buffer + total_read, to_read, 0);
+ int read = recv(sockfd, (char *)p_buffer + total_read, to_read, 0);
if (read == -1) {
@@ -224,24 +223,24 @@ Error StreamPeerWinsock::read(uint8_t* p_buffer, int p_bytes,int &r_received, bo
return OK;
};
-Error StreamPeerWinsock::put_data(const uint8_t* p_data,int p_bytes) {
+Error StreamPeerWinsock::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 StreamPeerWinsock::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 StreamPeerWinsock::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 StreamPeerWinsock::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) {
return read(p_buffer, p_bytes, r_received, false);
};
@@ -255,7 +254,6 @@ StreamPeerTCP::Status StreamPeerWinsock::get_status() const {
return status;
};
-
bool StreamPeerWinsock::is_connected_to_host() const {
if (status == STATUS_NONE || status == STATUS_ERROR) {
@@ -266,14 +264,14 @@ bool StreamPeerWinsock::is_connected_to_host() const {
return true;
};
- return (sockfd!=INVALID_SOCKET);
+ return (sockfd != INVALID_SOCKET);
};
void StreamPeerWinsock::disconnect_from_host() {
if (sockfd != INVALID_SOCKET)
closesocket(sockfd);
- sockfd=INVALID_SOCKET;
+ sockfd = INVALID_SOCKET;
sock_type = IP::TYPE_NONE;
status = STATUS_NONE;
@@ -291,13 +289,13 @@ 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 StreamPeerWinsock::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);
sock_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6;
sockfd = _socket_create(sock_type, SOCK_STREAM, IPPROTO_TCP);
- if (sockfd == INVALID_SOCKET) {
+ if (sockfd == INVALID_SOCKET) {
ERR_PRINT("Socket creation failed!");
disconnect_from_host();
//perror("socket");
@@ -314,7 +312,7 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_po
struct sockaddr_storage their_addr;
size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type);
- if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == SOCKET_ERROR) {
+ if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == SOCKET_ERROR) {
if (WSAGetLastError() != WSAEWOULDBLOCK) {
ERR_PRINT("Connection to remote host failed!");
@@ -333,18 +331,17 @@ Error StreamPeerWinsock::connect_to_host(const IP_Address& p_host, uint16_t p_po
};
void StreamPeerWinsock::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));
+ 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 {
unsigned long len;
- int ret = ioctlsocket(sockfd,FIONREAD,&len);
- ERR_FAIL_COND_V(ret==-1,0)
+ int ret = ioctlsocket(sockfd, FIONREAD, &len);
+ ERR_FAIL_COND_V(ret == -1, 0)
return len;
-
}
IP_Address StreamPeerWinsock::get_connected_host() const {
@@ -370,5 +367,4 @@ StreamPeerWinsock::~StreamPeerWinsock() {
disconnect_from_host();
};
-
#endif