35 #define ERRNO WSAGetLastError()
37 #define EAGAIN WSAEWOULDBLOCK
39 #define EINTR WSAEINTR
41 #define ECONNRESET WSAECONNRESET
42 static inline int SetNonblocking(
int s)
45 return ioctlsocket(
s, FIONBIO, &arg);
47 #define SETNONBLOCK(s) SetNonblocking(s)
49 #define close closesocket
50 #define IS_INVALID_SOCKET(fd) (fd==INVALID_SOCKET)
57 #include <netinet/in.h>
58 #include <sys/socket.h>
64 #define SETNONBLOCK(s) fcntl(s,F_SETFL,O_NONBLOCK)
65 #define SOCKLEN_T socklen_t
67 #define IS_INVALID_SOCKET(fd) (fd<0)
68 #define INVALID_SOCKET (-1)
69 #define STRERROR(x) strerror(x)
73 long long int GetNow(
void);
80 virtual ~
Socket() { hangup(); }
82 virtual void prepareSelectFds(fd_set &read_fds, fd_set &write_fds,
int &fd_max) = 0;
83 virtual void handleSelectFds(
const fd_set &read_fds,
const fd_set &write_fds) = 0;
84 virtual bool isClosed()
const
86 return IS_INVALID_SOCKET(fd);
88 virtual bool isTcpConnection()
const {
return false; }
89 virtual void sendPosition(
unsigned int ra_int,
int dec_int,
int status) {Q_UNUSED(ra_int); Q_UNUSED(dec_int); Q_UNUSED(status);}
92 Socket(
Server &server, SOCKET fd) : server(server), fd(fd) {}
96 virtual int readNonblocking(
char *buf,
int count)
98 return recv(fd, buf, count, 0);
100 virtual int writeNonblocking(
const char *buf,
int count)
102 return send(fd, buf, count, 0);
105 int readNonblocking(
void *buf,
int count)
107 return read(fd, buf, count);
109 int writeNonblocking(
const void *buf,
int count) {
110 return write(fd, buf, count);