summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorMichael Brown2006-03-23 23:37:05 +0100
committerMichael Brown2006-03-23 23:37:05 +0100
commit7e61f38799366618bc4fa5dfb512c4451098f5ff (patch)
tree8290382db26d6a22f20cd1be95b5e260ffcf24a0 /src/util
parentAdded container_of(). This seems about the best place to put it, since (diff)
downloadipxe-7e61f38799366618bc4fa5dfb512c4451098f5ff.tar.gz
ipxe-7e61f38799366618bc4fa5dfb512c4451098f5ff.tar.xz
ipxe-7e61f38799366618bc4fa5dfb512c4451098f5ff.zip
Moved "hello world" protocol implementation out of prototester.c and into
the first standalong uIP-based protocol module.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/prototester.c104
1 files changed, 1 insertions, 103 deletions
diff --git a/src/util/prototester.c b/src/util/prototester.c
index f520d668..d5cd91fd 100644
--- a/src/util/prototester.c
+++ b/src/util/prototester.c
@@ -12,6 +12,7 @@
#include <assert.h>
#include <gpxe/tcp.h>
+#include <gpxe/hello.h>
typedef int irq_action_t;
@@ -251,109 +252,6 @@ static void hijack_disable ( struct hijack_device *hijack_dev ) {
*
*/
-#include <stddef.h>
-#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
-
-enum hello_state {
- HELLO_SENDING_MESSAGE = 1,
- HELLO_SENDING_ENDL,
-};
-
-struct hello_request {
- struct tcp_connection tcp;
- const char *message;
- enum hello_state state;
- size_t remaining;
- void ( *callback ) ( char *data, size_t len );
- int complete;
-};
-
-static inline struct hello_request *
-tcp_to_hello ( struct tcp_connection *conn ) {
- return container_of ( conn, struct hello_request, tcp );
-}
-
-static void hello_aborted ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- printf ( "Connection aborted\n" );
- hello->complete = 1;
-}
-
-static void hello_timedout ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- printf ( "Connection timed out\n" );
- hello->complete = 1;
-}
-
-static void hello_closed ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- hello->complete = 1;
-}
-
-static void hello_connected ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- printf ( "Connection established\n" );
- hello->state = HELLO_SENDING_MESSAGE;
-}
-
-static void hello_acked ( struct tcp_connection *conn, size_t len ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- hello->message += len;
- hello->remaining -= len;
- if ( hello->remaining == 0 ) {
- switch ( hello->state ) {
- case HELLO_SENDING_MESSAGE:
- hello->state = HELLO_SENDING_ENDL;
- hello->message = "\r\n";
- hello->remaining = 2;
- break;
- case HELLO_SENDING_ENDL:
- /* Nothing to do once we've finished sending
- * the end-of-line indicator.
- */
- break;
- default:
- assert ( 0 );
- }
- }
-}
-
-static void hello_newdata ( struct tcp_connection *conn, void *data,
- size_t len ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- hello->callback ( data, len );
-}
-
-static void hello_senddata ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- tcp_send ( conn, hello->message, hello->remaining );
-}
-
-static struct tcp_operations hello_tcp_operations = {
- .aborted = hello_aborted,
- .timedout = hello_timedout,
- .closed = hello_closed,
- .connected = hello_connected,
- .acked = hello_acked,
- .newdata = hello_newdata,
- .senddata = hello_senddata,
-};
-
-static int hello_connect ( struct hello_request *hello ) {
- hello->tcp.tcp_op = &hello_tcp_operations;
- hello->remaining = strlen ( hello->message );
- return tcp_connect ( &hello->tcp );
-}
-
struct hello_options {
struct sockaddr_in server;
const char *message;