changeset 177:16c4e43f34e5 libavformat

added primitive aborting system
author bellard
date Thu, 17 Jul 2003 10:25:36 +0000
parents dbe87175dd99
children d1290621cc6a
files avio.c avio.h
diffstat 2 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/avio.c	Thu Jul 17 10:24:28 2003 +0000
+++ b/avio.c	Thu Jul 17 10:25:36 2003 +0000
@@ -19,7 +19,10 @@
 #include "avformat.h"
 #include <ctype.h>
 
+static int default_interrupt_cb(void);
+
 URLProtocol *first_protocol = NULL;
+URLInterruptCB *url_interrupt_cb = default_interrupt_cb;
 
 int register_protocol(URLProtocol *protocol)
 {
@@ -165,3 +168,22 @@
 {
     pstrcpy(buf, buf_size, h->filename);
 }
+
+
+static int default_interrupt_cb(void)
+{
+    return 0;
+}
+
+/** 
+ * The callback is called in blocking functions to test regulary if
+ * asynchronous interruption is needed. -EINTR is returned in this
+ * case by the interrupted function. 'NULL' means no interrupt
+ * callback is given.  
+ */
+void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)
+{
+    if (!interrupt_cb)
+        interrupt_cb = default_interrupt_cb;
+    url_interrupt_cb = interrupt_cb;
+}
--- a/avio.h	Thu Jul 17 10:24:28 2003 +0000
+++ b/avio.h	Thu Jul 17 10:25:36 2003 +0000
@@ -28,6 +28,8 @@
 #define URL_WRONLY 1
 #define URL_RDWR   2
 
+typedef int URLInterruptCB(void);
+
 int url_open(URLContext **h, const char *filename, int flags);
 int url_read(URLContext *h, unsigned char *buf, int size);
 int url_write(URLContext *h, unsigned char *buf, int size);
@@ -38,6 +40,12 @@
 int url_get_max_packet_size(URLContext *h);
 void url_get_filename(URLContext *h, char *buf, int buf_size);
 
+/* the callback is called in blocking functions to test regulary if
+   asynchronous interruption is needed. -EINTR is returned in this
+   case by the interrupted function. 'NULL' means no interrupt
+   callback is given. */
+void url_set_interrupt_cb(URLInterruptCB *interrupt_cb);
+
 /* not implemented */
 int url_poll(URLPollEntry *poll_table, int n, int timeout);
 
@@ -52,6 +60,7 @@
 } URLProtocol;
 
 extern URLProtocol *first_protocol;
+extern URLInterruptCB *url_interrupt_cb;
 
 int register_protocol(URLProtocol *protocol);
 
@@ -100,7 +109,7 @@
 
 #define URL_EOF (-1)
 int url_fgetc(ByteIOContext *s);
-int url_fprintf(ByteIOContext *s, const char *fmt, ...);
+int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
 char *url_fgets(ByteIOContext *s, char *buf, int buf_size);
 
 void put_flush_packet(ByteIOContext *s);