38 #pragma warning(disable: 4005) 41 #define ERRNO WSAGetLastError() 43 #define EAGAIN WSAEWOULDBLOCK 45 #define EINTR WSAEINTR 47 #define ECONNRESET WSAECONNRESET 48 static inline int SetNonblocking(
int s)
51 return ioctlsocket(s, FIONBIO, &arg);
53 #define SETNONBLOCK(s) SetNonblocking(s) 55 #define close closesocket 56 #define IS_INVALID_SOCKET(fd) (fd==INVALID_SOCKET) 63 #include <netinet/in.h> 64 #include <sys/socket.h> 65 #include <sys/select.h> 71 #define SETNONBLOCK(s) fcntl(s,F_SETFL,O_NONBLOCK) 72 #define SOCKLEN_T socklen_t 74 #define IS_INVALID_SOCKET(fd) (fd<0) 75 #define INVALID_SOCKET (-1) 76 #define STRERROR(x) strerror(x) 80 long long int GetNow(
void);
87 virtual ~
Socket() { hangup(); }
89 virtual void prepareSelectFds(fd_set &read_fds, fd_set &write_fds,
int &fd_max) = 0;
90 virtual void handleSelectFds(
const fd_set &read_fds,
const fd_set &write_fds) = 0;
91 virtual bool isClosed()
const 93 return IS_INVALID_SOCKET(fd);
95 virtual bool isTcpConnection()
const {
return false; }
96 virtual void sendPosition(
unsigned int ra_int,
int dec_int,
int status) {Q_UNUSED(ra_int); Q_UNUSED(dec_int); Q_UNUSED(status);}
99 Socket(
Server &server, SOCKET fd) : server(server), fd(fd) {}
103 virtual int readNonblocking(
char *buf,
int count)
105 return recv(fd, buf, count, 0);
107 virtual int writeNonblocking(
const char *buf,
int count)
109 return send(fd, buf, count, 0);
112 int readNonblocking(
void *buf,
int count)
114 return read(fd, buf, count);
116 int writeNonblocking(
const void *buf,
int count) {
117 return write(fd, buf, count);
Base class for telescope server classes.