summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxav/bwcontroler.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/toxav/bwcontroler.c b/toxav/bwcontroler.c
index a4328045..2530e7fd 100644
--- a/toxav/bwcontroler.c
+++ b/toxav/bwcontroler.c
@@ -138,14 +138,9 @@ void bwc_add_recv(BWControler *bwc, uint32_t bytes)
138 138
139 139
140struct BWCMessage { 140struct BWCMessage {
141 uint8_t core_type; /* Aligner for payload type which is always 196 */
142
143 uint32_t lost; 141 uint32_t lost;
144 uint32_t recv; 142 uint32_t recv;
145} __attribute__((packed)); 143};
146
147/* Check alignment */
148typedef char __fail_if_misaligned [ sizeof(struct BWCMessage) == 9 ? 1 : -1 ];
149 144
150void send_update(BWControler *bwc) 145void send_update(BWControler *bwc)
151{ 146{
@@ -159,15 +154,18 @@ void send_update(BWControler *bwc)
159 154
160 if (bwc->cycle.lost) 155 if (bwc->cycle.lost)
161 { 156 {
162 LOGGER_DEBUG ("%p Sent update", bwc); 157 LOGGER_DEBUG ("%p Sent update rcv: %u lost: %u",
158 bwc, bwc->cycle.recv, bwc->cycle.lost);
163 159
164 struct BWCMessage msg; 160 uint8_t p_msg[sizeof(struct BWCMessage) + 1];
165 msg.core_type = BWC_PACKET_ID; 161 struct BWCMessage* b_msg = (struct BWCMessage*)(p_msg + 1);
166 msg.lost = htonl(bwc->cycle.lost); 162
167 msg.recv = htonl(bwc->cycle.recv); 163 p_msg[0] = BWC_PACKET_ID;
164 b_msg->lost = htonl(bwc->cycle.lost);
165 b_msg->recv = htonl(bwc->cycle.recv);
168 166
169 if (-1 == send_custom_lossy_packet(bwc->m, bwc->friend_number, (uint8_t *)&msg, sizeof(msg))) 167 if (-1 == send_custom_lossy_packet(bwc->m, bwc->friend_number, p_msg, sizeof(p_msg)))
170 LOGGER_WARNING("BWC send failed (len: %d)! std error: %s", sizeof(msg), strerror(errno)); 168 LOGGER_WARNING("BWC send failed (len: %d)! std error: %s", sizeof(p_msg), strerror(errno));
171 } 169 }
172 170
173 bwc->cycle.lsu = current_time_monotonic(); 171 bwc->cycle.lsu = current_time_monotonic();
@@ -199,9 +197,9 @@ int on_update (BWControler *bwc, struct BWCMessage *msg)
199} 197}
200int bwc_handle_data(Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object) 198int bwc_handle_data(Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object)
201{ 199{
202 if (length != sizeof(struct BWCMessage)) 200 if (length - 1 != sizeof(struct BWCMessage))
203 return -1; 201 return -1;
204 202
205 /* NOTE the data is mutable */ 203 /* NOTE the data is mutable */
206 return on_update(object, (struct BWCMessage *) data); 204 return on_update(object, (struct BWCMessage *) (data + 1));
207} 205}