summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Posix/Fl_Posix_System_Driver.H4
-rw-r--r--src/drivers/Posix/Fl_Posix_System_Driver.cxx29
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.H4
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx54
4 files changed, 88 insertions, 3 deletions
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H
index df9407c17..5712f6be2 100644
--- a/src/drivers/Posix/Fl_Posix_System_Driver.H
+++ b/src/drivers/Posix/Fl_Posix_System_Driver.H
@@ -82,6 +82,10 @@ public:
virtual int dot_file_hidden() {return 1;}
virtual void gettime(time_t *sec, int *usec);
virtual char* strdup(const char *s) {return ::strdup(s);}
+ virtual int close_fd(int fd);
+ // next 2 for support of Fl_SVG_Image
+ virtual int write_nonblocking_fd(int , const unsigned char *&, size_t &);
+ virtual void pipe_support(int &, int &, const unsigned char *, size_t );
#if defined(HAVE_PTHREAD)
virtual void lock_ring();
virtual void unlock_ring();
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx
index dcf9e8f1a..ec43ea741 100644
--- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx
+++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx
@@ -1,7 +1,7 @@
//
// Definition of Posix system driver (used by the X11, Wayland and macOS platforms).
//
-// Copyright 1998-2021 by Bill Spitzak and others.
+// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -308,6 +308,33 @@ bool Fl_Posix_System_Driver::probe_for_GTK(int major, int minor, void **p_ptr_gt
#endif // HAVE_DLSYM && HAVE_DLFCN_H
+int Fl_Posix_System_Driver::close_fd(int fd) { return close(fd); }
+
+int Fl_Posix_System_Driver::write_nonblocking_fd(int fdwrite, const unsigned char *&bytes, size_t &rest_bytes) {
+ if (rest_bytes > 0) {
+ ssize_t nw = write(fdwrite, bytes, rest_bytes);
+ if (nw == -1) {
+ close(fdwrite);
+ return 1; // error
+ }
+ bytes += nw;
+ rest_bytes -= nw;
+ if (rest_bytes == 0) close(fdwrite);
+ }
+ return 0; // success
+}
+
+void Fl_Posix_System_Driver::pipe_support(int &fdread, int &fdwrite, const unsigned char *unused, size_t unused_s) {
+ int fds[2];
+ if (pipe(fds)) { // create anonymous pipe
+ Fl_System_Driver::pipe_support(fdread, fdwrite, NULL, 0); // indicates error
+ } else {
+ fdread = fds[0];
+ fdwrite = fds[1];
+ fcntl(fdwrite, F_SETFL, O_NONBLOCK); // make pipe's write end non-blocking
+ }
+}
+
////////////////////////////////////////////////////////////////
// POSIX threading...
#if defined(HAVE_PTHREAD)
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
index 730d9320d..d05b580d6 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
@@ -1,7 +1,7 @@
//
// Windows system driver for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2010-2021 by Bill Spitzak and others.
+// Copyright 2010-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -114,6 +114,8 @@ public:
virtual void unlock_ring();
virtual double wait(double time_to_wait);
virtual int ready();
+ virtual void pipe_support(int &, int &, const unsigned char *, size_t );
+ virtual int close_fd(int fd);
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
index 237243975..cdb0805eb 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx
@@ -1,7 +1,7 @@
//
// Definition of Windows system driver for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2021 by Bill Spitzak and others.
+// Copyright 1998-2022 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -1026,3 +1026,55 @@ void Fl_WinAPI_System_Driver::unlock() {
void Fl_WinAPI_System_Driver::awake(void* msg) {
PostThreadMessage( main_thread, fl_wake_msg, (WPARAM)msg, 0);
}
+
+// create anonymous pipe in the form of 2 unix-style file descriptors
+static void pipe_win32(int fds[2]) {
+ HANDLE read_h, write_h;
+ SECURITY_ATTRIBUTES sa;
+ sa.nLength = sizeof(sa);
+ sa.lpSecurityDescriptor = NULL;
+ sa.bInheritHandle = true;
+ if (CreatePipe(&read_h, &write_h, &sa, 0) == 0) {
+ fds[0] = fds[1] = -1; // indicates error
+ } else { // create unix-style file descriptors from handles
+ fds[0] = _open_osfhandle((fl_intptr_t)read_h, _O_RDONLY | _O_BINARY);
+ fds[1] = _open_osfhandle((fl_intptr_t)write_h, _O_WRONLY | _O_BINARY);
+ }
+}
+
+struct gunz_data { // data transmitted to thread
+ const unsigned char *data;
+ unsigned length;
+ int fd;
+};
+
+static void __cdecl write_func(struct gunz_data *pdata) { // will run in child thread
+ //const unsigned char *from = pdata->data;
+ while (pdata->length > 0) {
+ int done = _write(pdata->fd, pdata->data, pdata->length);
+ if (done == -1) break;
+ pdata->length -= done;
+ pdata->data += done;
+ }
+ _close(pdata->fd);
+ free(pdata);
+}
+
+int Fl_WinAPI_System_Driver::close_fd(int fd) {
+ return _close(fd);
+}
+
+void Fl_WinAPI_System_Driver::pipe_support(int &fdread, int &fdwrite, const unsigned char *bytes, size_t length) {
+ int fds[2];
+ pipe_win32(fds); // create anonymous pipe
+ if (fds[0] == -1) return Fl_System_Driver::pipe_support(fdread, fdwrite, NULL, 0);
+ fdread = fds[0];
+ fdwrite = -1;
+ // prepare data transmitted to child thread
+ struct gunz_data *thread_data = (struct gunz_data*)malloc(sizeof(struct gunz_data));
+ thread_data->data = bytes;
+ thread_data->length = (unsigned)length;
+ thread_data->fd = fds[1];
+ // launch child thread that will write byte buffer to pipe's write end
+ _beginthread((void( __cdecl * )( void * ))write_func, 0, thread_data);
+}