Browse Source

Add seek()

Dehyphenate "data-transfer".
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
280160139d
4 changed files with 137 additions and 38 deletions
  1. 4
    4
      src/core/open.c
  2. 75
    18
      src/core/xfer.c
  3. 2
    2
      src/include/gpxe/open.h
  4. 56
    14
      src/include/gpxe/xfer.h

+ 4
- 4
src/core/open.c View File

@@ -45,7 +45,7 @@ static struct socket_opener socket_openers_end[0]
45 45
 /**
46 46
  * Open URI
47 47
  *
48
- * @v xfer		Data-transfer interface
48
+ * @v xfer		Data transfer interface
49 49
  * @v uri_string	URI string (e.g. "http://etherboot.org/kernel")
50 50
  * @ret rc		Return status code
51 51
  */
@@ -74,7 +74,7 @@ int open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
74 74
 /**
75 75
  * Open socket
76 76
  *
77
- * @v xfer		Data-transfer interface
77
+ * @v xfer		Data transfer interface
78 78
  * @v domain		Communication domain (e.g. PF_INET)
79 79
  * @v type		Communication semantics (e.g. SOCK_STREAM)
80 80
  */
@@ -101,7 +101,7 @@ int open_socket ( struct xfer_interface *xfer,
101 101
 /**
102 102
  * Open location
103 103
  *
104
- * @v xfer		Data-transfer interface
104
+ * @v xfer		Data transfer interface
105 105
  * @v type		Location type
106 106
  * @v args		Remaining arguments depend upon location type
107 107
  * @ret rc		Return status code
@@ -128,7 +128,7 @@ int vopen ( struct xfer_interface *xfer, int type, va_list args ) {
128 128
 /**
129 129
  * Open location
130 130
  *
131
- * @v xfer		Data-transfer interface
131
+ * @v xfer		Data transfer interface
132 132
  * @v type		Location type
133 133
  * @v ...		Remaining arguments depend upon location type
134 134
  * @ret rc		Return status code

+ 75
- 18
src/core/xfer.c View File

@@ -26,10 +26,36 @@
26 26
  *
27 27
  */
28 28
 
29
+/**
30
+ * Close data transfer interface
31
+ *
32
+ * @v xfer		Data transfer interface
33
+ * @v rc		Reason for close
34
+ */
35
+void close ( struct xfer_interface *xfer, int rc ) {
36
+	struct xfer_interface *dest = xfer_dest ( xfer );
37
+
38
+	dest->op->close ( dest, rc );
39
+	xfer_unplug ( xfer );
40
+}
41
+
42
+/**
43
+ * Seek to position
44
+ *
45
+ * @v xfer		Data transfer interface
46
+ * @v pos		New position
47
+ * @ret rc		Return status code
48
+ */
49
+int seek ( struct xfer_interface *xfer, size_t pos ) {
50
+	struct xfer_interface *dest = xfer_dest ( xfer );
51
+
52
+	return dest->op->seek ( dest, pos );
53
+}
54
+
29 55
 /**
30 56
  * Send redirection event
31 57
  *
32
- * @v xfer		Data-transfer interface
58
+ * @v xfer		Data transfer interface
33 59
  * @v type		New location type
34 60
  * @v args		Remaining arguments depend upon location type
35 61
  * @ret rc		Return status code
@@ -43,7 +69,7 @@ int vredirect ( struct xfer_interface *xfer, int type, va_list args ) {
43 69
 /**
44 70
  * Send redirection event
45 71
  *
46
- * @v xfer		Data-transfer interface
72
+ * @v xfer		Data transfer interface
47 73
  * @v type		New location type
48 74
  * @v ...		Remaining arguments depend upon location type
49 75
  * @ret rc		Return status code
@@ -61,7 +87,7 @@ int redirect ( struct xfer_interface *xfer, int type, ... ) {
61 87
 /**
62 88
  * Deliver datagram
63 89
  *
64
- * @v xfer		Data-transfer interface
90
+ * @v xfer		Data transfer interface
65 91
  * @v iobuf		Datagram I/O buffer
66 92
  * @ret rc		Return status code
67 93
  */
@@ -74,7 +100,7 @@ int deliver ( struct xfer_interface *xfer, struct io_buffer *iobuf ) {
74 100
 /**
75 101
  * Deliver datagram as raw data
76 102
  *
77
- * @v xfer		Data-transfer interface
103
+ * @v xfer		Data transfer interface
78 104
  * @v iobuf		Datagram I/O buffer
79 105
  * @ret rc		Return status code
80 106
  */
@@ -93,10 +119,44 @@ int deliver_raw ( struct xfer_interface *xfer, const void *data, size_t len ) {
93 119
  *
94 120
  */
95 121
 
122
+/**
123
+ * Ignore close()
124
+ *
125
+ * @v xfer		Data transfer interface
126
+ * @v rc		Reason for close
127
+ */
128
+void ignore_close ( struct xfer_interface *xfer __unused, int rc __unused ) {
129
+	/* Nothing to do */
130
+}
131
+
132
+/**
133
+ * Ignore vredirect()
134
+ *
135
+ * @v xfer		Data transfer interface
136
+ * @v type		New location type
137
+ * @v args		Remaining arguments depend upon location type
138
+ * @ret rc		Return status code
139
+ */
140
+int ignore_vredirect ( struct xfer_interface *xfer __unused,
141
+		       int type __unused, va_list args __unused ) {
142
+	return 0;
143
+}
144
+
145
+/**
146
+ * Ignore seek()
147
+ *
148
+ * @v xfer		Data transfer interface
149
+ * @v pos		New position
150
+ * @ret rc		Return status code
151
+ */
152
+int ignore_seek ( struct xfer_interface *xfer __unused, size_t pos __unused ) {
153
+	return 0;
154
+}
155
+
96 156
 /**
97 157
  * Deliver datagram as raw data
98 158
  *
99
- * @v xfer		Data-transfer interface
159
+ * @v xfer		Data transfer interface
100 160
  * @v iobuf		Datagram I/O buffer
101 161
  * @ret rc		Return status code
102 162
  *
@@ -115,7 +175,7 @@ int deliver_as_raw ( struct xfer_interface *xfer,
115 175
 /**
116 176
  * Deliver datagram as I/O buffer
117 177
  *
118
- * @v xfer		Data-transfer interface
178
+ * @v xfer		Data transfer interface
119 179
  * @v data		Data buffer
120 180
  * @v len		Length of data buffer
121 181
  * @ret rc		Return status code
@@ -135,32 +195,29 @@ int deliver_as_iobuf ( struct xfer_interface *xfer,
135 195
 	return xfer->op->deliver ( xfer, iobuf );
136 196
 }
137 197
 
138
-/****************************************************************************
139
- *
140
- * Null data transfer interface
141
- *
142
- */
143
-
144 198
 /**
145
- * Null deliver datagram as raw data
199
+ * Ignore datagram as raw data
146 200
  *
147
- * @v xfer		Data-transfer interface
201
+ * @v xfer		Data transfer interface
148 202
  * @v data		Data buffer
149 203
  * @v len		Length of data buffer
150 204
  * @ret rc		Return status code
151 205
  */
152
-static int null_deliver_raw ( struct xfer_interface *xfer,
153
-			      const void *data __unused, size_t len ) {
206
+int ignore_deliver_raw ( struct xfer_interface *xfer,
207
+			 const void *data __unused, size_t len ) {
154 208
 	DBGC ( xfer, "XFER %p %zd bytes delivered %s\n", xfer, len,
155 209
 	       ( ( xfer == &null_xfer ) ?
156 210
 		 "before connection" : "after termination" ) );
157
-	return -EPIPE;
211
+	return 0;
158 212
 }
159 213
 
160 214
 /** Null data transfer interface operations */
161 215
 struct xfer_interface_operations null_xfer_ops = {
216
+	.close		= ignore_close,
217
+	.vredirect	= ignore_vredirect,
218
+	.seek		= ignore_seek,
162 219
 	.deliver	= deliver_as_raw,
163
-	.deliver_raw	= null_deliver_raw,
220
+	.deliver_raw	= ignore_deliver_raw,
164 221
 };
165 222
 
166 223
 /**

+ 2
- 2
src/include/gpxe/open.h View File

@@ -41,7 +41,7 @@ struct uri_opener {
41 41
 	const char *scheme;
42 42
 	/** Open URI
43 43
 	 *
44
-	 * @v xfer		Data-transfer interface
44
+	 * @v xfer		Data transfer interface
45 45
 	 * @v uri		URI
46 46
 	 * @ret rc		Return status code
47 47
 	 *
@@ -62,7 +62,7 @@ struct socket_opener {
62 62
 	int type;
63 63
 	/** Open socket
64 64
 	 *
65
-	 * @v xfer		Data-transfer interface
65
+	 * @v xfer		Data transfer interface
66 66
 	 * @v sa		Socket address
67 67
 	 * @ret rc		Return status code
68 68
 	 */

+ 56
- 14
src/include/gpxe/xfer.h View File

@@ -32,22 +32,29 @@ struct xfer_interface_operations {
32 32
 
33 33
 	/** Close interface
34 34
 	 *
35
-	 * @v xfer		Data-transfer interface
35
+	 * @v xfer		Data transfer interface
36 36
 	 * @v rc		Reason for close
37 37
 	 */
38 38
 	void ( * close ) ( struct xfer_interface *xfer, int rc );
39 39
 	/** Redirect to new location
40 40
 	 *
41
-	 * @v xfer		Data-transfer interface
41
+	 * @v xfer		Data transfer interface
42 42
 	 * @v type		New location type
43 43
 	 * @v args		Remaining arguments depend upon location type
44 44
 	 * @ret rc		Return status code
45 45
 	 */
46 46
 	int ( * vredirect ) ( struct xfer_interface *xfer, int type,
47 47
 			      va_list args );
48
+	/** Seek to position
49
+	 *
50
+	 * @v xfer		Data transfer interface
51
+	 * @v pos		New position
52
+	 * @ret rc		Return status code
53
+	 */
54
+	int ( * seek ) ( struct xfer_interface *xfer, size_t pos );
48 55
 	/** Deliver datagram
49 56
 	 *
50
-	 * @v xfer		Data-transfer interface
57
+	 * @v xfer		Data transfer interface
51 58
 	 * @v iobuf		Datagram I/O buffer
52 59
 	 * @ret rc		Return status code
53 60
 	 *
@@ -59,7 +66,7 @@ struct xfer_interface_operations {
59 66
 			    struct io_buffer *iobuf );
60 67
 	/** Deliver datagram as raw data
61 68
 	 *
62
-	 * @v xfer		Data-transfer interface
69
+	 * @v xfer		Data transfer interface
63 70
 	 * @v data		Data buffer
64 71
 	 * @v len		Length of data buffer
65 72
 	 * @ret rc		Return status code
@@ -83,32 +90,67 @@ struct xfer_interface {
83 90
 extern struct xfer_interface null_xfer;
84 91
 extern struct xfer_interface_operations null_xfer_ops;
85 92
 
93
+extern void close ( struct xfer_interface *xfer, int rc );
94
+extern int seek ( struct xfer_interface *xfer, size_t pos );
86 95
 extern int vredirect ( struct xfer_interface *xfer, int type, va_list args );
87 96
 extern int redirect ( struct xfer_interface *xfer, int type, ... );
88 97
 extern int deliver ( struct xfer_interface *xfer, struct io_buffer *iobuf );
89 98
 extern int deliver_raw ( struct xfer_interface *xfer,
90 99
 			 const void *data, size_t len );
91 100
 
101
+extern void ignore_close ( struct xfer_interface *xfer, int rc );
102
+extern int ignore_vredirect ( struct xfer_interface *xfer,
103
+			      int type, va_list args );
104
+extern int ignore_seek ( struct xfer_interface *xfer, size_t pos );
92 105
 extern int deliver_as_raw ( struct xfer_interface *xfer,
93 106
 			    struct io_buffer *iobuf );
94 107
 extern int deliver_as_iobuf ( struct xfer_interface *xfer,
95 108
 			      const void *data, size_t len );
109
+extern int ignore_deliver_raw ( struct xfer_interface *xfer,
110
+				const void *data __unused, size_t len );
111
+
112
+/**
113
+ * Initialise a data transfer interface
114
+ *
115
+ * @v xfer		Data transfer interface
116
+ * @v op		Data transfer interface operations
117
+ * @v refcnt		Data transfer interface reference counting method
118
+ */
119
+static inline void xfer_init ( struct xfer_interface *xfer,
120
+			       struct xfer_interface_operations *op,
121
+			       void ( * refcnt ) ( struct interface *intf,
122
+						   int delta ) ) {
123
+	xfer->intf.dest = &null_xfer.intf;
124
+	xfer->intf.refcnt = refcnt;
125
+	xfer->op = op;
126
+}
127
+
128
+/**
129
+ * Get data transfer interface from generic object communication interface
130
+ *
131
+ * @v intf		Generic object communication interface
132
+ * @ret xfer		Data transfer interface
133
+ */
134
+static inline struct xfer_interface *
135
+intf_to_xfer ( struct interface *intf ) {
136
+	return container_of ( intf, struct xfer_interface, intf );
137
+}
96 138
 
97 139
 /**
98
- * Get destination data-transfer interface
140
+ * Get destination data transfer interface
99 141
  *
100
- * @v xfer		Data-transfer interface
142
+ * @v xfer		Data transfer interface
101 143
  * @ret dest		Destination interface
102 144
  */
103 145
 static inline struct xfer_interface *
104 146
 xfer_dest ( struct xfer_interface *xfer ) {
105
-	return container_of ( xfer->intf.dest, struct xfer_interface, intf );
147
+	return intf_to_xfer ( xfer->intf.dest );
106 148
 }
107 149
 
108 150
 /**
109
- * Plug a data-transfer interface into a new destination interface
151
+ * Plug a data transfer interface into a new destination interface
110 152
  *
111
- * @v xfer		Data-transfer interface
153
+ * @v xfer		Data transfer interface
112 154
  * @v dest		New destination interface
113 155
  */
114 156
 static inline void xfer_plug ( struct xfer_interface *xfer,
@@ -117,23 +159,23 @@ static inline void xfer_plug ( struct xfer_interface *xfer,
117 159
 }
118 160
 
119 161
 /**
120
- * Unplug a data-transfer interface
162
+ * Unplug a data transfer interface
121 163
  *
122
- * @v xfer		Data-transfer interface
164
+ * @v xfer		Data transfer interface
123 165
  */
124 166
 static inline void xfer_unplug ( struct xfer_interface *xfer ) {
125 167
 	plug ( &xfer->intf, &null_xfer.intf );
126 168
 }
127 169
 
128 170
 /**
129
- * Terminate a data-transfer interface
171
+ * Stop using a data transfer interface
130 172
  *
131
- * @v xfer		Data-transfer interface
173
+ * @v xfer		Data transfer interface
132 174
  *
133 175
  * After calling this method, no further messages will be received via
134 176
  * the interface.
135 177
  */
136
-static inline void xfer_terminate ( struct xfer_interface *xfer ) {
178
+static inline void xfer_nullify ( struct xfer_interface *xfer ) {
137 179
 	xfer->op = &null_xfer_ops;
138 180
 };
139 181
 

Loading…
Cancel
Save