Re: Porting SANE backends

Milon Firikis (milonf@ariadne-t.gr)
Sun, 28 Feb 1999 18:21:32 +0200

Oliver Rauch wrote:
>
> But there must be a routine on other system that creates a new process.
> So where is the problem to implement an own wrapper that is called via
> fork() ?
>
> Bye
> Oliver
>

Unfortunately fork() is rather not trivial to implement. Just take a
look at the amount of effort being produced for the gnu-win32 tools by
the cygnus guys. They implement fork() based in the CreateProcess32 all
right but from what I have "heard" wasn't easy task. Also keep in mind
that other systems may be more thread friendly than process friendly.

Note that the objective is to hide all Unix specific functions from the
backend much like the sanei_scsi_ routines do for scsi operations. It is
a fact that under SANE is possible to provide an ASPI implementation of
sanei_scsi_cmd* under win32 thus providing the natural bridge for
porting the bulk (SCSI) of sane backends under win32. I think that
somebody has already did that...

Anyway since the backends using fork() only for allowing non blocking
access to the frontends I had something like this in mind:

DISCLAIMER: I am writing this of memory. Please don't shoot.

############
sane_start_scan() {

Initialize and start the actual scan

fd=sanei_StartDetachedReadProcess(sane_dev, TheActualSubroutine, other
variables... )
^^^^^
provided by SANE API
...}

where fd is created by a pipe inside sanei_StartDetachedReadProcess

######################

sanei_StartDetachedReadProcess(sane_dev, TheActualSubroutine, other
variables... ){

#if POSIX_UNIX
pipe(rw)

if (!fork()) /* Child */
{
close(rw[0]);
mysterious UNIX signal handling sigaction, sigfillset and more...
_exit(TheActualReaderSubroutine(sane_dev, rw[1]))
}

close(rw[1]);

return rw[0];

// sane_read will read from the pipe and not directly from the sane_dev
descriptor while
// TheActualReaderSubroutine will read from sane_dev and write to rw[1]

#elif OS2_THREADS

// I don't have a clue for non Unix cases &&|| Threads

#elif AMIGA_THREADS

#else

#endif
}

MF

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com