diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2017-03-05 16:44:50 +0100 |
commit | 5dbf1809c6e3e905b94b8764e99491e608122261 (patch) | |
tree | 5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /drivers/unix/stream_peer_tcp_posix.cpp | |
parent | 45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff) | |
download | redot-engine-5dbf1809c6e3e905b94b8764e99491e608122261.tar.gz |
A Whole New World (clang-format edition)
I can show you the code
Pretty, with proper whitespace
Tell me, coder, now when did
You last write readable code?
I can open your eyes
Make you see your bad indent
Force you to respect the style
The core devs agreed upon
A whole new world
A new fantastic code format
A de facto standard
With some sugar
Enforced with clang-format
A whole new world
A dazzling style we all dreamed of
And when we read it through
It's crystal clear
That now we're in a whole new world of code
Diffstat (limited to 'drivers/unix/stream_peer_tcp_posix.cpp')
-rw-r--r-- | drivers/unix/stream_peer_tcp_posix.cpp | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index 08a2954617..fc4838f1e0 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -30,21 +30,21 @@ #include "stream_peer_tcp_posix.h" +#include <errno.h> +#include <netdb.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> -#include <errno.h> #include <string.h> -#include <netdb.h> -#include <sys/types.h> #include <sys/ioctl.h> +#include <sys/types.h> +#include <unistd.h> #ifndef NO_FCNTL - #ifdef __HAIKU__ - #include <fcntl.h> - #else - #include <sys/fcntl.h> - #endif +#ifdef __HAIKU__ +#include <fcntl.h> +#else +#include <sys/fcntl.h> +#endif #else #include <sys/ioctl.h> #endif @@ -58,12 +58,12 @@ #include <netinet/tcp.h> #if defined(OSX_ENABLED) || defined(IPHONE_ENABLED) - #define MSG_NOSIGNAL SO_NOSIGPIPE +#define MSG_NOSIGNAL SO_NOSIGPIPE #endif #include "drivers/unix/socket_helpers.h" -StreamPeerTCP* StreamPeerTCPPosix::_create() { +StreamPeerTCP *StreamPeerTCPPosix::_create() { return memnew(StreamPeerTCPPosix); }; @@ -95,7 +95,7 @@ Error StreamPeerTCPPosix::_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) == -1) { + if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == -1) { if (errno == EISCONN) { status = STATUS_CONNECTED; @@ -134,9 +134,9 @@ void StreamPeerTCPPosix::set_socket(int p_sockfd, IP_Address p_host, int p_port, peer_port = p_port; }; -Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_port) { +Error StreamPeerTCPPosix::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); @@ -158,7 +158,7 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p size_t addr_size = _set_sockaddr(&their_addr, p_host, p_port, sock_type); errno = 0; - if (::connect(sockfd, (struct sockaddr *)&their_addr,addr_size) == -1 && errno != EINPROGRESS) { + if (::connect(sockfd, (struct sockaddr *)&their_addr, addr_size) == -1 && errno != EINPROGRESS) { ERR_PRINT("Connection to remote host failed!"); disconnect_from_host(); @@ -177,7 +177,7 @@ Error StreamPeerTCPPosix::connect_to_host(const IP_Address& p_host, uint16_t p_p return OK; }; -Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, bool p_block) { +Error StreamPeerTCPPosix::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool p_block) { if (status == STATUS_NONE || status == STATUS_ERROR) { @@ -237,7 +237,7 @@ Error StreamPeerTCPPosix::write(const uint8_t* p_data,int p_bytes, int &r_sent, return OK; }; -Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, bool p_block) { +Error StreamPeerTCPPosix::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { if (!is_connected_to_host()) { @@ -282,9 +282,9 @@ Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, b }; _block(sockfd, true, false); - } else if (read==0) { + } else if (read == 0) { - sockfd=-1; + sockfd = -1; status = STATUS_NONE; peer_port = 0; peer_host = IP_Address(); @@ -305,8 +305,8 @@ Error StreamPeerTCPPosix::read(uint8_t* p_buffer, int p_bytes,int &r_received, b void StreamPeerTCPPosix::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 flag = p_enabled ? 1 : 0; + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); } bool StreamPeerTCPPosix::is_connected_to_host() const { @@ -319,7 +319,7 @@ bool StreamPeerTCPPosix::is_connected_to_host() const { return true; }; - return (sockfd!=-1); + return (sockfd != -1); }; StreamPeerTCP::Status StreamPeerTCPPosix::get_status() const { @@ -331,39 +331,37 @@ StreamPeerTCP::Status StreamPeerTCPPosix::get_status() const { return status; }; - void StreamPeerTCPPosix::disconnect_from_host() { if (sockfd != -1) close(sockfd); sock_type = IP::TYPE_NONE; - sockfd=-1; + sockfd = -1; status = STATUS_NONE; peer_port = 0; peer_host = IP_Address(); }; - -Error StreamPeerTCPPosix::put_data(const uint8_t* p_data,int p_bytes) { +Error StreamPeerTCPPosix::put_data(const uint8_t *p_data, int p_bytes) { int total; return write(p_data, p_bytes, total, true); }; -Error StreamPeerTCPPosix::put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent) { +Error StreamPeerTCPPosix::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { return write(p_data, p_bytes, r_sent, false); }; -Error StreamPeerTCPPosix::get_data(uint8_t* p_buffer, int p_bytes) { +Error StreamPeerTCPPosix::get_data(uint8_t *p_buffer, int p_bytes) { int total; return read(p_buffer, p_bytes, total, true); }; -Error StreamPeerTCPPosix::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r_received) { +Error StreamPeerTCPPosix::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { return read(p_buffer, p_bytes, r_received, false); }; @@ -371,10 +369,9 @@ Error StreamPeerTCPPosix::get_partial_data(uint8_t* p_buffer, int p_bytes,int &r int StreamPeerTCPPosix::get_available_bytes() const { unsigned long len; - int ret = ioctl(sockfd,FIONREAD,&len); - ERR_FAIL_COND_V(ret==-1,0) + int ret = ioctl(sockfd, FIONREAD, &len); + ERR_FAIL_COND_V(ret == -1, 0) return len; - } IP_Address StreamPeerTCPPosix::get_connected_host() const { |