summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/Socket.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-01-27 21:27:13 +0100
committermadmaxoft <github@xoft.cz>2014-01-27 21:27:13 +0100
commitcc1284a753874aa7d351a6ea41aaec4662ca6e57 (patch)
tree1d865db64553efc61d16203e06eb93d83e636bc0 /src/OSSupport/Socket.cpp
parentFixed client packet parsing. (diff)
downloadcuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.tar
cuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.tar.gz
cuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.tar.bz2
cuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.tar.lz
cuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.tar.xz
cuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.tar.zst
cuberite-cc1284a753874aa7d351a6ea41aaec4662ca6e57.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/Socket.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/OSSupport/Socket.cpp b/src/OSSupport/Socket.cpp
index 4226a7535..3248eed88 100644
--- a/src/OSSupport/Socket.cpp
+++ b/src/OSSupport/Socket.cpp
@@ -320,7 +320,7 @@ bool cSocket::ConnectIPv4(const AString & a_HostNameOrAddr, unsigned short a_Por
-int cSocket::Receive(char* a_Buffer, unsigned int a_Length, unsigned int a_Flags)
+int cSocket::Receive(char * a_Buffer, unsigned int a_Length, unsigned int a_Flags)
{
return recv(m_Socket, a_Buffer, a_Length, a_Flags);
}
@@ -354,3 +354,32 @@ unsigned short cSocket::GetPort(void) const
+
+void cSocket::SetNonBlocking(void)
+{
+ #ifdef _WIN32
+ u_long NonBlocking = 1;
+ int res = ioctlsocket(m_Socket, FIONBIO, &NonBlocking);
+ if (res != 0)
+ {
+ LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s",
+ res, GetLastError(), GetLastErrorString().c_str()
+ );
+ abort();
+ }
+ #else
+ int NonBlocking = 1;
+ int res = ioctl(m_Socket, FIONBIO, (char *)&NonBlocking);
+ if (res != 0)
+ {
+ LOGERROR("Cannot set socket to non-blocking. This would make the server deadlock later on, aborting.\nErr: %d, %d, %s",
+ res, GetLastError(), GetLastErrorString().c_str()
+ );
+ abort();
+ }
+ #endif
+}
+
+
+
+