Bladeren bron

Unmaintained example code is probably worse than useless.

tags/v0.9.3
Michael Brown 18 jaren geleden
bovenliggende
commit
c676591cd1
2 gewijzigde bestanden met toevoegingen van 0 en 174 verwijderingen
  1. 0
    52
      src/include/gpxe/hello.h
  2. 0
    122
      src/net/tcp/hello.c

+ 0
- 52
src/include/gpxe/hello.h Bestand weergeven

@@ -1,52 +0,0 @@
1
-#ifndef _GPXE_HELLO_H
2
-#define _GPXE_HELLO_H
3
-
4
-/** @file
5
- *
6
- * "Hello world" TCP protocol
7
- *
8
- */
9
-
10
-#include <stdint.h>
11
-#include <gpxe/tcp.h>
12
-#include <gpxe/async.h>
13
-
14
-enum hello_state {
15
-	HELLO_SENDING_MESSAGE = 1,
16
-	HELLO_SENDING_ENDL,
17
-};
18
-
19
-/**
20
- * A "hello world" request
21
- *
22
- */
23
-struct hello_request {
24
-	/** Server to connect to */
25
-	struct sockaddr_tcpip server;
26
-	/** Message to be transmitted */
27
-	const char *message;
28
-	/** Callback function
29
-	 *
30
-	 * @v data	Received data
31
-	 * @v len	Length of received data
32
-	 *
33
-	 * This function is called for all data received from the
34
-	 * remote server.
35
-	 */
36
-	void ( *callback ) ( char *data, size_t len );
37
-
38
-	/** Current state */
39
-	enum hello_state state;
40
-	/** Amount of message remaining to be transmitted */
41
-	size_t remaining;
42
-
43
-	/** TCP application for this request */
44
-	struct tcp_application tcp;
45
-
46
-	/** Asynchronous operation */
47
-	struct async async;
48
-};
49
-
50
-extern struct async_operation * say_hello ( struct hello_request *hello );
51
-
52
-#endif

+ 0
- 122
src/net/tcp/hello.c Bestand weergeven

@@ -1,122 +0,0 @@
1
-#include <stddef.h>
2
-#include <string.h>
3
-#include <vsprintf.h>
4
-#include <assert.h>
5
-#include <gpxe/async.h>
6
-#include <gpxe/hello.h>
7
-
8
-/** @file
9
- *
10
- * "Hello world" TCP protocol
11
- *
12
- * This file implements a trivial TCP-based protocol.  It connects to
13
- * the server specified in hello_request::server and transmits a
14
- * single message (hello_request::message).  Any data received from
15
- * the server will be passed to the callback function,
16
- * hello_request::callback(), and once the connection has been closed,
17
- * the asynchronous operation associated with the request will be
18
- * marked as complete.
19
- *
20
- * To use this code, do something like:
21
- *
22
- * @code
23
- *
24
- *   static void my_callback ( char *data, size_t len ) {
25
- *     ... process data ...
26
- *   }
27
- *
28
- *   struct hello_request hello = {
29
- *     .server = {
30
- *       ...
31
- *     },
32
- *     .message = "hello world!",
33
- *     .callback = my_callback,
34
- *   };
35
- *
36
- *   rc = async_wait ( say_hello ( &hello ) );
37
- *
38
- * @endcode
39
- *
40
- * It's worth noting that this trivial protocol would be entirely
41
- * adequate to implement a TCP-based version of TFTP; just use "RRQ
42
- * <filename>" as the message.  Now, if only an appropriate server
43
- * existed...
44
- */
45
-
46
-static inline struct hello_request *
47
-tcp_to_hello ( struct tcp_application *app ) {
48
-	return container_of ( app, struct hello_request, tcp );
49
-}
50
-
51
-static void hello_closed ( struct tcp_application *app, int status ) {
52
-	struct hello_request *hello = tcp_to_hello ( app );
53
-
54
-	async_done ( &hello->async, status );
55
-}
56
-
57
-static void hello_connected ( struct tcp_application *app ) {
58
-	struct hello_request *hello = tcp_to_hello ( app );
59
-
60
-	hello->remaining = strlen ( hello->message );
61
-	hello->state = HELLO_SENDING_MESSAGE;
62
-}
63
-
64
-static void hello_acked ( struct tcp_application *app, size_t len ) {
65
-	struct hello_request *hello = tcp_to_hello ( app );
66
-	
67
-	hello->message += len;
68
-	hello->remaining -= len;
69
-	if ( hello->remaining == 0 ) {
70
-		switch ( hello->state ) {
71
-		case HELLO_SENDING_MESSAGE:
72
-			hello->message = "\r\n";
73
-			hello->remaining = 2;
74
-			hello->state = HELLO_SENDING_ENDL;
75
-			break;
76
-		case HELLO_SENDING_ENDL:
77
-			/* Nothing to do once we've finished sending
78
-			 * the end-of-line indicator.
79
-			 */
80
-			break;
81
-		default:
82
-			assert ( 0 );
83
-		}
84
-	}
85
-}
86
-
87
-static void hello_newdata ( struct tcp_application *app, void *data,
88
-			    size_t len ) {
89
-	struct hello_request *hello = tcp_to_hello ( app );
90
-
91
-	hello->callback ( data, len );
92
-}
93
-
94
-static void hello_senddata ( struct tcp_application *app,
95
-			     void *buf __unused, size_t len __unused ) {
96
-	struct hello_request *hello = tcp_to_hello ( app );
97
-
98
-	tcp_send ( app, hello->message, hello->remaining );
99
-}
100
-
101
-static struct tcp_operations hello_tcp_operations = {
102
-	.closed		= hello_closed,
103
-	.connected	= hello_connected,
104
-	.acked		= hello_acked,
105
-	.newdata	= hello_newdata,
106
-	.senddata	= hello_senddata,
107
-};
108
-
109
-/**
110
- * Initiate a "hello world" connection
111
- *
112
- * @v hello	"Hello world" request
113
- */
114
-struct async_operation * say_hello ( struct hello_request *hello ) {
115
-	int rc;
116
-
117
-	hello->tcp.tcp_op = &hello_tcp_operations;
118
-	if ( ( rc = tcp_connect ( &hello->tcp, &hello->server, 0 ) ) != 0 )
119
-		async_done ( &hello->async, rc );
120
-
121
-	return &hello->async;
122
-}

Laden…
Annuleren
Opslaan