|
@@ -0,0 +1,61 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ * @file
|
|
21
|
+ *
|
|
22
|
+ * Stream API
|
|
23
|
+ */
|
|
24
|
+
|
|
25
|
+#include <stdint.h>
|
|
26
|
+#include <string.h>
|
|
27
|
+#include <errno.h>
|
|
28
|
+#include <gpxe/stream.h>
|
|
29
|
+
|
|
30
|
+/**
|
|
31
|
+ * Send data via connection
|
|
32
|
+ *
|
|
33
|
+ * @v app Stream application
|
|
34
|
+ * @v data Data to send
|
|
35
|
+ * @v len Length of data
|
|
36
|
+ * @ret rc Return status code
|
|
37
|
+ *
|
|
38
|
+ * This method should be called only in the context of an
|
|
39
|
+ * application's senddata() method.
|
|
40
|
+ */
|
|
41
|
+int stream_send ( struct stream_application *app, void *data, size_t len ) {
|
|
42
|
+ struct stream_connection *conn = app->conn;
|
|
43
|
+ int rc;
|
|
44
|
+
|
|
45
|
+ DBGC2 ( app, "Stream %p sending %zd bytes\n", app, len );
|
|
46
|
+
|
|
47
|
+ /* Check connection actually exists */
|
|
48
|
+ if ( ! conn ) {
|
|
49
|
+ DBGC ( app, "Stream %p has no connection\n", app );
|
|
50
|
+ return -ENOTCONN;
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ /* Send data via connection */
|
|
54
|
+ if ( ( rc = conn->op->send ( conn, data, len ) ) != 0 ) {
|
|
55
|
+ DBGC ( app, "Stream %p failed to send %zd bytes: %s\n",
|
|
56
|
+ app, len, strerror ( rc ) );
|
|
57
|
+ return rc;
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ return 0;
|
|
61
|
+}
|