| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_WIN32SOCKETSERVER_H_ | 11 #ifndef WEBRTC_BASE_WIN32SOCKETSERVER_H_ |
| 12 #define WEBRTC_BASE_WIN32SOCKETSERVER_H_ | 12 #define WEBRTC_BASE_WIN32SOCKETSERVER_H_ |
| 13 | 13 |
| 14 #if defined(WEBRTC_WIN) | |
| 15 #include "webrtc/base/asyncsocket.h" | |
| 16 #include "webrtc/base/criticalsection.h" | |
| 17 #include "webrtc/base/messagequeue.h" | |
| 18 #include "webrtc/base/socketserver.h" | |
| 19 #include "webrtc/base/socketfactory.h" | |
| 20 #include "webrtc/base/socket.h" | |
| 21 #include "webrtc/base/thread.h" | |
| 22 #include "webrtc/base/win32window.h" | |
| 23 | 14 |
| 24 namespace rtc { | 15 // This header is deprecated and is just left here temporarily during |
| 25 | 16 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
| 26 /////////////////////////////////////////////////////////////////////////////// | 17 #include "webrtc/rtc_base/win32socketserver.h" |
| 27 // Win32Socket | |
| 28 /////////////////////////////////////////////////////////////////////////////// | |
| 29 | |
| 30 class Win32Socket : public AsyncSocket { | |
| 31 public: | |
| 32 Win32Socket(); | |
| 33 virtual ~Win32Socket(); | |
| 34 | |
| 35 bool CreateT(int family, int type); | |
| 36 | |
| 37 int Attach(SOCKET s); | |
| 38 void SetTimeout(int ms); | |
| 39 | |
| 40 // AsyncSocket Interface | |
| 41 virtual SocketAddress GetLocalAddress() const; | |
| 42 virtual SocketAddress GetRemoteAddress() const; | |
| 43 virtual int Bind(const SocketAddress& addr); | |
| 44 virtual int Connect(const SocketAddress& addr); | |
| 45 virtual int Send(const void *buffer, size_t length); | |
| 46 virtual int SendTo(const void *buffer, size_t length, const SocketAddress& add
r); | |
| 47 virtual int Recv(void* buffer, size_t length, int64_t* timestamp); | |
| 48 virtual int RecvFrom(void* buffer, | |
| 49 size_t length, | |
| 50 SocketAddress* out_addr, | |
| 51 int64_t* timestamp); | |
| 52 virtual int Listen(int backlog); | |
| 53 virtual Win32Socket *Accept(SocketAddress *out_addr); | |
| 54 virtual int Close(); | |
| 55 virtual int GetError() const; | |
| 56 virtual void SetError(int error); | |
| 57 virtual ConnState GetState() const; | |
| 58 virtual int GetOption(Option opt, int* value); | |
| 59 virtual int SetOption(Option opt, int value); | |
| 60 | |
| 61 private: | |
| 62 void CreateSink(); | |
| 63 bool SetAsync(int events); | |
| 64 int DoConnect(const SocketAddress& addr); | |
| 65 bool HandleClosed(int close_error); | |
| 66 void PostClosed(); | |
| 67 void UpdateLastError(); | |
| 68 static int TranslateOption(Option opt, int* slevel, int* sopt); | |
| 69 | |
| 70 void OnSocketNotify(SOCKET socket, int event, int error); | |
| 71 void OnDnsNotify(HANDLE task, int error); | |
| 72 | |
| 73 SOCKET socket_; | |
| 74 int error_; | |
| 75 ConnState state_; | |
| 76 SocketAddress addr_; // address that we connected to (see DoConnect) | |
| 77 uint32_t connect_time_; | |
| 78 bool closing_; | |
| 79 int close_error_; | |
| 80 | |
| 81 class EventSink; | |
| 82 friend class EventSink; | |
| 83 EventSink * sink_; | |
| 84 | |
| 85 struct DnsLookup; | |
| 86 DnsLookup * dns_; | |
| 87 }; | |
| 88 | |
| 89 /////////////////////////////////////////////////////////////////////////////// | |
| 90 // Win32SocketServer | |
| 91 /////////////////////////////////////////////////////////////////////////////// | |
| 92 | |
| 93 class Win32SocketServer : public SocketServer { | |
| 94 public: | |
| 95 Win32SocketServer(); | |
| 96 virtual ~Win32SocketServer(); | |
| 97 | |
| 98 void set_modeless_dialog(HWND hdlg) { | |
| 99 hdlg_ = hdlg; | |
| 100 } | |
| 101 | |
| 102 // SocketServer Interface | |
| 103 virtual Socket* CreateSocket(int type); | |
| 104 virtual Socket* CreateSocket(int family, int type); | |
| 105 | |
| 106 virtual AsyncSocket* CreateAsyncSocket(int type); | |
| 107 virtual AsyncSocket* CreateAsyncSocket(int family, int type); | |
| 108 | |
| 109 virtual void SetMessageQueue(MessageQueue* queue); | |
| 110 virtual bool Wait(int cms, bool process_io); | |
| 111 virtual void WakeUp(); | |
| 112 | |
| 113 void Pump(); | |
| 114 | |
| 115 HWND handle() { return wnd_.handle(); } | |
| 116 | |
| 117 private: | |
| 118 class MessageWindow : public Win32Window { | |
| 119 public: | |
| 120 explicit MessageWindow(Win32SocketServer* ss) : ss_(ss) {} | |
| 121 private: | |
| 122 virtual bool OnMessage(UINT msg, WPARAM wp, LPARAM lp, LRESULT& result); | |
| 123 Win32SocketServer* ss_; | |
| 124 }; | |
| 125 | |
| 126 static const TCHAR kWindowName[]; | |
| 127 MessageQueue *message_queue_; | |
| 128 MessageWindow wnd_; | |
| 129 CriticalSection cs_; | |
| 130 bool posted_; | |
| 131 HWND hdlg_; | |
| 132 }; | |
| 133 | |
| 134 /////////////////////////////////////////////////////////////////////////////// | |
| 135 // Win32Thread. Automatically pumps Windows messages. | |
| 136 /////////////////////////////////////////////////////////////////////////////// | |
| 137 | |
| 138 class Win32Thread : public Thread { | |
| 139 public: | |
| 140 explicit Win32Thread(SocketServer* ss) : Thread(ss), id_(0) {} | |
| 141 virtual ~Win32Thread() { | |
| 142 Stop(); | |
| 143 } | |
| 144 virtual void Run() { | |
| 145 id_ = GetCurrentThreadId(); | |
| 146 Thread::Run(); | |
| 147 id_ = 0; | |
| 148 } | |
| 149 virtual void Quit() { | |
| 150 PostThreadMessage(id_, WM_QUIT, 0, 0); | |
| 151 } | |
| 152 private: | |
| 153 DWORD id_; | |
| 154 }; | |
| 155 | |
| 156 /////////////////////////////////////////////////////////////////////////////// | |
| 157 | |
| 158 } // namespace rtc | |
| 159 | |
| 160 #endif // WEBRTC_WIN | |
| 161 | 18 |
| 162 #endif // WEBRTC_BASE_WIN32SOCKETSERVER_H_ | 19 #endif // WEBRTC_BASE_WIN32SOCKETSERVER_H_ |
| OLD | NEW |