Socket.hpp   Socket.hpp 
/* /*
The stellarium telescope library helps building The stellarium telescope library helps building
telescope server programs, that can communicate with stellarium telescope server programs, that can communicate with stellarium
by means of the stellarium TCP telescope protocol. by means of the stellarium TCP telescope protocol.
It also contains smaple server classes (dummy, Meade LX200). It also contains smaple server classes (dummy, Meade LX200).
Author and Copyright of this file and of the stellarium telescope library: Author and Copyright of this file and of the stellarium telescope library:
Johannes Gajdosik, 2006 Johannes Gajdosik, 2006
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU General Public License
License as published by the Free Software Foundation; either as published by the Free Software Foundation; either version 2
version 2.1 of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU General Public License
License along with this library; if not, write to the Free Software along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA USA.
*/ */
#ifndef _SOCKET_HPP_ #ifndef _SOCKET_HPP_
#define _SOCKET_HPP_ #define _SOCKET_HPP_
#ifdef WIN32 #include <QtGlobal>
#ifdef Q_OS_WIN32
#include <winsock2.h> #include <winsock2.h>
#include <fcntl.h> #include <fcntl.h>
#define ERRNO WSAGetLastError() #define ERRNO WSAGetLastError()
#undef EAGAIN #undef EAGAIN
#define EAGAIN WSAEWOULDBLOCK #define EAGAIN WSAEWOULDBLOCK
#undef EINTR #undef EINTR
#define EINTR WSAEINTR #define EINTR WSAEINTR
#undef ECONNRESET #undef ECONNRESET
skipping to change at line 69 skipping to change at line 71
#include <errno.h> #include <errno.h>
#include <string.h> // strerror #include <string.h> // strerror
#define ERRNO errno #define ERRNO errno
#define SETNONBLOCK(s) fcntl(s,F_SETFL,O_NONBLOCK) #define SETNONBLOCK(s) fcntl(s,F_SETFL,O_NONBLOCK)
#define SOCKLEN_T socklen_t #define SOCKLEN_T socklen_t
#define SOCKET int #define SOCKET int
#define IS_INVALID_SOCKET(fd) (fd<0) #define IS_INVALID_SOCKET(fd) (fd<0)
#define INVALID_SOCKET (-1) #define INVALID_SOCKET (-1)
#define STRERROR(x) strerror(x) #define STRERROR(x) strerror(x)
#endif //WIN32 #endif //Q_OS_WIN32
long long int GetNow(void); long long int GetNow(void);
class Server; class Server;
class Socket class Socket
{ {
public: public:
virtual ~Socket(void) { hangup(); } virtual ~Socket() { hangup(); }
void hangup(void); void hangup();
virtual void prepareSelectFds(fd_set &read_fds, fd_set &write_fds, i nt &fd_max) = 0; virtual void prepareSelectFds(fd_set &read_fds, fd_set &write_fds, i nt &fd_max) = 0;
virtual void handleSelectFds(const fd_set &read_fds, const fd_set &w rite_fds) = 0; virtual void handleSelectFds(const fd_set &read_fds, const fd_set &w rite_fds) = 0;
virtual bool isClosed(void) const virtual bool isClosed() const
{ {
return IS_INVALID_SOCKET(fd); return IS_INVALID_SOCKET(fd);
} }
virtual bool isTcpConnection(void) const { return false; } virtual bool isTcpConnection() const { return false; }
virtual void sendPosition(unsigned int ra_int, int dec_int, int stat virtual void sendPosition(unsigned int ra_int, int dec_int, int stat
us) {} us) {Q_UNUSED(ra_int); Q_UNUSED(dec_int); Q_UNUSED(status);}
protected: protected:
Socket(Server &server, SOCKET fd) : server(server), fd(fd) {} Socket(Server &server, SOCKET fd) : server(server), fd(fd) {}
Server & server; Server & server;
#ifdef WIN32 #ifdef Q_OS_WIN32
virtual int readNonblocking(char *buf, int count) virtual int readNonblocking(char *buf, int count)
{ {
return recv(fd, buf, count, 0); return recv(fd, buf, count, 0);
} }
virtual int writeNonblocking(const char *buf, int count) virtual int writeNonblocking(const char *buf, int count)
{ {
return send(fd, buf, count, 0); return send(fd, buf, count, 0);
} }
#else #else
int readNonblocking(void *buf, int count) int readNonblocking(void *buf, int count)
 End of changes. 9 change blocks. 
18 lines changed or deleted 20 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/