From 3a660f9b2580432477e0804e7d94fc01854c481a Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 19 Jun 2006 15:46:58 +0000 Subject: Update ftp.c and hello.c to use the generic async_operations API. --- src/tests/ftptest.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/tests/hellotest.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 src/tests/ftptest.c create mode 100644 src/tests/hellotest.c (limited to 'src/tests') diff --git a/src/tests/ftptest.c b/src/tests/ftptest.c new file mode 100644 index 000000000..f8208de73 --- /dev/null +++ b/src/tests/ftptest.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include + +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" ); + } +} diff --git a/src/tests/hellotest.c b/src/tests/hellotest.c new file mode 100644 index 000000000..e38856ee8 --- /dev/null +++ b/src/tests/hellotest.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +#include + +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" ); + } +} -- cgit v1.2.3-55-g7522