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 CTCPSOCKET_H
|
---|
16 | #define CTCPSOCKET_H
|
---|
17 |
|
---|
18 | #include "IDataSocket.h"
|
---|
19 | #include "CStreamBuffer.h"
|
---|
20 | #include "CCondVar.h"
|
---|
21 | #include "CMutex.h"
|
---|
22 | #include "IArchNetwork.h"
|
---|
23 |
|
---|
24 | class CMutex;
|
---|
25 | class CThread;
|
---|
26 | class ISocketMultiplexerJob;
|
---|
27 |
|
---|
28 | //! TCP data socket
|
---|
29 | /*!
|
---|
30 | A data socket using TCP.
|
---|
31 | */
|
---|
32 | class CTCPSocket : public IDataSocket {
|
---|
33 | public:
|
---|
34 | CTCPSocket();
|
---|
35 | CTCPSocket(CArchSocket);
|
---|
36 | ~CTCPSocket();
|
---|
37 |
|
---|
38 | // ISocket overrides
|
---|
39 | virtual void bind(const CNetworkAddress&);
|
---|
40 | virtual void close();
|
---|
41 | virtual void* getEventTarget() const;
|
---|
42 |
|
---|
43 | // IStream overrides
|
---|
44 | virtual UInt32 read(void* buffer, UInt32 n);
|
---|
45 | virtual void write(const void* buffer, UInt32 n);
|
---|
46 | virtual void flush();
|
---|
47 | virtual void shutdownInput();
|
---|
48 | virtual void shutdownOutput();
|
---|
49 | virtual bool isReady() const;
|
---|
50 | virtual UInt32 getSize() const;
|
---|
51 |
|
---|
52 | // IDataSocket overrides
|
---|
53 | virtual void connect(const CNetworkAddress&);
|
---|
54 |
|
---|
55 | private:
|
---|
56 | void init();
|
---|
57 |
|
---|
58 | void setJob(ISocketMultiplexerJob*);
|
---|
59 | ISocketMultiplexerJob* newJob();
|
---|
60 | void sendConnectionFailedEvent(const char*);
|
---|
61 | void sendEvent(CEvent::Type);
|
---|
62 |
|
---|
63 | void onConnected();
|
---|
64 | void onInputShutdown();
|
---|
65 | void onOutputShutdown();
|
---|
66 | void onDisconnected();
|
---|
67 |
|
---|
68 | ISocketMultiplexerJob*
|
---|
69 | serviceConnecting(ISocketMultiplexerJob*,
|
---|
70 | bool, bool, bool);
|
---|
71 | ISocketMultiplexerJob*
|
---|
72 | serviceConnected(ISocketMultiplexerJob*,
|
---|
73 | bool, bool, bool);
|
---|
74 |
|
---|
75 | private:
|
---|
76 | CMutex m_mutex;
|
---|
77 | CArchSocket m_socket;
|
---|
78 | CStreamBuffer m_inputBuffer;
|
---|
79 | CStreamBuffer m_outputBuffer;
|
---|
80 | CCondVar<bool> m_flushed;
|
---|
81 | bool m_connected;
|
---|
82 | bool m_readable;
|
---|
83 | bool m_writable;
|
---|
84 | };
|
---|
85 |
|
---|
86 | #endif
|
---|