* [Caml-list] getting fd behind a channel from C
@ 2001-09-04 6:23 Jeremy Fincher
2001-09-04 8:30 ` Olivier Andrieu
0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Fincher @ 2001-09-04 6:23 UTC (permalink / raw)
To: caml-list
I can't for the life of me figure out how, from C, to take an in_channel and
get the file descriptor of it. How do I write a C function that takes an
in_channel and then does some work on the underlying file descriptor?
Thanks,
Jeremy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] getting fd behind a channel from C
2001-09-04 6:23 [Caml-list] getting fd behind a channel from C Jeremy Fincher
@ 2001-09-04 8:30 ` Olivier Andrieu
2001-09-04 14:37 ` Jeremy Fincher
0 siblings, 1 reply; 4+ messages in thread
From: Olivier Andrieu @ 2001-09-04 8:30 UTC (permalink / raw)
To: Jeremy Fincher; +Cc: caml-list
Jeremy Fincher [Tuesday 4 September 2001] :
>
> I can't for the life of me figure out how, from C, to take an in_channel and
> get the file descriptor of it. How do I write a C function that takes an
> in_channel and then does some work on the underlying file descriptor?
in the OCaml source tree, look at byterun/io.h : it contains
definitions and macros to access caml channels from C :
- struct channel has a field fd for the file descriptor.
- the macro Channel takes a Caml value and gives you a struct
channel*
so (Channel(ml_channel))->fd does what you want.
There's also the Unix.descr_of_in_channel and
Unix.descr_of_out_channel functions.
Olivier
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] getting fd behind a channel from C
2001-09-04 8:30 ` Olivier Andrieu
@ 2001-09-04 14:37 ` Jeremy Fincher
2001-09-04 15:08 ` Olivier Andrieu
0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Fincher @ 2001-09-04 14:37 UTC (permalink / raw)
To: caml-list
I already found this, but there's no way to get to this from the standard
C/O'Caml interface.
Jeremy
> in the OCaml source tree, look at byterun/io.h : it contains
> definitions and macros to access caml channels from C :
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] getting fd behind a channel from C
2001-09-04 14:37 ` Jeremy Fincher
@ 2001-09-04 15:08 ` Olivier Andrieu
0 siblings, 0 replies; 4+ messages in thread
From: Olivier Andrieu @ 2001-09-04 15:08 UTC (permalink / raw)
To: Jeremy Fincher; +Cc: caml-list
Jeremy Fincher [Tuesday 4 September 2001] :
> > in the OCaml source tree, look at byterun/io.h : it contains
> > definitions and macros to access caml channels from C :
> I already found this, but there's no way to get to this from the standard
> C/O'Caml interface.
You just have to take the io.h from the OCaml tree, put with your C
files, #include it, at it works !
You can just keep the relevant parts :
<<<<<
#ifndef IO_BUFFER_SIZE
#define IO_BUFFER_SIZE 4096
#endif
struct channel {
int fd; /* Unix file descriptor */
long offset; /* Absolute position of fd in the file */
char * end; /* Physical end of the buffer */
char * curr; /* Current position in the buffer */
char * max; /* Logical end of the buffer (for input) */
void * mutex; /* Placeholder for mutex (for systhreads) */
char buff[IO_BUFFER_SIZE]; /* The buffer itself */
};
#define Channel(v) (*((struct channel **) (Data_custom_val(v))))
>>>>>
Oliv
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-09-04 15:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-04 6:23 [Caml-list] getting fd behind a channel from C Jeremy Fincher
2001-09-04 8:30 ` Olivier Andrieu
2001-09-04 14:37 ` Jeremy Fincher
2001-09-04 15:08 ` Olivier Andrieu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox