00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef MYSOCKET_INCLUDED
00027 #define MYSOCKET_INCLUDED
00028
00033 #include <string>
00034 #include "config.h"
00035
00036 #if defined(_MSC_VER) || defined(HAVE_SYS_MINGW)
00037 #include <winsock2.h>
00038 #undef GetCurrentTime // defined by winbase.h, clashes with SystemClock::GetCurrentTime()
00039 #include <sys/types.h>
00040 #define ssize_t size_t
00041 #else
00042 #include <unistd.h>
00043 #endif
00044
00045 class Socket {
00046
00047 private:
00048 # if defined(_MSC_VER) || defined(HAVE_SYS_MINGW)
00049 static void Start();
00050 static void End();
00051 static int socketCount;
00052 SOCKET _socket;
00053 # else
00054 int sock, conn;
00055 void OpenSocket(int port);
00056 # endif
00057
00058 public:
00059 Socket(int port);
00060 ~Socket();
00061 ssize_t Read(std::string &a);
00062 void Write(const std::string &s);
00063 ssize_t Poll();
00064
00065 void Write(const char *in) {
00066 std::string a(in);
00067 Write(a);
00068 }
00069 };
00070
00071
00072 #endif
00073