chiark / gitweb /
disorder.h: more consistent approach to function attributes
[disorder] / lib / sink.h
index d3ab9990d61fc24db172a721976fb132336ea864..fc99d6b7b6c1515b51eaf22867b1e301fb54bd42 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdarg.h>
 
 struct dynstr;
+struct socketio;
 
 /** @brief Sink type
  *
@@ -70,6 +71,9 @@ struct sink *sink_discard(void);
 struct sink *sink_error(void);
 /* return a sink which fails all writes */
 
+struct sink *sink_socketio(struct socketio *sio);
+/* return a sink which writes to a socket */
+
 int sink_vprintf(struct sink *s, const char *fmt, va_list ap);
 int sink_printf(struct sink *s, const char *fmt, ...)
   attribute((format (printf, 2, 3)));
@@ -111,6 +115,29 @@ static inline int sink_err(struct sink *s) {
   return s->error(s);
 }
 
+struct source {
+  int (*getch)(struct source *s);
+  int (*error)(struct source *s);
+  int (*eof)(struct source *s);
+
+  enum error_class eclass;
+};
+
+struct source *source_stdio(FILE *fp);
+struct source *source_socketio(struct socketio *sio);
+
+static inline int source_getc(struct source *s) {
+  return s->getch(s);
+}
+
+static inline int source_err(struct source *s) {
+  return s->error(s);
+}
+
+static inline int source_eof(struct source *s) {
+  return s->eof(s);
+}
+
 #endif /* SINK_H */
 
 /*