Change FTP to use a data buffer rather than a callback function.

This commit is contained in:
Michael Brown
2007-01-11 04:51:20 +00:00
parent c0ef730ec4
commit 6918cf9e9e
3 changed files with 47 additions and 25 deletions

View File

@@ -4,9 +4,10 @@
#include <console.h>
#include <vsprintf.h>
#include <gpxe/async.h>
#include <gpxe/buffer.h>
#include <gpxe/ftp.h>
static void test_ftp_callback ( char *data, size_t len ) {
static void print_ftp_response ( char *data, size_t len ) {
unsigned int i;
char c;
@@ -23,18 +24,29 @@ static void test_ftp_callback ( char *data, size_t len ) {
}
void test_ftp ( struct sockaddr_tcpip *server, const char *filename ) {
char data[256];
struct buffer buffer;
struct ftp_request ftp;
int rc;
printf ( "FTP fetching %s\n", filename );
memset ( &buffer, 0, sizeof ( buffer ) );
buffer.addr = virt_to_phys ( data );
buffer.len = sizeof ( data );
memset ( &ftp, 0, sizeof ( ftp ) );
memcpy ( &ftp.server, server, sizeof ( ftp.server ) );
ftp.filename = filename;
ftp.callback = test_ftp_callback;
ftp.buffer = &buffer;
rc = async_wait ( ftp_get ( &ftp ) );
if ( rc ) {
printf ( "FTP fetch failed\n" );
return;
}
printf ( "FTP received %d bytes\n", buffer.fill );
print_ftp_response ( data, buffer.fill );
}