OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_POSIX_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_POSIX_H_ |
| 7 |
| 8 #include "content/common/p2p_sockets.h" |
| 9 |
| 10 #include "base/message_loop.h" |
| 11 #include "content/browser/renderer_host/p2p_socket_host.h" |
| 12 |
| 13 class P2PSocketHostPosix : public P2PSocketHost { |
| 14 public: |
| 15 P2PSocketHostPosix(P2PSocketsHost* host, int routing_id, int id); |
| 16 virtual ~P2PSocketHostPosix(); |
| 17 |
| 18 virtual bool Init(); |
| 19 virtual void Send(P2PSocketAddress socket_address, |
| 20 const std::vector<char>& data); |
| 21 |
| 22 private: |
| 23 enum State { |
| 24 STATE_UNINITIALIZED, |
| 25 STATE_OPEN, |
| 26 STATE_ERROR, |
| 27 }; |
| 28 |
| 29 // MessageLoopForIO::Watcher implementation used to catch read |
| 30 // events from the socket. |
| 31 class ReadWatcher : public MessageLoopForIO::Watcher { |
| 32 public: |
| 33 explicit ReadWatcher(P2PSocketHostPosix* socket) : socket_(socket) { } |
| 34 |
| 35 // MessageLoopForIO::Watcher methods |
| 36 virtual void OnFileCanReadWithoutBlocking(int /* fd */) { |
| 37 socket_->DidCompleteRead(); |
| 38 } |
| 39 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) {} |
| 40 |
| 41 private: |
| 42 P2PSocketHostPosix* socket_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(ReadWatcher); |
| 45 }; |
| 46 |
| 47 void DidCompleteRead(); |
| 48 void OnError(); |
| 49 |
| 50 State state_; |
| 51 int socket_; |
| 52 MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; |
| 53 ReadWatcher read_watcher_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(P2PSocketHostPosix); |
| 56 }; |
| 57 |
| 58 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_POSIX_H_ |
OLD | NEW |