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