+static guint handler_SIGALRM_hits;
+static sigjmp_buf handler_SIGALRM_sigjmp_buf;
+
+static void handler_SIGALRM(int signo)
+{
+ g_return_if_fail(signo==SIGALRM);
+
+ /* Try to abort the read(2) call first.
+ * If it already read something it will return the partially read data.
+ * Otherwise gnome_vfs_inet_connection_read() will loop back to retry read(2)
+ * and we will abort it after 1 second. OK, some data may be read that time
+ * but who cares.
+ */
+ if (handler_SIGALRM_hits++<ACQUIRE_CABINET_READ_RAW_READ_TIMEOUT_ITERS
+ && !(*ui_progress)(NULL))
+ return;
+
+ siglongjmp(handler_SIGALRM_sigjmp_buf,1); /* 1; meaning: !=0 */
+}
+
+/* FIXME: This is hack.
+ * Correct way would be to use 'GnomeVFSCancellation'
+ * to abort 'GnomeVFSInetConnection' acting as 'GnomeVFSSocket'.
+ * This abort should be handled from 'http' handler
+ * but gnome_vfs_cancellation_cancel() cannot be invoked from
+ * the asynchronous slave thread.
+ */
+static GnomeVFSResult acquire_cabinet_read_raw
+ (struct acquire_cabinet *acquire_cabinet,gpointer buffer,GnomeVFSFileSize bytes,GnomeVFSFileSize *bytes_read,
+ GnomeVFSFileOffset offset)
+{
+gint try=0;
+
+ g_return_val_if_fail(acquire_cabinet!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail(buffer!=NULL || bytes==0,GNOME_VFS_ERROR_BAD_PARAMETERS);
+ g_return_val_if_fail(bytes_read!=NULL,GNOME_VFS_ERROR_BAD_PARAMETERS);
+
+ *bytes_read=0;
+
+ if (!bytes)
+ return GNOME_VFS_ERROR_EOF;
+
+ while (try++<=ACQUIRE_CABINET_READ_RAW_READ_TRY_MAX) {
+GnomeVFSResult errvfsresult;
+GnomeVFSHandle *handle_new;
+struct sigaction oldact;
+int errint;
+struct itimerval itimerval;
+GnomeVFSFileSize offset_current;
+
+ if ((*ui_progress)(NULL))
+ return GNOME_VFS_ERROR_INTERRUPTED;
+
+ if (!sigsetjmp(
+ handler_SIGALRM_sigjmp_buf, /* env */
+ TRUE)) { /* savesigs */
+ handler_SIGALRM_hits=0;
+ errint=sigaction(
+ SIGALRM, /* signum */
+ NULL, /* act */
+ &oldact); /* oldact */
+ g_assert(errint==0);
+ signal(SIGALRM,handler_SIGALRM);
+ itimerval.it_interval.tv_sec=ACQUIRE_CABINET_READ_RAW_READ_ITER_SEC;
+ itimerval.it_interval.tv_usec=ACQUIRE_CABINET_READ_RAW_READ_ITER_USEC;
+ itimerval.it_value=itimerval.it_interval;
+ errint=setitimer(
+ ITIMER_REAL, /* which */
+ &itimerval, /* value */
+ NULL); /* ovalue */
+ g_assert(errint==0);
+ /* Optimization avoid resetting connection
+ * in neon "http" handler of: FC4 gnome-vfs2-2.10.0-5
+ * http://bugzilla.gnome.org/show_bug.cgi?id=324984
+ */
+ errvfsresult=gnome_vfs_tell(*acquire_cabinet->handlep,&offset_current);
+ if (GNOME_VFS_OK==errvfsresult && (GnomeVFSFileOffset)offset_current!=offset)
+ errvfsresult=gnome_vfs_seek(*acquire_cabinet->handlep,GNOME_VFS_SEEK_START,offset);
+ if (GNOME_VFS_OK==errvfsresult)
+ errvfsresult=gnome_vfs_read(*acquire_cabinet->handlep,buffer,bytes,bytes_read);
+ }
+ else
+ errvfsresult=GNOME_VFS_ERROR_INTERRUPTED;
+ itimerval.it_interval.tv_sec=0;
+ itimerval.it_interval.tv_usec=0;
+ itimerval.it_value=itimerval.it_interval;
+ errint=setitimer(
+ ITIMER_REAL, /* which */
+ &itimerval, /* value */
+ NULL); /* ovalue */
+ g_assert(errint==0);
+ errint=sigaction(
+ SIGALRM, /* signum */
+ &oldact, /* act */
+ NULL); /* oldact */
+ g_assert(errint==0);
+ if (errvfsresult==GNOME_VFS_OK) {
+ g_assert(*bytes_read>0);
+ return GNOME_VFS_OK;
+ }
+
+ /* Reopen '*acquire_cabinet->handlep' */
+ g_assert(acquire_cabinet->handle_uri!=NULL);
+ if (GNOME_VFS_OK==(errvfsresult=gnome_vfs_open_uri(&handle_new,acquire_cabinet->handle_uri,
+ GNOME_VFS_OPEN_READ|GNOME_VFS_OPEN_RANDOM))) {
+ gnome_vfs_close(*acquire_cabinet->handlep); /* errors ignored */
+ *acquire_cabinet->handlep=handle_new;
+ }
+ }
+
+ return GNOME_VFS_ERROR_IO;
+}
+