bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I'd like to rearrange the stream_t API slightly


From: Alain Magloire
Subject: Re: I'd like to rearrange the stream_t API slightly
Date: Sun, 9 Dec 2001 20:08:15 -0500 (EST)

Bonjour

[deleted]
..

> 2) Provide the specific information to "create".
> 
> So here the existing stream_*_create() functions would stay the same, except
> for tcp and file which would become
> 
> extern int stream_file_create __P ((stream_t *, char* filename, int flags))
> extern int stream_tcp_create __P ((stream_t *, char* host, int port, int 
> flags))
> 
> (If you want to seperate specification of the resource and opening, then
> having a generic stream_open(stream_t) would be useful. When you create the
> stream it wouldnt be automatically opened it would just create the stream_t
> and return the interface, then you would call stream_open() when you wanted
> the stream opened.
> 
> --
> 
> It sounds like (2) might keep the idea that stream_t is an interface.
> 
> How about:
> 
>  extern int stream_file_create __P ((stream_t *, char* filename, int flags))
>  extern int stream_tcp_create __P ((stream_t *, char* host, int port, int 
> flags))
>  extern int stream_stdio_create __P ((stream_t *, FILE *))
>  extern int stream_mmap_create __P ((stream_t *))
>  extern int stream_memory_create __P ((stream_t *, size_t))
>  extern int stream_fd_create __P ((stream_t *, int))
>  extern int stream_buffer_create __P ((stream_t *, stream_t, size_t)) 
> 
> And:
> 
>  extern int stream_open __P ((stream_t));
> 
>    (Open's the stream, how it does this is its business, the information
>     it needs to open the resource was specified in the stream_X_create()
>     function.)
> 
>  extern int stream_close __P ((stream_t));
>  extern int stream_read __P ((stream_t, void *, size_t, off_t, size_t *))
>  extern int stream_write __P ((stream_t, const void *, size_t, off_t, 
> size_t*))
>  ... etc ...
> 
> 
> Does this make more sense?

Yes.  I agree.
However, if you do the changes, send a note so we can update the other
utilities in mailutils/*.

The arguments in stream_open() was a hack to be able to reuse the stream object
with a new hostname/port(tcp stream) or filename(file stream).
With the new mailbox2, it should not be necessary tcp or file  will
have to extend the base stream_t object. In java/C++:
 public class tcp_stream extends stream {
    // Actually it should be "implements" stream since stream is
    // an interface.
 }

In C, it is a little more awkward:

/* stream_t interface object.  */
typedef struct _mu_stream *mu_stream_t;

struct _mu_stream_vtable
{
...
  int  (*read)      __P ((mu_stream_t, void *, size_t, off_t, size_t *));
  int  (*readline)  __P ((mu_stream_t, char *, size_t, off_t, size_t *));
  int  (*write)     __P ((mu_stream_t, const void *, size_t, off_t, size_t *));
...
};

struct _mu_stream
{
  struct _mu_stream_vtable *vtable;
};

/* tcp_stream_t interface, extends mu_stream_t  */
typedef struct _mu_tcp_stream *mu_stream_t;

struct _mu_tcp_stream_vtable {
  struct _mu_stream_vtable base;
  int (*set_hostname) (...., const char *hostname);
  int (*get_hostname) (....);
  int (*set_port)     (...., int port);
  int (*get_port)     (...., int *port);
};

struct _mu_tcp_stream
{
  struct _mu_tcp_stream_vtable *vtable;
};







reply via email to

[Prev in Thread] Current Thread [Next in Thread]