source: trunk/synergy/lib/arch/CArchNetworkWinsock.h

Last change on this file was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 3.1 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2002 Chris Schoeneman
4 *
5 * This package is free software you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef CARCHNETWORKWINSOCK_H
16#define CARCHNETWORKWINSOCK_H
17
18#define WIN32_LEAN_AND_MEAN
19
20// declare no functions in winsock2
21#define INCL_WINSOCK_API_PROTOTYPES 0
22#define INCL_WINSOCK_API_TYPEDEFS 0
23
24#include "IArchNetwork.h"
25#include "IArchMultithread.h"
26#include <windows.h>
27#include <winsock2.h>
28
29#define ARCH_NETWORK CArchNetworkWinsock
30
31class CArchSocketImpl {
32public:
33 SOCKET m_socket;
34 int m_refCount;
35 WSAEVENT m_event;
36 bool m_pollWrite;
37};
38
39class CArchNetAddressImpl {
40public:
41 static CArchNetAddressImpl* alloc(size_t);
42
43public:
44 int m_len;
45 struct sockaddr m_addr;
46};
47#define ADDR_HDR_SIZE offsetof(CArchNetAddressImpl, m_addr)
48#define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_*>(&addr_->m_addr))
49
50//! Win32 implementation of IArchNetwork
51class CArchNetworkWinsock : public IArchNetwork {
52public:
53 CArchNetworkWinsock();
54 virtual ~CArchNetworkWinsock();
55
56 // IArchNetwork overrides
57 virtual CArchSocket newSocket(EAddressFamily, ESocketType);
58 virtual CArchSocket copySocket(CArchSocket s);
59 virtual void closeSocket(CArchSocket s);
60 virtual void closeSocketForRead(CArchSocket s);
61 virtual void closeSocketForWrite(CArchSocket s);
62 virtual void bindSocket(CArchSocket s, CArchNetAddress addr);
63 virtual void listenOnSocket(CArchSocket s);
64 virtual CArchSocket acceptSocket(CArchSocket s, CArchNetAddress* addr);
65 virtual bool connectSocket(CArchSocket s, CArchNetAddress name);
66 virtual int pollSocket(CPollEntry[], int num, double timeout);
67 virtual void unblockPollSocket(CArchThread thread);
68 virtual size_t readSocket(CArchSocket s, void* buf, size_t len);
69 virtual size_t writeSocket(CArchSocket s,
70 const void* buf, size_t len);
71 virtual void throwErrorOnSocket(CArchSocket);
72 virtual bool setNoDelayOnSocket(CArchSocket, bool noDelay);
73 virtual bool setReuseAddrOnSocket(CArchSocket, bool reuse);
74 virtual std::string getHostName();
75 virtual CArchNetAddress newAnyAddr(EAddressFamily);
76 virtual CArchNetAddress copyAddr(CArchNetAddress);
77 virtual CArchNetAddress nameToAddr(const std::string&);
78 virtual void closeAddr(CArchNetAddress);
79 virtual std::string addrToName(CArchNetAddress);
80 virtual std::string addrToString(CArchNetAddress);
81 virtual EAddressFamily getAddrFamily(CArchNetAddress);
82 virtual void setAddrPort(CArchNetAddress, int port);
83 virtual int getAddrPort(CArchNetAddress);
84 virtual bool isAnyAddr(CArchNetAddress);
85 virtual bool isEqualAddr(CArchNetAddress, CArchNetAddress);
86
87private:
88 void init(HMODULE);
89
90 void setBlockingOnSocket(SOCKET, bool blocking);
91
92 void throwError(int);
93 void throwNameError(int);
94
95private:
96 CArchMutex m_mutex;
97};
98
99#endif
Note: See TracBrowser for help on using the repository browser.