2003-01-04 22:01:32 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CARCHNETWORKWINSOCK_H
|
|
|
|
#define CARCHNETWORKWINSOCK_H
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
|
|
// declare no functions in winsock2
|
|
|
|
#define INCL_WINSOCK_API_PROTOTYPES 0
|
|
|
|
#define INCL_WINSOCK_API_TYPEDEFS 0
|
|
|
|
|
|
|
|
#include "IArchNetwork.h"
|
|
|
|
#include "IArchMultithread.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
|
|
|
#define ARCH_NETWORK CArchNetworkWinsock
|
|
|
|
|
|
|
|
class CArchSocketImpl {
|
|
|
|
public:
|
|
|
|
SOCKET m_socket;
|
|
|
|
int m_refCount;
|
2004-02-28 12:19:49 +00:00
|
|
|
WSAEVENT m_event;
|
|
|
|
bool m_pollWrite;
|
2003-01-04 22:01:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CArchNetAddressImpl {
|
|
|
|
public:
|
2004-02-28 12:19:49 +00:00
|
|
|
static CArchNetAddressImpl* alloc(size_t);
|
2003-01-04 22:01:32 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
int m_len;
|
2004-02-28 12:19:49 +00:00
|
|
|
struct sockaddr m_addr;
|
2003-01-04 22:01:32 +00:00
|
|
|
};
|
2004-02-28 12:19:49 +00:00
|
|
|
#define ADDR_HDR_SIZE offsetof(CArchNetAddressImpl, m_addr)
|
|
|
|
#define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_*>(&addr_->m_addr))
|
2003-01-04 22:01:32 +00:00
|
|
|
|
2003-01-05 21:48:54 +00:00
|
|
|
//! Win32 implementation of IArchNetwork
|
2003-01-04 22:01:32 +00:00
|
|
|
class CArchNetworkWinsock : public IArchNetwork {
|
|
|
|
public:
|
|
|
|
CArchNetworkWinsock();
|
|
|
|
virtual ~CArchNetworkWinsock();
|
|
|
|
|
|
|
|
// IArchNetwork overrides
|
|
|
|
virtual CArchSocket newSocket(EAddressFamily, ESocketType);
|
|
|
|
virtual CArchSocket copySocket(CArchSocket s);
|
|
|
|
virtual void closeSocket(CArchSocket s);
|
|
|
|
virtual void closeSocketForRead(CArchSocket s);
|
|
|
|
virtual void closeSocketForWrite(CArchSocket s);
|
|
|
|
virtual void bindSocket(CArchSocket s, CArchNetAddress addr);
|
|
|
|
virtual void listenOnSocket(CArchSocket s);
|
|
|
|
virtual CArchSocket acceptSocket(CArchSocket s, CArchNetAddress* addr);
|
2004-02-29 16:11:17 +00:00
|
|
|
virtual bool connectSocket(CArchSocket s, CArchNetAddress name);
|
2003-01-04 22:01:32 +00:00
|
|
|
virtual int pollSocket(CPollEntry[], int num, double timeout);
|
2004-02-28 12:19:49 +00:00
|
|
|
virtual void unblockPollSocket(CArchThread thread);
|
2003-01-04 22:01:32 +00:00
|
|
|
virtual size_t readSocket(CArchSocket s, void* buf, size_t len);
|
|
|
|
virtual size_t writeSocket(CArchSocket s,
|
|
|
|
const void* buf, size_t len);
|
|
|
|
virtual void throwErrorOnSocket(CArchSocket);
|
|
|
|
virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay);
|
|
|
|
virtual std::string getHostName();
|
|
|
|
virtual CArchNetAddress newAnyAddr(EAddressFamily);
|
|
|
|
virtual CArchNetAddress copyAddr(CArchNetAddress);
|
|
|
|
virtual CArchNetAddress nameToAddr(const std::string&);
|
|
|
|
virtual void closeAddr(CArchNetAddress);
|
|
|
|
virtual std::string addrToName(CArchNetAddress);
|
|
|
|
virtual std::string addrToString(CArchNetAddress);
|
|
|
|
virtual EAddressFamily getAddrFamily(CArchNetAddress);
|
|
|
|
virtual void setAddrPort(CArchNetAddress, int port);
|
|
|
|
virtual int getAddrPort(CArchNetAddress);
|
|
|
|
virtual bool isAnyAddr(CArchNetAddress);
|
2004-02-28 12:19:49 +00:00
|
|
|
virtual bool isEqualAddr(CArchNetAddress, CArchNetAddress);
|
2003-01-04 22:01:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void init(HMODULE);
|
|
|
|
|
2004-02-29 16:11:17 +00:00
|
|
|
void setBlockingOnSocket(SOCKET, bool blocking);
|
|
|
|
|
2003-01-04 22:01:32 +00:00
|
|
|
void throwError(int);
|
|
|
|
void throwNameError(int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
CArchMutex m_mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|