mirror of
https://github.com/ipxe/ipxe
synced 2026-04-04 03:00:20 +03:00
Update ftp.c and hello.c to use the generic async_operations API.
This commit is contained in:
41
src/tests/ftptest.c
Normal file
41
src/tests/ftptest.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <byteswap.h>
|
||||
#include <console.h>
|
||||
#include <vsprintf.h>
|
||||
#include <gpxe/async.h>
|
||||
#include <gpxe/ftp.h>
|
||||
|
||||
static void test_ftp_callback ( char *data, size_t len ) {
|
||||
unsigned int i;
|
||||
char c;
|
||||
|
||||
for ( i = 0 ; i < len ; i++ ) {
|
||||
c = data[i];
|
||||
if ( c == '\r' ) {
|
||||
/* Print nothing */
|
||||
} else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
|
||||
putchar ( c );
|
||||
} else {
|
||||
putchar ( '.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_ftp ( struct in_addr server, const char *filename ) {
|
||||
struct ftp_request ftp;
|
||||
int rc;
|
||||
|
||||
printf ( "FTP fetching %s:%s\n", inet_ntoa ( server ), filename );
|
||||
|
||||
memset ( &ftp, 0, sizeof ( ftp ) );
|
||||
ftp.tcp.sin.sin_addr.s_addr = server.s_addr;
|
||||
ftp.tcp.sin.sin_port = htons ( FTP_PORT );
|
||||
ftp.filename = filename;
|
||||
ftp.callback = test_ftp_callback;
|
||||
|
||||
rc = async_wait ( ftp_get ( &ftp ) );
|
||||
if ( rc ) {
|
||||
printf ( "FTP fetch failed\n" );
|
||||
}
|
||||
}
|
||||
41
src/tests/hellotest.c
Normal file
41
src/tests/hellotest.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <byteswap.h>
|
||||
#include <console.h>
|
||||
#include <vsprintf.h>
|
||||
#include <gpxe/async.h>
|
||||
#include <gpxe/hello.h>
|
||||
|
||||
static void test_hello_callback ( char *data, size_t len ) {
|
||||
unsigned int i;
|
||||
char c;
|
||||
|
||||
for ( i = 0 ; i < len ; i++ ) {
|
||||
c = data[i];
|
||||
if ( c == '\r' ) {
|
||||
/* Print nothing */
|
||||
} else if ( ( c == '\n' ) || ( c >= 32 ) || ( c <= 126 ) ) {
|
||||
putchar ( c );
|
||||
} else {
|
||||
putchar ( '.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_hello ( struct sockaddr_in *server, const char *message ) {
|
||||
struct hello_request hello;
|
||||
int rc;
|
||||
|
||||
printf ( "Saying \"%s\" to %s:%d\n", message,
|
||||
inet_ntoa ( server->sin_addr ), ntohs ( server->sin_port ) );
|
||||
|
||||
memset ( &hello, 0, sizeof ( hello ) );
|
||||
hello.tcp.sin = *server;
|
||||
hello.message = message;
|
||||
hello.callback = test_hello_callback;
|
||||
|
||||
rc = async_wait ( say_hello ( &hello ) );
|
||||
if ( rc ) {
|
||||
printf ( "HELLO fetch failed\n" );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user