English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Reading into a string from C code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-02-21 (16:28)
From: Richard Jones <rich@a...>
Subject: [Caml-list] Reading into a string from C code
This is my wrapper around the Apache ap_get_client_block call:

CAMLprim value
mod_caml_request_get_client_block (value rv, value str)
  CAMLparam2 (rv, str);
  request_rec *r = Request_rec_val (rv);
  int n = string_length (str);
  char *buffer = String_val (str);
  int i = ap_get_client_block (r, buffer, n);
  if (i == -1) raise_http_error (HTTP_INTERNAL_SERVER_ERROR);
  CAMLreturn (Val_int (i));

ap_get_client_block is prototyped as:

long ap_get_client_block (request_rec *, char *buffer, int buffer_size);

Its job is to read up to buffer_size bytes into buffer and return the
number of bytes actually written into this buffer.

Is my wrapper correct?  Can I call String_val (str) and then write
into that buffer in order to write into the string?  I suspect not,
actually, since although it works most of the time, I seem to be
getting some data corruption errors occasionally.


Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
C2LIB is a library of basic Perl/STL-like types for C. Vectors, hashes,
trees, string funcs, pool allocator: http://www.annexia.org/freeware/c2lib/

To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners