summaryrefslogtreecommitdiffstats
path: root/source/MCSocket.h
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-03 20:41:19 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-10-03 20:41:19 +0200
commit386d58b5862d8b76925c6523721594887606e82a (patch)
treeef073e7a843f4b75a4008d4b7383f7cdf08ceee5 /source/MCSocket.h
parentVisual Studio 2010 solution and project files (diff)
downloadcuberite-386d58b5862d8b76925c6523721594887606e82a.tar
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.gz
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.bz2
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.lz
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.xz
cuberite-386d58b5862d8b76925c6523721594887606e82a.tar.zst
cuberite-386d58b5862d8b76925c6523721594887606e82a.zip
Diffstat (limited to '')
-rw-r--r--source/MCSocket.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/source/MCSocket.h b/source/MCSocket.h
new file mode 100644
index 000000000..554a5f35b
--- /dev/null
+++ b/source/MCSocket.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#ifdef _WIN32
+
+#include <winsock2.h>
+#define socklen_t int
+#ifdef SendMessage
+#undef SendMessage
+#endif
+#else
+
+// Linux threads http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
+
+#include <netdb.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <pthread.h>
+#include <unistd.h>
+#define SOCKET int
+typedef void *HANDLE;
+#define CRITICAL_SECTION pthread_mutex_t
+#define SD_BOTH (2)
+#define closesocket(x) (shutdown(x, SD_BOTH), close(x))
+#define SOCKET_ERROR SO_ERROR
+#define EnterCriticalSection(x) pthread_mutex_lock(x)
+#define LeaveCriticalSection(x) pthread_mutex_unlock(x)
+#define InitializeCriticalSection(x) pthread_mutex_init(x, NULL)
+#define DeleteCriticalSection(x) (x)
+#define sprintf_s(x, y, ...) sprintf(x, __VA_ARGS__)
+
+#endif
+
+inline bool IsSocketError( int a_ReturnedValue )
+{
+ #ifdef _WIN32
+ return (a_ReturnedValue == SOCKET_ERROR || a_ReturnedValue == 0);
+ #else
+ return (a_ReturnedValue <= 0);
+ #endif
+}