34 #define ERRNO WSAGetLastError() 36 #define EAGAIN WSAEWOULDBLOCK 38 #define EINTR WSAEINTR 40 #define ECONNRESET WSAECONNRESET 41 static inline int SetNonblocking(
int s)
44 return ioctlsocket(s, FIONBIO, &arg);
46 #define SETNONBLOCK(s) SetNonblocking(s) 48 #define close closesocket 49 #define IS_INVALID_SOCKET(fd) (fd==INVALID_SOCKET) 56 #include <netinet/in.h> 57 #include <sys/socket.h> 63 #define SETNONBLOCK(s) fcntl(s,F_SETFL,O_NONBLOCK) 64 #define SOCKLEN_T socklen_t 66 #define IS_INVALID_SOCKET(fd) (fd<0) 67 #define INVALID_SOCKET (-1) 68 #define STRERROR(x) strerror(x) 72 long long int GetNow(
void);
79 virtual ~
Socket() { hangup(); }
81 virtual void prepareSelectFds(fd_set &read_fds, fd_set &write_fds,
int &fd_max) = 0;
82 virtual void handleSelectFds(
const fd_set &read_fds,
const fd_set &write_fds) = 0;
83 virtual bool isClosed()
const 85 return IS_INVALID_SOCKET(fd);
87 virtual bool isTcpConnection()
const {
return false; }
88 virtual void sendPosition(
unsigned int ra_int,
int dec_int,
int status) {Q_UNUSED(ra_int); Q_UNUSED(dec_int); Q_UNUSED(status);}
91 Socket(
Server &server, SOCKET fd) : server(server), fd(fd) {}
95 virtual int readNonblocking(
char *buf,
int count)
97 return recv(fd, buf, count, 0);
99 virtual int writeNonblocking(
const char *buf,
int count)
101 return send(fd, buf, count, 0);
104 int readNonblocking(
void *buf,
int count)
106 return read(fd, buf, count);
108 int writeNonblocking(
const void *buf,
int count) {
109 return write(fd, buf, count);
Base class for telescope server classes.