Skip to content

Commit 08d5687

Browse files
committed
udp-socket: only memcpy when required
The buffer is only used when there is a callback, so only perform the memcpy under the same circumstances.
1 parent 7921ddf commit 08d5687

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

os/net/ipv6/udp-socket.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ PROCESS_THREAD(udp_socket_process, ev, data)
167167

168168
/* If we were called because of incoming data, we should call
169169
the reception callback. */
170-
if(uip_newdata()) {
170+
if(uip_newdata() && c->input_callback != NULL) {
171171
/* Copy the data from the uIP data buffer into our own
172172
buffer to avoid the uIP buffer being messed with by the
173173
callee. */
@@ -176,16 +176,14 @@ PROCESS_THREAD(udp_socket_process, ev, data)
176176
/* Call the client process. We use the PROCESS_CONTEXT
177177
mechanism to temporarily switch process context to the
178178
client process. */
179-
if(c->input_callback != NULL) {
180-
PROCESS_CONTEXT_BEGIN(c->p);
181-
c->input_callback(c, c->ptr,
182-
&(UIP_IP_BUF->srcipaddr),
183-
UIP_HTONS(UIP_UDP_BUF->srcport),
184-
&(UIP_IP_BUF->destipaddr),
185-
UIP_HTONS(UIP_UDP_BUF->destport),
186-
buf, uip_datalen());
187-
PROCESS_CONTEXT_END();
188-
}
179+
PROCESS_CONTEXT_BEGIN(c->p);
180+
c->input_callback(c, c->ptr,
181+
&(UIP_IP_BUF->srcipaddr),
182+
UIP_HTONS(UIP_UDP_BUF->srcport),
183+
&(UIP_IP_BUF->destipaddr),
184+
UIP_HTONS(UIP_UDP_BUF->destport),
185+
buf, uip_datalen());
186+
PROCESS_CONTEXT_END();
189187
}
190188
}
191189
}

0 commit comments

Comments
 (0)