static THD_FUNCTION(rcvThd, arg) { comm_interface_t * comm_interface = (comm_interface_t*) arg; comm_handler_t * comm_handler = comm_interface->comm_handler; err_t err = ERR_OK; /* * Run, as long as connection was not closed or other error occured. */ while(err == ERR_OK) { /* * Read the data from the port, blocking if nothing yet there. * Continue in case of closed connection (error). */ struct netbuf * head = NULL; struct netbuf * cur; while ( /* * Connection is open */ (err = netconn_recv(comm_interface->conn, &cur))== ERR_OK ) { /* * Increment total received length. Netbufs only store * a length of up to 16 bit. */ uint32_t len = (uint32_t)cur->p->len; comm_handler->rcvd_len += len; if(head == NULL) { /* * Directly reference the first netbuf to "head" */ head = cur; comm_handler->nb = head; } else { /* * Chain the new netbuf to the previous netbuf. cur is deallocated * in this operation. */ netbuf_chain(head, cur); } chMsgSend(comm_handler->evl_thread, (msg_t)MSG_OK); } }