正在显示
2 个修改的文件
包含
12 行增加
和
21 行删除
| @@ -755,17 +755,10 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs) | @@ -755,17 +755,10 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs) | ||
| 755 | 755 | ||
| 756 | // always write the header event payload is empty. | 756 | // always write the header event payload is empty. |
| 757 | while (p < pend) { | 757 | while (p < pend) { |
| 758 | - // always has header | ||
| 759 | - int nbh = 0; | ||
| 760 | - char* header = NULL; | ||
| 761 | - generate_chunk_header(c0c3_cache, &msg->header, p == msg->payload, &nbh, &header); | ||
| 762 | - srs_assert(nbh > 0); | 758 | + // header use iov[0]. |
| 759 | + generate_chunk_header(c0c3_cache, &msg->header, p == msg->payload, iov); | ||
| 763 | 760 | ||
| 764 | - // header iov | ||
| 765 | - iov[0].iov_base = header; | ||
| 766 | - iov[0].iov_len = nbh; | ||
| 767 | - | ||
| 768 | - // payload iov | 761 | + // payload use iov[1]. |
| 769 | int payload_size = pend - p; | 762 | int payload_size = pend - p; |
| 770 | if (payload_size > out_chunk_size) { | 763 | if (payload_size > out_chunk_size) { |
| 771 | payload_size = out_chunk_size; | 764 | payload_size = out_chunk_size; |
| @@ -788,14 +781,14 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs) | @@ -788,14 +781,14 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs) | ||
| 788 | int realloc_size = sizeof(iovec) * nb_out_iovs; | 781 | int realloc_size = sizeof(iovec) * nb_out_iovs; |
| 789 | out_iovs = (iovec*)realloc(out_iovs, realloc_size); | 782 | out_iovs = (iovec*)realloc(out_iovs, realloc_size); |
| 790 | } | 783 | } |
| 784 | + | ||
| 785 | + // to next c0c3 header cache | ||
| 786 | + c0c3_cache_index += iov[0].iov_len; | ||
| 787 | + c0c3_cache = out_c0c3_caches + c0c3_cache_index; | ||
| 791 | 788 | ||
| 792 | // to next pair of iovs | 789 | // to next pair of iovs |
| 793 | iov_index += 2; | 790 | iov_index += 2; |
| 794 | iov = out_iovs + iov_index; | 791 | iov = out_iovs + iov_index; |
| 795 | - | ||
| 796 | - // to next c0c3 header cache | ||
| 797 | - c0c3_cache_index += nbh; | ||
| 798 | - c0c3_cache = out_c0c3_caches + c0c3_cache_index; | ||
| 799 | 792 | ||
| 800 | // the cache header should never be realloc again, | 793 | // the cache header should never be realloc again, |
| 801 | // for the ptr is set to iovs, so we just warn user to set larger | 794 | // for the ptr is set to iovs, so we just warn user to set larger |
| @@ -905,7 +898,7 @@ int SrsProtocol::do_send_and_free_packet(SrsPacket* packet, int stream_id) | @@ -905,7 +898,7 @@ int SrsProtocol::do_send_and_free_packet(SrsPacket* packet, int stream_id) | ||
| 905 | return ret; | 898 | return ret; |
| 906 | } | 899 | } |
| 907 | 900 | ||
| 908 | -void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool c0, int* pnbh, char** ph) | 901 | +void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool c0, iovec* iov) |
| 909 | { | 902 | { |
| 910 | // to directly set the field. | 903 | // to directly set the field. |
| 911 | char* pp = NULL; | 904 | char* pp = NULL; |
| @@ -982,8 +975,8 @@ void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool | @@ -982,8 +975,8 @@ void SrsProtocol::generate_chunk_header(char* cache, SrsMessageHeader* mh, bool | ||
| 982 | } | 975 | } |
| 983 | 976 | ||
| 984 | // always has header | 977 | // always has header |
| 985 | - *pnbh = p - cache; | ||
| 986 | - *ph = cache; | 978 | + iov->iov_base = cache; |
| 979 | + iov->iov_len = p - cache; | ||
| 987 | } | 980 | } |
| 988 | 981 | ||
| 989 | int SrsProtocol::do_decode_message(SrsMessageHeader& header, SrsStream* stream, SrsPacket** ppacket) | 982 | int SrsProtocol::do_decode_message(SrsMessageHeader& header, SrsStream* stream, SrsPacket** ppacket) |
| @@ -496,11 +496,9 @@ private: | @@ -496,11 +496,9 @@ private: | ||
| 496 | * generate the chunk header for msg. | 496 | * generate the chunk header for msg. |
| 497 | * @param mh, the header of msg to send. | 497 | * @param mh, the header of msg to send. |
| 498 | * @param c0, whether the first chunk, the c0 chunk. | 498 | * @param c0, whether the first chunk, the c0 chunk. |
| 499 | - * @param pnbh, output the size of header. | ||
| 500 | - * @param ph, output the header cache. | ||
| 501 | - * user should never free it, it's cached header. | 499 | + * @param iov, output the header and size to iovec. |
| 502 | */ | 500 | */ |
| 503 | - virtual void generate_chunk_header(char* cache, SrsMessageHeader* mh, bool c0, int* pnbh, char** ph); | 501 | + virtual void generate_chunk_header(char* cache, SrsMessageHeader* mh, bool c0, iovec* iov); |
| 504 | /** | 502 | /** |
| 505 | * imp for decode_message | 503 | * imp for decode_message |
| 506 | */ | 504 | */ |
-
请 注册 或 登录 后发表评论