| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * libjingle | |
| 3 * Copyright 2004--2005, Google Inc. | |
| 4 * | |
| 5 * Redistribution and use in source and binary forms, with or without | |
| 6 * modification, are permitted provided that the following conditions are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | |
| 9 * this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| 11 * this list of conditions and the following disclaimer in the documentation | |
| 12 * and/or other materials provided with the distribution. | |
| 13 * 3. The name of the author may not be used to endorse or promote products | |
| 14 * derived from this software without specific prior written permission. | |
| 15 * | |
| 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
| 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
| 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
| 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 26 */ | |
| 27 | |
| 28 #ifndef TALK_BASE_WIN32SOCKETSERVER_H__ | |
| 29 #define TALK_BASE_WIN32SOCKETSERVER_H__ | |
| 30 | |
| 31 #ifdef WIN32 | |
| 32 | |
| 33 #include "talk/base/messagequeue.h" | |
| 34 #include "talk/base/socketserver.h" | |
| 35 #include "talk/base/socketfactory.h" | |
| 36 #include "talk/base/socket.h" | |
| 37 #include "talk/base/asyncsocket.h" | |
| 38 | |
| 39 namespace talk_base { | |
| 40 | |
| 41 /////////////////////////////////////////////////////////////////////////////// | |
| 42 // Win32Socket | |
| 43 /////////////////////////////////////////////////////////////////////////////// | |
| 44 | |
| 45 class Win32Socket : public talk_base::AsyncSocket { | |
| 46 public: | |
| 47 Win32Socket(); | |
| 48 virtual ~Win32Socket(); | |
| 49 | |
| 50 int Attach(SOCKET s); | |
| 51 void SetTimeout(int ms); | |
| 52 | |
| 53 // AsyncSocket Interface | |
| 54 virtual SocketAddress GetLocalAddress() const; | |
| 55 virtual SocketAddress GetRemoteAddress() const; | |
| 56 virtual int Bind(const SocketAddress& addr); | |
| 57 virtual int Connect(const SocketAddress& addr); | |
| 58 virtual int Send(const void *pv, size_t cb); | |
| 59 virtual int SendTo(const void *pv, size_t cb, const SocketAddress& addr); | |
| 60 virtual int Recv(void *pv, size_t cb); | |
| 61 virtual int RecvFrom(void *pv, size_t cb, SocketAddress *paddr); | |
| 62 virtual int Listen(int backlog); | |
| 63 virtual Socket *Accept(SocketAddress *paddr); | |
| 64 virtual int Close(); | |
| 65 virtual int GetError() const; | |
| 66 virtual void SetError(int error); | |
| 67 virtual ConnState GetState() const; | |
| 68 virtual int EstimateMTU(uint16* mtu); | |
| 69 virtual int SetOption(Option opt, int value); | |
| 70 | |
| 71 private: | |
| 72 bool Create(long events); | |
| 73 void UpdateLastError(); | |
| 74 | |
| 75 int DoConnect(const sockaddr_in& addr); | |
| 76 void OnSocketNotify(int event, int error); | |
| 77 void OnDnsNotify(int ip, int error); | |
| 78 | |
| 79 sockaddr_in addr_; // address that we connected to (see DoConnect) | |
| 80 SOCKET socket_; | |
| 81 int error_; | |
| 82 uint32 connect_time_; | |
| 83 ConnState state_; | |
| 84 bool signal_close_; | |
| 85 | |
| 86 class EventSink; | |
| 87 friend class EventSink; | |
| 88 EventSink * sink_; | |
| 89 | |
| 90 struct DnsLookup; | |
| 91 DnsLookup * dns_; | |
| 92 }; | |
| 93 | |
| 94 /////////////////////////////////////////////////////////////////////////////// | |
| 95 // Win32SocketServer | |
| 96 /////////////////////////////////////////////////////////////////////////////// | |
| 97 | |
| 98 class Win32SocketServer : public SocketServer { | |
| 99 public: | |
| 100 Win32SocketServer(MessageQueue *message_queue); | |
| 101 virtual ~Win32SocketServer(); | |
| 102 | |
| 103 // SocketServer Interface | |
| 104 virtual Socket* CreateSocket(int type); | |
| 105 virtual AsyncSocket* CreateAsyncSocket(int type); | |
| 106 virtual bool Wait(int cms, bool process_io); | |
| 107 virtual void WakeUp(); | |
| 108 | |
| 109 void Pump(); | |
| 110 | |
| 111 private: | |
| 112 void CreateDummyWindow(); | |
| 113 | |
| 114 MessageQueue *message_queue_; | |
| 115 HWND hwnd_; | |
| 116 }; | |
| 117 | |
| 118 /////////////////////////////////////////////////////////////////////////////// | |
| 119 | |
| 120 } // namespace talk_base | |
| 121 | |
| 122 #endif // WIN32 | |
| 123 | |
| 124 #endif // TALK_BASE_WIN32SOCKETSERVER_H__ | |
| OLD | NEW |