henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_LIBJINGLE_XMPP_ASYNCSOCKET_H_ |
| 12 | #define WEBRTC_LIBJINGLE_XMPP_ASYNCSOCKET_H_ |
| 13 | |
| 14 | #include <string> |
| 15 | |
| 16 | #include "webrtc/base/sigslot.h" |
| 17 | |
| 18 | namespace rtc { |
| 19 | class SocketAddress; |
| 20 | } |
| 21 | |
| 22 | namespace buzz { |
| 23 | |
| 24 | class AsyncSocket { |
| 25 | public: |
| 26 | enum State { |
| 27 | STATE_CLOSED = 0, //!< Socket is not open. |
| 28 | STATE_CLOSING, //!< Socket is closing but can have buffered data |
| 29 | STATE_CONNECTING, //!< In the process of |
| 30 | STATE_OPEN, //!< Socket is connected |
| 31 | #if defined(FEATURE_ENABLE_SSL) |
| 32 | STATE_TLS_CONNECTING, //!< Establishing TLS connection |
| 33 | STATE_TLS_OPEN, //!< TLS connected |
| 34 | #endif |
| 35 | }; |
| 36 | |
| 37 | enum Error { |
| 38 | ERROR_NONE = 0, //!< No error |
| 39 | ERROR_WINSOCK, //!< Winsock error |
| 40 | ERROR_DNS, //!< Couldn't resolve host name |
| 41 | ERROR_WRONGSTATE, //!< Call made while socket is in the wrong state |
| 42 | #if defined(FEATURE_ENABLE_SSL) |
| 43 | ERROR_SSL, //!< Something went wrong with OpenSSL |
| 44 | #endif |
| 45 | }; |
| 46 | |
| 47 | virtual ~AsyncSocket() {} |
| 48 | virtual State state() = 0; |
| 49 | virtual Error error() = 0; |
| 50 | virtual int GetError() = 0; // winsock error code |
| 51 | |
| 52 | virtual bool Connect(const rtc::SocketAddress& addr) = 0; |
| 53 | virtual bool Read(char * data, size_t len, size_t* len_read) = 0; |
| 54 | virtual bool Write(const char * data, size_t len) = 0; |
| 55 | virtual bool Close() = 0; |
| 56 | #if defined(FEATURE_ENABLE_SSL) |
| 57 | // We allow matching any passed domain. This allows us to avoid |
| 58 | // handling the valuable certificates for logins into proxies. If |
| 59 | // both names are passed as empty, we do not require a match. |
| 60 | virtual bool StartTls(const std::string & domainname) = 0; |
| 61 | #endif |
| 62 | |
| 63 | sigslot::signal0<> SignalConnected; |
| 64 | sigslot::signal0<> SignalSSLConnected; |
| 65 | sigslot::signal0<> SignalClosed; |
| 66 | sigslot::signal0<> SignalRead; |
| 67 | sigslot::signal0<> SignalError; |
| 68 | }; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | #endif // WEBRTC_LIBJINGLE_XMPP_ASYNCSOCKET_H_ |