From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: Unbuffered socket I/O Date: Wed, 28 Feb 2007 10:47:58 +0100 Organization: LAAS-CNRS Message-ID: <87fy8qlik1.fsf@laas.fr> References: <87mz34ol6r.fsf@laas.fr> <87abz13kxl.fsf@zip.com.au> <877iu59fm8.fsf@laas.fr> <87slcsfqk4.fsf@zip.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1172656281 3765 80.91.229.12 (28 Feb 2007 09:51:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 28 Feb 2007 09:51:21 +0000 (UTC) To: Guile-Devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Feb 28 10:51:12 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HMLSn-0005eY-9T for guile-devel@m.gmane.org; Wed, 28 Feb 2007 10:51:09 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HMLSn-0006Ji-Is for guile-devel@m.gmane.org; Wed, 28 Feb 2007 04:51:09 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HMLPl-0004Ns-6z for guile-devel@gnu.org; Wed, 28 Feb 2007 04:48:01 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HMLPk-0004MV-52 for guile-devel@gnu.org; Wed, 28 Feb 2007 04:48:00 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HMLPj-0004MG-Tu for guile-devel@gnu.org; Wed, 28 Feb 2007 04:47:59 -0500 Original-Received: from laas.laas.fr ([140.93.0.15]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.52) id 1HMLPj-0004rP-91 for guile-devel@gnu.org; Wed, 28 Feb 2007 04:47:59 -0500 Original-Received: from messiaen.laas.fr (messiaen [IPv6:2001:660:6602:0:230:65ff:fed4:9d20]) by laas.laas.fr (8.13.8/8.13.8) with SMTP id l1S9ltQn015239 for ; Wed, 28 Feb 2007 10:47:55 +0100 (MET) Original-Received: by messiaen.laas.fr (sSMTP sendmail emulation); Wed, 28 Feb 2007 10:47:58 +0100 X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 10 =?iso-8859-1?Q?Vent=F4se?= an 215 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: powerpc-unknown-linux-gnu Mail-Followup-To: Guile-Devel In-Reply-To: <87slcsfqk4.fsf@zip.com.au> (Kevin Ryde's message of "Tue, 27 Feb 2007 10:27:07 +1100") User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) X-Spam-Score: 0.306 () MAILTO_TO_SPAM_ADDR,NO_RELAYS X-Scanned-By: MIMEDefang at CNRS-LAAS on IPv6:2001:660:6602::2 X-detected-kernel: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6579 Archived-At: --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id l1S9ltQn015239 Hi, Kevin Ryde writes: > ludovic.courtes@laas.fr (Ludovic Court=E8s) writes: >> >> Right. That's an incompatible change if the _output_ is buffered. >> Input can be buffered, though, without this being visible by users. > > Alas, that too is in an incompatible change, because recv! ignores > buffering. Hmm, right. > Sounds good. Perhaps `setvbuf-input' and `setvbuf-output' for the two > directions. They could go in 1.8 too if you're careful with the > implementation. Below is a tentative patch (I chose more meaningful names since they don't relate to `setvbuf(3)'). The issue is that it duplicates fport buffering logic, but I couldn't think of a nice way to factorize this with, e.g., `scm_fport_buffer_add ()'. What do you think? Besides, how about applying the change I originally proposed to HEAD? That would require changing `recv!', `send', etc. so that they are somehow "buffering-aware". Ideally, it would be nice if they didn't break through the port abstraction as they currently do, but I don't know how that could be implemented (what should be the meaning of `MSG_DONTROUTE' on an input string buffer? ;-)). >> It >> does nothing for O_NONBLOCK streams and waits for events otherwise. >> Since, for blocking streams, `read ()' does not return until either EO= F >> is reached or at least one octet was read, `fport_wait_for_input ()' >> seems redundant. > > Ahh, hang on, I wonder if it's a hack to do an "exit guile" while > blocked within a read(), thus allowing gc to run in other threads. Indeed, `scm_std_select ()' does a "leave guile". > If that's true then presumably the write side is afflicted too, as > well as various other potentially blocking operations like > read-string!/partial and gethost. Afflicted by what? Thanks, Ludovic. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename*=us-ascii''%2c%2cfport-buffering.diff Content-Description: Asymmetrical fport buffering. --- orig/libguile/fports.c +++ mod/libguile/fports.c @@ -90,10 +90,10 @@ /* default buffer size, used if the O/S won't supply a value. */ static const size_t default_buffer_size = 1024; -/* create FPORT buffer with specified sizes (or -1 to use default size or - 0 for no buffer. */ +/* Create FPORT buffer with specified sizes (or -1 to use default size or + 0 for no buffer). */ static void -scm_fport_buffer_add (SCM port, long read_size, int write_size) +scm_fport_buffer_add (SCM port, long read_size, long write_size) #define FUNC_NAME "scm_fport_buffer_add" { scm_t_port *pt = SCM_PTAB_ENTRY (port); @@ -217,6 +217,115 @@ } #undef FUNC_NAME +SCM_DEFINE (scm_set_port_input_buffer_size_x, "set-port-input-buffer-size!", + 2, 0, 0, + (SCM port, SCM size), + "Use a @var{size}-octet input buffer for @var{port}, which " + "must be a file or socket port. The current input buffer " + "of @var{port} must contain less than @var{size} octets.") +#define FUNC_NAME s_scm_set_port_input_buffer_size_x +{ + scm_t_port *pt; + size_t c_size; + + SCM_VALIDATE_FPORT (1, port); + c_size = scm_to_uint (size); + + pt = SCM_PTAB_ENTRY (port); + + if (pt->read_buf_size != c_size) + { + size_t c_offset, c_end; + unsigned char *new_buf; + + c_end = pt->read_end - pt->read_buf; + c_offset = pt->read_pos - pt->read_buf; + + if (c_offset > c_size) + scm_wrong_type_arg_msg (FUNC_NAME, 1, port, + "Input buffer must be flushed before it " + "can be shrunk"); + + if (c_size == 0) + new_buf = &pt->shortbuf, c_size = 1; + else + { + if (pt->read_buf != &pt->shortbuf) + new_buf = scm_gc_realloc (pt->read_buf, + pt->read_buf_size, c_size, + "port buffer"); + else + new_buf = scm_gc_malloc (c_size, "port buffer"); + } + + pt->read_buf = new_buf; + pt->read_end = new_buf + c_end; + pt->read_pos = new_buf + c_offset; + pt->read_buf_size = c_size; + + if ((pt->read_buf_size == 0) && (pt->write_buf_size == 0)) + SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0); + } + + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + +SCM_DEFINE (scm_set_port_output_buffer_size_x, "set-port-output-buffer-size!", + 2, 0, 0, + (SCM port, SCM size), + "Use a @var{size}-octet output buffer for @var{port}, which " + "must be a file or socket port. The current output buffer of " + "@var{port} must contain less than @var{size} octets.") +#define FUNC_NAME s_scm_set_port_output_buffer_size_x +{ + scm_t_port *pt; + size_t c_size; + + SCM_VALIDATE_FPORT (1, port); + c_size = scm_to_uint (size); + + pt = SCM_PTAB_ENTRY (port); + + if (pt->write_buf_size != c_size) + { + size_t c_offset, c_end; + unsigned char *new_buf; + + c_end = pt->write_end - pt->write_buf; + c_offset = pt->write_pos - pt->write_buf; + + if (c_offset > c_size) + scm_wrong_type_arg_msg (FUNC_NAME, 1, port, + "Output buffer must be flushed before it " + "can be shrunk"); + + if (c_size == 0) + new_buf = &pt->shortbuf, c_size = 1; + else + { + if (pt->write_buf != &pt->shortbuf) + new_buf = scm_gc_realloc (pt->write_buf, + pt->write_buf_size, c_size, + "port buffer"); + else + new_buf = scm_gc_malloc (c_size, "port buffer"); + } + + pt->write_buf = new_buf; + pt->write_end = new_buf + c_end; + pt->write_pos = new_buf + c_offset; + pt->write_buf_size = c_size; + + if ((pt->read_buf_size == 0) && (pt->write_buf_size == 0)) + SCM_SET_CELL_WORD_0 (port, SCM_CELL_WORD_0 (port) | SCM_BUF0); + } + + return SCM_UNSPECIFIED; +} +#undef FUNC_NAME + + /* Move ports with the specified file descriptor to new descriptors, * resetting the revealed count to 0. */ --- orig/libguile/fports.h +++ mod/libguile/fports.h @@ -49,6 +49,8 @@ SCM_API SCM scm_setbuf0 (SCM port); SCM_API SCM scm_setvbuf (SCM port, SCM mode, SCM size); +SCM_API SCM scm_set_port_input_buffer_size_x (SCM port, SCM size); +SCM_API SCM scm_set_port_output_buffer_size_x (SCM port, SCM size); SCM_API void scm_evict_ports (int fd); SCM_API SCM scm_open_file (SCM filename, SCM modes); SCM_API SCM scm_fdes_to_port (int fdes, char *mode, SCM name); --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel --=-=-=--