⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 port.h

📁 本人收集整理的一份c/c++跨平台网络库
💻 H
📖 第 1 页 / 共 2 页
字号:
  float preference_;  std::vector<Candidate> candidates_;  AddressMap connections_;  enum Lifetime { LT_PRESTART, LT_PRETIMEOUT, LT_POSTTIMEOUT } lifetime_;  bool enable_port_packets_;  // Fills in the username fragment and password.  These will be initially set  // in the constructor to random values.  Subclasses can override, though.  void set_username_fragment(const std::string& username_fragment) {    username_frag_ = username_fragment;  }  void set_password(const std::string& password) { password_ = password; }  // Fills in the local address of the port.  void AddAddress(const talk_base::SocketAddress& address,                   const std::string& protocol, bool final);  // Adds the given connection to the list.  (Deleting removes them.)  void AddConnection(Connection* conn);  // Called when a packet is received from an unknown address that is not  // currently a connection.  If this is an authenticated STUN binding request,  // then we will signal the client.  void OnReadPacket(const char* data, size_t size,                     const talk_base::SocketAddress& addr);  // Constructs a STUN binding request for the given connection and sends it.  void SendBindingRequest(Connection* conn);  // If the given data comprises a complete and correct STUN message then the  // return value is true, otherwise false. If the message username corresponds  // with this port's username fragment, msg will contain the parsed STUN  // message.  Otherwise, the function may send a STUN response internally.  // remote_username contains the remote fragment of the STUN username.  bool GetStunMessage(const char* data, size_t size,                       const talk_base::SocketAddress& addr,                      StunMessage *& msg, std::string& remote_username);  friend class Connection;private:  // Called when one of our connections deletes itself.  void OnConnectionDestroyed(Connection* conn);  // Checks if this port is useless, and hence, should be destroyed.  void CheckTimeout();  static std::string agent_;  static talk_base::ProxyInfo proxy_;};// Represents a communication link between a port on the local client and a// port on the remote client.class Connection : public talk_base::MessageHandler,     public sigslot::has_slots<> {public:  virtual ~Connection();  // The local port where this connection sends and receives packets.  Port* port() { return port_; }  const Port* port() const { return port_; }  // Returns the description of the local port  virtual const Candidate& local_candidate() const;  // Returns the description of the remote port to which we communicate.  const Candidate& remote_candidate() const { return remote_candidate_; }  enum ReadState {    STATE_READABLE     = 0, // we have received pings recently    STATE_READ_TIMEOUT = 1  // we haven't received pings in a while  };  ReadState read_state() const { return read_state_; }  enum WriteState {    STATE_WRITABLE      = 0, // we have received ping responses recently    STATE_WRITE_CONNECT = 1, // we have had a few ping failures    STATE_WRITE_TIMEOUT = 2  // we have had a large number of ping failures  };  WriteState write_state() const { return write_state_; }  // Determines whether the connection has finished connecting.  This can only  // be false for TCP connections.  bool connected() const { return connected_; }  // Estimate of the round-trip time over this connection.  uint32 rtt() const { return rtt_; }  size_t sent_total_bytes();  size_t sent_bytes_second();  size_t recv_total_bytes();  size_t recv_bytes_second();  sigslot::signal1<Connection*> SignalStateChange;  // Sent when the connection has decided that it is no longer of value.  It  // will delete itself immediately after this call.  sigslot::signal1<Connection*> SignalDestroyed;  // The connection can send and receive packets asynchronously.  This matches  // the interface of AsyncPacketSocket, which may use UDP or TCP under the   // covers.  virtual int Send(const void* data, size_t size) = 0;  // Error if Send() returns < 0  virtual int GetError() = 0;  sigslot::signal3<Connection*, const char*, size_t> SignalReadPacket;  // Called when a packet is received on this connection.  void OnReadPacket(const char* data, size_t size);  // Called when a connection is determined to be no longer useful to us.  We  // still keep it around in case the other side wants to use it.  But we can  // safely stop pinging on it and we can allow it to time out if the other  // side stops using it as well.  bool pruned() { return pruned_; }  void Prune();  // Makes the connection go away.  void Destroy();  // Checks that the state of this connection is up-to-date.  The argument is  // the current time, which is compared against various timeouts.  void UpdateState(uint32 now);  // Called when this connection should try checking writability again.  uint32 last_ping_sent() { return last_ping_sent_; }  void Ping(uint32 now);  // Called whenever a valid ping is received on this connection.  This is  // public because the connection intercepts the first ping for us.  void ReceivedPing();  // Debugging description of this connection  std::string ToString() const;  bool reported() { return reported_; }  void set_reported(bool reported) { reported_ = reported;}protected:  Port* port_;  size_t local_candidate_index_;  Candidate remote_candidate_;  ReadState read_state_;  WriteState write_state_;  bool connected_;  bool pruned_;  StunRequestManager requests_;  uint32 rtt_;  uint32 rtt_data_points_;  uint32 last_ping_sent_;     // last time we sent a ping to the other side  uint32 last_ping_received_; // last time we received a ping from the other                               // side  std::vector<uint32> pings_since_last_response_;  size_t recv_total_bytes_;  size_t recv_bytes_second_;  uint32 last_recv_bytes_second_time_;  size_t last_recv_bytes_second_calc_;  size_t sent_total_bytes_;  size_t sent_bytes_second_;  uint32 last_sent_bytes_second_time_;  size_t last_sent_bytes_second_calc_;  // Callbacks from ConnectionRequest  void OnConnectionRequestResponse(StunMessage *response, uint32 rtt);  void OnConnectionRequestErrorResponse(StunMessage *response, uint32 rtt);  // Called back when StunRequestManager has a stun packet to send  void OnSendStunPacket(const void* data, size_t size, StunRequest* req);  // Constructs a new connection to the given remote port.  Connection(Port* port, size_t index, const Candidate& candidate);  // Changes the state and signals if necessary.  void set_read_state(ReadState value);  void set_write_state(WriteState value);  void set_connected(bool value);  // Checks if this connection is useless, and hence, should be destroyed.  void CheckTimeout();  void OnMessage(talk_base::Message *pmsg);  friend class Port;  friend class ConnectionRequest;private:  bool reported_;};// ProxyConnection defers all the interesting work to the portclass ProxyConnection : public Connection {public:  ProxyConnection(Port* port, size_t index, const Candidate& candidate);  virtual int Send(const void* data, size_t size);  virtual int GetError() { return error_; }private:  int error_;};} // namespace cricket#endif // __PORT_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -