summaryrefslogtreecommitdiff
path: root/src/gpgrt-int.h
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2016-10-19 12:20:44 +0200
committerWerner Koch <wk@gnupg.org>2016-11-12 19:55:05 +0100
commit40e5ff0a0084c0d9521b401db4f38885bfdae233 (patch)
treece754e1533719e6931d11480adc4ca28aad5d12f /src/gpgrt-int.h
parente15416d3668ea9dcc6a64cbb98140a99be8a7865 (diff)
downloadlibgpg-error-40e5ff0a0084c0d9521b401db4f38885bfdae233.tar.gz
estream: Support 'es_poll' on Windows.
* src/Makefile.am (arch_sources): Add new file. * src/estream.c (O_NONBLOCK): Move to 'gpgrt-int.h'. (BUFFER_BLOCK_SIZE): Likewise. (BUFFER_UNREAD_SIZE): Likewise. (struct notify_list_s, notify_list_t): Likewise. (struct _gpgrt_stream_internal, estream_internal_t): Likewise. (X_POLLABLE): New macro. (parse_mode): Parse keyword 'pollable', emulate O_NONBLOCK using the same mechanism on Windows. (_gpgrt_poll): Use the new '_gpgrt_w32_poll' on Windows. * src/gpgrt-int.h (_gpgrt_functions_w32_pollable): New declaration. (_gpgrt_w32_pollable_create): New prototype. (_gpgrt_w32_poll): Likewise. * src/w32-estream.c: New file. This code is adapted from GPGME. * tests/t-poll.c (create_pipe): Create pollable streams. GnuPG-bug-id: 2731 Signed-off-by: Justus Winter <justus@g10code.com>
Diffstat (limited to 'src/gpgrt-int.h')
-rw-r--r--src/gpgrt-int.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index a517cc6..a6e6036 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -52,6 +52,12 @@ gpg_err_code_t _gpgrt_yield (void);
/* Local definitions for estream. */
+#if HAVE_W32_SYSTEM
+# ifndef O_NONBLOCK
+# define O_NONBLOCK 0x40000000 /* FIXME: Is that safe? */
+# endif
+#endif
+
/*
* A private cookie function to implement an internal IOCTL service.
* and ist IOCTL numbers.
@@ -80,6 +86,65 @@ typedef enum
} gpgrt_stream_backend_kind_t;
+/*
+ * A type to hold notification functions.
+ */
+struct notify_list_s
+{
+ struct notify_list_s *next;
+ void (*fnc) (estream_t, void*); /* The notification function. */
+ void *fnc_value; /* The value to be passed to FNC. */
+};
+typedef struct notify_list_s *notify_list_t;
+
+
+/*
+ * Buffer management layer.
+ */
+
+#define BUFFER_BLOCK_SIZE BUFSIZ
+#define BUFFER_UNREAD_SIZE 16
+
+
+/*
+ * The private object describing a stream.
+ */
+struct _gpgrt_stream_internal
+{
+ unsigned char buffer[BUFFER_BLOCK_SIZE];
+ unsigned char unread_buffer[BUFFER_UNREAD_SIZE];
+
+ gpgrt_lock_t lock; /* Lock. Used by *_stream_lock(). */
+
+ gpgrt_stream_backend_kind_t kind;
+ void *cookie; /* Cookie. */
+ void *opaque; /* Opaque data. */
+ unsigned int modeflags; /* Flags for the backend. */
+ char *printable_fname; /* Malloced filename for es_fname_get. */
+ gpgrt_off_t offset;
+ gpgrt_cookie_read_function_t func_read;
+ gpgrt_cookie_write_function_t func_write;
+ gpgrt_cookie_seek_function_t func_seek;
+ gpgrt_cookie_close_function_t func_close;
+ cookie_ioctl_function_t func_ioctl;
+ int strategy;
+ es_syshd_t syshd; /* A copy of the system handle. */
+ struct
+ {
+ unsigned int err: 1;
+ unsigned int eof: 1;
+ unsigned int hup: 1;
+ } indicators;
+ unsigned int deallocate_buffer: 1;
+ unsigned int is_stdstream:1; /* This is a standard stream. */
+ unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */
+ unsigned int printable_fname_inuse: 1; /* es_fname_get has been used. */
+ unsigned int samethread: 1; /* The "samethread" mode keyword. */
+ size_t print_ntotal; /* Bytes written from in print_writer. */
+ notify_list_t onclose; /* On close notify function list. */
+};
+typedef struct _gpgrt_stream_internal *estream_internal_t;
+
/* Local prototypes for estream. */
int _gpgrt_es_init (void);
@@ -237,5 +302,14 @@ const char *_gpgrt_fname_get (gpgrt_stream_t stream);
#include "estream-printf.h"
+#if _WIN32
+/* Prototypes for w32-estream.c. */
+struct cookie_io_functions_s _gpgrt_functions_w32_pollable;
+int _gpgrt_w32_pollable_create (void *_GPGRT__RESTRICT *_GPGRT__RESTRICT cookie,
+ unsigned int modeflags,
+ struct cookie_io_functions_s next_functions,
+ void *next_cookie);
+int _gpgrt_w32_poll (gpgrt_poll_t *fds, size_t nfds, int timeout);
+#endif
#endif /*_GPGRT_GPGRT_INT_H*/