正在显示
2 个修改的文件
包含
29 行增加
和
21 行删除
| @@ -135,27 +135,34 @@ public: | @@ -135,27 +135,34 @@ public: | ||
| 135 | }; | 135 | }; |
| 136 | 136 | ||
| 137 | /** | 137 | /** |
| 138 | -* to statistic the kbps of io. | ||
| 139 | -* itself can be a statistic source, for example, used for SRS bytes stat. | ||
| 140 | -* there are two usage scenarios: | ||
| 141 | -* 1. connections to calc kbps by sample(): | ||
| 142 | -* SrsKbps* kbps = ...; | ||
| 143 | -* kbps->set_io(in, out) | ||
| 144 | -* kbps->sample() | ||
| 145 | -* kbps->get_xxx_kbps(). | ||
| 146 | -* the connections know how many bytes already send/recv. | ||
| 147 | -* 2. server to calc kbps by add_delta(): | ||
| 148 | -* SrsKbps* kbps = ...; | ||
| 149 | -* kbps->set_io(NULL, NULL) | ||
| 150 | -* for each connection in connections: | ||
| 151 | -* IKbpsDelta* delta = connection; // where connection implements IKbpsDelta | ||
| 152 | -* delta->resample() | ||
| 153 | -* kbps->add_delta(delta) | ||
| 154 | -* delta->cleanup() | ||
| 155 | -* kbps->sample() | ||
| 156 | -* kbps->get_xxx_kbps(). | ||
| 157 | -* the server never know how many bytes already send/recv, for the connection maybe closed. | ||
| 158 | -*/ | 138 | + * to statistic the kbps of io. |
| 139 | + * itself can be a statistic source, for example, used for SRS bytes stat. | ||
| 140 | + * there are some usage scenarios: | ||
| 141 | + * 1. connections to calc kbps by sample(): | ||
| 142 | + * SrsKbps* kbps = ...; | ||
| 143 | + * kbps->set_io(in, out) | ||
| 144 | + * kbps->sample() | ||
| 145 | + * kbps->get_xxx_kbps(). | ||
| 146 | + * the connections know how many bytes already send/recv. | ||
| 147 | + * 2. server to calc kbps by add_delta(): | ||
| 148 | + * SrsKbps* kbps = ...; | ||
| 149 | + * kbps->set_io(NULL, NULL) | ||
| 150 | + * for each connection in connections: | ||
| 151 | + * IKbpsDelta* delta = connection; // where connection implements IKbpsDelta | ||
| 152 | + * delta->resample() | ||
| 153 | + * kbps->add_delta(delta) | ||
| 154 | + * delta->cleanup() | ||
| 155 | + * kbps->sample() | ||
| 156 | + * kbps->get_xxx_kbps(). | ||
| 157 | + * 3. kbps used as IKbpsDelta, to provides delta bytes: | ||
| 158 | + * SrsKbps* kbps = ...; | ||
| 159 | + * kbps->set_io(in, out); | ||
| 160 | + * IKbpsDelta* delta = (IKbpsDelta*)kbps; | ||
| 161 | + * delta->resample(); | ||
| 162 | + * printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta()); | ||
| 163 | + * delta->cleanup(); | ||
| 164 | + * the server never know how many bytes already send/recv, for the connection maybe closed. | ||
| 165 | + */ | ||
| 159 | class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta | 166 | class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta |
| 160 | { | 167 | { |
| 161 | private: | 168 | private: |
| @@ -167,6 +167,7 @@ public: | @@ -167,6 +167,7 @@ public: | ||
| 167 | * sample the kbps, add delta bytes of conn. | 167 | * sample the kbps, add delta bytes of conn. |
| 168 | * use kbps_sample() to get all result of kbps stat. | 168 | * use kbps_sample() to get all result of kbps stat. |
| 169 | */ | 169 | */ |
| 170 | + // TODO: FIXME: the add delta must use IKbpsDelta interface instead. | ||
| 170 | virtual void kbps_add_delta(SrsConnection* conn); | 171 | virtual void kbps_add_delta(SrsConnection* conn); |
| 171 | /** | 172 | /** |
| 172 | * calc the result for all kbps. | 173 | * calc the result for all kbps. |
-
请 注册 或 登录 后发表评论