asyncsocket.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #ifndef THIRD_PARTY_LIBJINGLE_XMPP_XMPP_ASYNCSOCKET_H_
  11. #define THIRD_PARTY_LIBJINGLE_XMPP_XMPP_ASYNCSOCKET_H_
  12. #include <string>
  13. #include "net/base/host_port_pair.h"
  14. #include "third_party/webrtc/rtc_base/third_party/sigslot/sigslot.h"
  15. namespace jingle_xmpp {
  16. class AsyncSocket {
  17. public:
  18. enum State {
  19. STATE_CLOSED = 0, //!< Socket is not open.
  20. STATE_CLOSING, //!< Socket is closing but can have buffered data
  21. STATE_CONNECTING, //!< In the process of
  22. STATE_OPEN, //!< Socket is connected
  23. STATE_TLS_CONNECTING, //!< Establishing TLS connection
  24. STATE_TLS_OPEN, //!< TLS connected
  25. };
  26. enum Error {
  27. ERROR_NONE = 0, //!< No error
  28. ERROR_WINSOCK, //!< Winsock error
  29. ERROR_DNS, //!< Couldn't resolve host name
  30. ERROR_WRONGSTATE, //!< Call made while socket is in the wrong state
  31. ERROR_SSL, //!< Something went wrong with OpenSSL
  32. };
  33. virtual ~AsyncSocket() {}
  34. virtual State state() = 0;
  35. virtual Error error() = 0;
  36. virtual int GetError() = 0; // winsock error code
  37. virtual bool Connect(const net::HostPortPair& addr) = 0;
  38. virtual bool Read(char * data, size_t len, size_t* len_read) = 0;
  39. virtual bool Write(const char * data, size_t len) = 0;
  40. virtual bool Close() = 0;
  41. // We allow matching any passed domain. This allows us to avoid
  42. // handling the valuable certificates for logins into proxies. If
  43. // both names are passed as empty, we do not require a match.
  44. virtual bool StartTls(const std::string & domainname) = 0;
  45. sigslot::signal0<> SignalConnected;
  46. sigslot::signal0<> SignalSSLConnected;
  47. sigslot::signal0<> SignalClosed;
  48. sigslot::signal0<> SignalRead;
  49. sigslot::signal0<> SignalError;
  50. };
  51. }
  52. #endif // THIRD_PARTY_LIBJINGLE_XMPP_XMPP_ASYNCSOCKET_H_