27
27
* Make sure that the following mutexes are locked before calling this function:
28
28
* - ztu->mutex_tx
29
29
*/
30
- void __unsafe_z_prepare_wbuf (_z_wbuf_t * buf , _Bool is_streamed ) {
30
+ void __unsafe_z_prepare_wbuf (_z_wbuf_t * buf , uint8_t link_flow_capability ) {
31
31
_z_wbuf_reset (buf );
32
32
33
- if (is_streamed == true) {
34
- for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
35
- _z_wbuf_put (buf , 0 , i );
36
- }
37
- _z_wbuf_set_wpos (buf , _Z_MSG_LEN_ENC_SIZE );
33
+ switch (link_flow_capability ) {
34
+ // Stream capable links
35
+ case Z_LINK_CAP_FLOW_STREAM :
36
+ for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
37
+ _z_wbuf_put (buf , 0 , i );
38
+ }
39
+ _z_wbuf_set_wpos (buf , _Z_MSG_LEN_ENC_SIZE );
40
+ break ;
41
+ // Datagram capable links
42
+ case Z_LINK_CAP_FLOW_DATAGRAM :
43
+ default :
44
+ break ;
38
45
}
39
46
}
40
47
@@ -43,12 +50,20 @@ void __unsafe_z_prepare_wbuf(_z_wbuf_t *buf, _Bool is_streamed) {
43
50
* Make sure that the following mutexes are locked before calling this function:
44
51
* - ztu->mutex_tx
45
52
*/
46
- void __unsafe_z_finalize_wbuf (_z_wbuf_t * buf , _Bool is_streamed ) {
47
- if (is_streamed == true) {
48
- size_t len = _z_wbuf_len (buf ) - _Z_MSG_LEN_ENC_SIZE ;
49
- for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
50
- _z_wbuf_put (buf , (uint8_t )((len >> (uint8_t )8 * i ) & (uint8_t )0xFF ), i );
53
+ void __unsafe_z_finalize_wbuf (_z_wbuf_t * buf , uint8_t link_flow_capability ) {
54
+ switch (link_flow_capability ) {
55
+ // Stream capable links
56
+ case Z_LINK_CAP_FLOW_STREAM : {
57
+ size_t len = _z_wbuf_len (buf ) - _Z_MSG_LEN_ENC_SIZE ;
58
+ for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
59
+ _z_wbuf_put (buf , (uint8_t )((len >> (uint8_t )8 * i ) & (uint8_t )0xFF ), i );
60
+ }
61
+ break ;
51
62
}
63
+ // Datagram capable links
64
+ case Z_LINK_CAP_FLOW_DATAGRAM :
65
+ default :
66
+ break ;
52
67
}
53
68
}
54
69
@@ -74,24 +89,38 @@ int8_t _z_link_send_t_msg(const _z_link_t *zl, const _z_transport_message_t *t_m
74
89
// Create and prepare the buffer to serialize the message on
75
90
uint16_t mtu = (zl -> _mtu < Z_BATCH_UNICAST_SIZE ) ? zl -> _mtu : Z_BATCH_UNICAST_SIZE ;
76
91
_z_wbuf_t wbf = _z_wbuf_make (mtu , false);
77
- if (_Z_LINK_IS_STREAMED (zl -> _capabilities ) == true) {
78
- for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
79
- _z_wbuf_put (& wbf , 0 , i );
80
- }
81
- _z_wbuf_set_wpos (& wbf , _Z_MSG_LEN_ENC_SIZE );
82
- }
83
92
93
+ switch (zl -> _cap ._flow ) {
94
+ case Z_LINK_CAP_FLOW_STREAM :
95
+ for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
96
+ _z_wbuf_put (& wbf , 0 , i );
97
+ }
98
+ _z_wbuf_set_wpos (& wbf , _Z_MSG_LEN_ENC_SIZE );
99
+ break ;
100
+ case Z_LINK_CAP_FLOW_DATAGRAM :
101
+ break ;
102
+ default :
103
+ ret = _Z_ERR_GENERIC ;
104
+ break ;
105
+ }
84
106
// Encode the session message
85
107
ret = _z_transport_message_encode (& wbf , t_msg );
86
108
if (ret == _Z_RES_OK ) {
87
- // Write the message length in the reserved space if needed
88
- if (_Z_LINK_IS_STREAMED (zl -> _capabilities ) == true) {
89
- size_t len = _z_wbuf_len (& wbf ) - _Z_MSG_LEN_ENC_SIZE ;
90
- for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
91
- _z_wbuf_put (& wbf , (uint8_t )((len >> (uint8_t )8 * i ) & (uint8_t )0xFF ), i );
109
+ switch (zl -> _cap ._flow ) {
110
+ case Z_LINK_CAP_FLOW_STREAM : {
111
+ // Write the message length in the reserved space if needed
112
+ size_t len = _z_wbuf_len (& wbf ) - _Z_MSG_LEN_ENC_SIZE ;
113
+ for (uint8_t i = 0 ; i < _Z_MSG_LEN_ENC_SIZE ; i ++ ) {
114
+ _z_wbuf_put (& wbf , (uint8_t )((len >> (uint8_t )8 * i ) & (uint8_t )0xFF ), i );
115
+ }
116
+ break ;
92
117
}
118
+ case Z_LINK_CAP_FLOW_DATAGRAM :
119
+ break ;
120
+ default :
121
+ ret = _Z_ERR_GENERIC ;
122
+ break ;
93
123
}
94
-
95
124
// Send the wbuf on the socket
96
125
ret = _z_link_send_wbuf (zl , & wbf );
97
126
}
0 commit comments