Hello everybody, i'm using lwip 1.3.0 port to AVR for using in the board EVK1100.
Iḿ seeing a example code of tftp, and i don't understand this part, exactly the part to call the function lwip_select. Can anybody help me?
and where is the documentation for all API and struct, i only have these kind of documents -LwIP-STABLE-1.3.0.pdf // there is all function but a lot of don have any explanation -lwip.pdf // the old explanation of lwip, with a little function API
-Rx_flow.pdf // flow but exactly there is part that dont understand too
ok = pdTRUE;
closed = pdFALSE; block = 0; while (ok) { // Send ACK telling client he can send data reply->th_opcode = htons(ACK); reply->th_block = htons(block++); // postincrement
for (tries = 0; tries < TFTP_RETRIES_MAX; tries++) { sendto(s, reply, 4, 0, (struct sockaddr *)from_addr, from_len); repeat_select: timeout.tv_sec = TFTP_TIMEOUT_PERIOD;
timeout.tv_usec = 0; FD_ZERO(&fds); FD_SET(s, &fds); vParTestToggleLED( TFTP_LED ); if (lwip_select(s+1, &fds, 0, 0, &timeout) <= 0) {
if (++total_timeouts > TFTP_TIMEOUT_MAX) { tftpd_send_error(s,reply,TFTP_EBADOP,from_addr, from_len); ok = pdFALSE; break; }
continue; // retry the send, using up one retry. } vParTestToggleLED( TFTP_LED ); // Some data has arrived data_len = sizeof(data_in); client_len = sizeof(client_addr);
if ((data_len = recvfrom(s, data_in, data_len, 0, (struct sockaddr *)&client_addr, &client_len)) < 0) { // What happened? No data here! continue; // retry the send, using up one retry.
} if (ntohs(response->th_opcode) == DATA && ntohs(response->th_block) < block) { // Then it is repeat DATA with an old block; listen again,
// but do not repeat sending the current ack, and do not // use up a retry count. (we do re-send the ack if // subsequently we time out) goto repeat_select;
} if (ntohs(response->th_opcode) == DATA && ntohs(response->th_block) == block) { // Good data - write to file len = tftpd_write_data_file(fd, response->th_data, data_len-4);
if (len < (data_len-4)) { // File is "full" tftpd_send_error(s,reply,TFTP_ENOSPACE, from_addr, from_len);
ok = pdFALSE; // Give up break; // out of the retries loop } if (data_len < (SEGSIZE+4)) { // End of file closed = pdTRUE;
ok = pdFALSE; vParTestSetLED( 0 , 0 );
if (tftpd_close_data_file(fd) == -1) { tftpd_send_error(s,reply,TFTP_EACCESS, from_addr, from_len);
break; // out of the retries loop } // Exception to the loop structure: we must ACK the last // packet, the one that implied EOF:
reply->th_opcode = htons(ACK); reply->th_block = htons(block++); // postincrement sendto(s, reply, 4, 0, (struct sockaddr *)from_addr, from_len);
break; // out of the retries loop } // Happy! Break out of the retries loop. break; } } // End of the retries loop.
if (TFTP_RETRIES_MAX <= tries) { tftpd_send_error(s,reply,TFTP_EBADOP,from_addr, from_len); ok = pdFALSE; } } close(s); if (!closed) { tftpd_close_data_file(fd);
} }