OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ | 5 #ifndef JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ |
6 #define JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ | 6 #define JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "net/base/completion_callback.h" |
9 #include "net/socket/socket.h" | 10 #include "net/socket/socket.h" |
10 #include "third_party/libjingle/source/talk/base/socketaddress.h" | 11 #include "third_party/libjingle/source/talk/base/socketaddress.h" |
11 #include "third_party/libjingle/source/talk/base/sigslot.h" | 12 #include "third_party/libjingle/source/talk/base/sigslot.h" |
12 | 13 |
13 class MessageLoop; | 14 class MessageLoop; |
14 | 15 |
15 namespace cricket { | 16 namespace cricket { |
16 class TransportChannel; | 17 class TransportChannel; |
17 } // namespace cricket | 18 } // namespace cricket |
18 | 19 |
19 namespace jingle_glue { | 20 namespace jingle_glue { |
20 | 21 |
21 // TransportChannelSocketAdapter implements net::Socket interface on | 22 // TransportChannelSocketAdapter implements net::Socket interface on |
22 // top of libjingle's TransportChannel. It is used by | 23 // top of libjingle's TransportChannel. It is used by |
23 // JingleChromotocolConnection to provide net::Socket interface for channels. | 24 // JingleChromotocolConnection to provide net::Socket interface for channels. |
24 class TransportChannelSocketAdapter : public net::Socket, | 25 class TransportChannelSocketAdapter : public net::Socket, |
25 public sigslot::has_slots<> { | 26 public sigslot::has_slots<> { |
26 public: | 27 public: |
27 // TransportChannel object is always owned by the corresponding session. | 28 // TransportChannel object is always owned by the corresponding session. |
28 explicit TransportChannelSocketAdapter(cricket::TransportChannel* channel); | 29 explicit TransportChannelSocketAdapter(cricket::TransportChannel* channel); |
29 virtual ~TransportChannelSocketAdapter(); | 30 virtual ~TransportChannelSocketAdapter(); |
30 | 31 |
31 // Closes the stream. |error_code| specifies error code that will | 32 // Closes the stream. |error_code| specifies error code that will |
32 // be returned by Read() and Write() after the stream is closed. | 33 // be returned by Read() and Write() after the stream is closed. |
33 // Must be called before the session and the channel are destroyed. | 34 // Must be called before the session and the channel are destroyed. |
34 void Close(int error_code); | 35 void Close(int error_code); |
35 | 36 |
36 // Socket interface. | 37 // Socket implementation. |
37 virtual int Read(net::IOBuffer* buf, int buf_len, | 38 virtual int Read(net::IOBuffer* buf, int buf_len, |
38 net::OldCompletionCallback* callback) OVERRIDE; | 39 net::OldCompletionCallback* callback) OVERRIDE; |
| 40 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 41 const net::CompletionCallback& callback) OVERRIDE; |
39 virtual int Write(net::IOBuffer* buf, int buf_len, | 42 virtual int Write(net::IOBuffer* buf, int buf_len, |
40 net::OldCompletionCallback* callback) OVERRIDE; | 43 net::OldCompletionCallback* callback) OVERRIDE; |
41 | 44 |
42 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 45 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
43 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 46 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
44 | 47 |
45 private: | 48 private: |
46 void OnNewPacket(cricket::TransportChannel* channel, | 49 void OnNewPacket(cricket::TransportChannel* channel, |
47 const char* data, size_t data_size); | 50 const char* data, size_t data_size); |
48 void OnWritableState(cricket::TransportChannel* channel); | 51 void OnWritableState(cricket::TransportChannel* channel); |
49 void OnChannelDestroyed(cricket::TransportChannel* channel); | 52 void OnChannelDestroyed(cricket::TransportChannel* channel); |
50 | 53 |
51 MessageLoop* message_loop_; | 54 MessageLoop* message_loop_; |
52 | 55 |
53 cricket::TransportChannel* channel_; | 56 cricket::TransportChannel* channel_; |
54 | 57 |
55 net::OldCompletionCallback* read_callback_; // Not owned. | 58 net::OldCompletionCallback* old_read_callback_; // Not owned. |
| 59 net::CompletionCallback read_callback_; |
56 scoped_refptr<net::IOBuffer> read_buffer_; | 60 scoped_refptr<net::IOBuffer> read_buffer_; |
57 int read_buffer_size_; | 61 int read_buffer_size_; |
58 | 62 |
59 net::OldCompletionCallback* write_callback_; // Not owned. | 63 net::OldCompletionCallback* write_callback_; // Not owned. |
60 scoped_refptr<net::IOBuffer> write_buffer_; | 64 scoped_refptr<net::IOBuffer> write_buffer_; |
61 int write_buffer_size_; | 65 int write_buffer_size_; |
62 | 66 |
63 int closed_error_code_; | 67 int closed_error_code_; |
64 | 68 |
65 DISALLOW_COPY_AND_ASSIGN(TransportChannelSocketAdapter); | 69 DISALLOW_COPY_AND_ASSIGN(TransportChannelSocketAdapter); |
66 }; | 70 }; |
67 | 71 |
68 } // namespace jingle_glue | 72 } // namespace jingle_glue |
69 | 73 |
70 #endif // JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ | 74 #endif // JINGLE_GLUE_CHANNEL_SOCKET_ADAPTER_H_ |
OLD | NEW |