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