www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Named Pipes IPC in D for windows and linux ?

reply Tarun Ramakrishna <lenkite gmail.com> writes:
Hi,

Is there anything in the standard library to do named pipes IPC in
both windows and linux ? I am not necessarily looking for a unified
API, anything that will allow me to setup named pipes on either OS and
read/write on them will do.

Thanks,
Tarun
Feb 27 2011
next sibling parent Johannes Pfau <spam example.com> writes:
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

Tarun Ramakrishna wrote:
Hi,

Is there anything in the standard library to do named pipes IPC in
both windows and linux ? I am not necessarily looking for a unified
API, anything that will allow me to setup named pipes on either OS and
read/write on them will do.

Thanks,
Tarun

I'm not sure but I think there's nothing like that in the standard library. The only thing I can think of is that the new std.process (https://github.com/kyllingstad/phobos/blob/new-std-process/std/process.d) uses pipes for IPC (anonymous pipes though, not named pipes) :-( =20 at least for posix druntime exports the c api, so you could write a wrapper for that. (The pipe functions and types are in core.sys.posix.sys.stat.d (mknod, S_IFIFO)) --=20 Johannes Pfau
Feb 27 2011
prev sibling next sibling parent Tarun Ramakrishna <lenkite gmail.com> writes:
Hi Johannes,

Thanks! I located mkfifo in 'core.sys.posix.sys.stat'. I couldn't find
anything for named pipes in the standard library, but there is a
Windows API project in dsource and the module 'win32.winbase' has
declarations for 'CreateNamedPipe', etc. I guess this will do.

Best Regards,
Tarun


On Mon, Feb 28, 2011 at 3:00 AM, Johannes Pfau <spam example.com> wrote:
 Tarun Ramakrishna wrote:
Hi,

Is there anything in the standard library to do named pipes IPC in
both windows and linux ? I am not necessarily looking for a unified
API, anything that will allow me to setup named pipes on either OS and
read/write on them will do.

Thanks,
Tarun

I'm not sure but I think there's nothing like that in the standard library. The only thing I can think of is that the new std.process (https://github.com/kyllingstad/phobos/blob/new-std-process/std/process.d) uses pipes for IPC (anonymous pipes though, not named pipes) :-( at least for posix druntime exports the c api, so you could write a wrapper for that. (The pipe functions and types are in core.sys.posix.sys.stat.d (mknod, S_IFIFO)) -- Johannes Pfau

Feb 27 2011
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Sun, 27 Feb 2011 13:53:05 -0500, Tarun Ramakrishna <lenkite gmail.com>  
wrote:

 Is there anything in the standard library to do named pipes IPC in
 both windows and linux ? I am not necessarily looking for a unified
 API, anything that will allow me to setup named pipes on either OS and
 read/write on them will do.

Any C functions (including system calls) are available. You are free to write your own API, and maybe it will be included in Phobos! -Steve
Feb 28 2011
prev sibling next sibling parent Tarun Ramakrishna <lenkite gmail.com> writes:
Hi Steven,

Yes, I have now understood that.

Is there a guidelines/best practices page somewhere that describes how
should a good library be coded for acceptance into the standard
library:  patterns and conventions, etc ? I am very new to D, but from
the mails I have read on this list so far, I have learnt that all the
devs here prefer that a library API should preferably take power of D
ranges, slices and generics. But what about other things ?

Thanks,
Tarun

On Mon, Feb 28, 2011 at 6:19 PM, Steven Schveighoffer
<schveiguy yahoo.com> wrote:
 On Sun, 27 Feb 2011 13:53:05 -0500, Tarun Ramakrishna <lenkite gmail.com>
 wrote:

 Is there anything in the standard library to do named pipes IPC in
 both windows and linux ? I am not necessarily looking for a unified
 API, anything that will allow me to setup named pipes on either OS and
 read/write on them will do.

Any C functions (including system calls) are available. =A0You are free t=

 write your own API, and maybe it will be included in Phobos!

 -Steve

Feb 28 2011
prev sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Mon, 28 Feb 2011 08:00:28 -0500, Tarun Ramakrishna <lenkite gmail.com>
wrote:

 Hi Steven,

 Yes, I have now understood that.

 Is there a guidelines/best practices page somewhere that describes how
 should a good library be coded for acceptance into the standard
 library:  patterns and conventions, etc ? I am very new to D, but from
 the mails I have read on this list so far, I have learnt that all the
 devs here prefer that a library API should preferably take power of D
 ranges, slices and generics. But what about other things ?

There is an issue with Windows system calls that is difficult to solve. D uses the DMC runtime, not the MSVC runtime. This means when you call C library functions (e.g. printf, fopen), it uses DMC's C library. The library has very poor support for converting to/from OS handles from things like FILE *. This wouldn't be such a problem, except Phobos' I/O API is based on FILE *. This means any system calls you make (such as CreateNamedPipe) which return a HANDLE will be near impossible to wrap into a FILE *. In writing std.process, I had to write my own converters between FILE * and HANDLE, and when that code is available, you should be able to use it (expect to have it done by the next release of dmd). But for now, I would concentrate on getting it to work for your code. One thing to keep in mind is that any library to be accepted into Phobos *should* be cross-platform if possible. I would think named pipes should be able to be a cross-platform library. -Steve
Feb 28 2011