sending EOF portably

A

Ara.T.Howard

any way to send EOF down a pipe/io object in a portable fashion? i want to
signal EOF to another process w/o closing/reopen.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
R

Robert Klemme

Ara.T.Howard said:
any way to send EOF down a pipe/io object in a portable fashion? i
want to signal EOF to another process w/o closing/reopen.

There seems to be ETX, EOT, EM, FS... in ASCII but I dunno how portable that
is.
http://www.lookuptables.com/

If you control both processes you can use whatever convention you like.
Other than that it'll be difficult.

Btw, why do you want to do that? A named pipe where you want to disconnect
a listener but keep the pipe is about the only reasonable scenario that I
can think of at the moment.

Kind regards

robert
 
A

Austin Ziegler

any way to send EOF down a pipe/io object in a portable fashion? i want = to
signal EOF to another process w/o closing/reopen.

Design your own?

EOF as a marker character is a convention on Unix (usually Ctrl-D, but
mostly interpreted by the shells, etc.) and is a convention on Win32
when the file is opened in ASCII mode (e.g., 'w', not 'wb').

Better to make it so that you've got an explicit EOF marker yourself.

-austin
--=20
Austin Ziegler * (e-mail address removed)
* Alternate: (e-mail address removed)
 
A

Ara.T.Howard

There seems to be ETX, EOT, EM, FS... in ASCII but I dunno how portable that
is.
http://www.lookuptables.com/

yeah... but you can't actually send those...
If you control both processes you can use whatever convention you like.
Other than that it'll be difficult.

i don't think i can - the input/output could be any binary data so no sequence
of chars will do.
Btw, why do you want to do that? A named pipe where you want to disconnect
a listener but keep the pipe is about the only reasonable scenario that I
can think of at the moment.

see my acgi posts. right now i have to do

open environment
load environment
close environment

open stdin
new cgi using redirected stdin
close stdin

open stdout
open stderr
redirect stdout
redirect stderr
yield cgi
close stdout
close stderr

basically i need to be able to do

io.close
io.clearerr
io.read

in both reading/writing scenarios. i'm working on a clearerr module now ;-)

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
A

Ara.T.Howard

Design your own?

EOF as a marker character is a convention on Unix (usually Ctrl-D, but
mostly interpreted by the shells, etc.) and is a convention on Win32
when the file is opened in ASCII mode (e.g., 'w', not 'wb').

Better to make it so that you've got an explicit EOF marker yourself.


but what? the input/output can be arbitraily long binary data so no chars
will work methinks. my understanding is that you can't send eof on *nix -
only a close will do. but ruby has no clearerr... ;-(

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
N

nobu.nokada

Hi,

At Sat, 17 Sep 2005 05:49:51 +0900,
Ara.T.Howard wrote in [ruby-talk:156486]:
any way to send EOF down a pipe/io object in a portable fashion? i want to
signal EOF to another process w/o closing/reopen.

IO#close_write
 
R

Robert Klemme

Ara.T.Howard said:
yeah... but you can't actually send those...


i don't think i can - the input/output could be any binary data so no
sequence of chars will do.

Well, if you have control you can introduce any protocol (even efficient
ones) that will work. For example you can simply use an escape character.

If you search the web for "mulitplexing on a single stream" you might find
viable solutions, too.

An alternative approach in your case would be to use UNIX domain sockets.
They are limited to the local machine and I believe they are faster than
TCP/IP sockets. This will also make handling on the server side easier if
you have to server multiple clients *concurrently* - even if you initially
prevent actual concurrency. (From your description it's not clear to me how
you want to prevent two concurrent connections. I may be mistaken but I
think there is no way to open a (named) pipe exculsively for writing.)

Kind regards

robert
 
A

Ara.T.Howard

Well, if you have control you can introduce any protocol (even efficient
ones) that will work. For example you can simply use an escape character.

If you search the web for "mulitplexing on a single stream" you might find
viable solutions, too.

i'll consider.
An alternative approach in your case would be to use UNIX domain sockets.
They are limited to the local machine and I believe they are faster than
TCP/IP sockets. This will also make handling on the server side easier if
you have to server multiple clients *concurrently* - even if you initially
prevent actual concurrency. (From your description it's not clear to me how
you want to prevent two concurrent connections.

i don't think there is a good way to acheive high concurrency using ruby's
thread with io intensive application. i do plan to try a socket
implimentation however. i just want to to K.I.S.S though so we'll see.
I may be mistaken but I think there is no way to open a (named) pipe
exculsively for writing.)

open('fifo','w').flock File::FILE_EX

or
require 'posixlock'
open('fifo','w').posixlock File::FILE_EX

doesn't _open_ it exclusively but it does prevent multiple writers - which is
sufficient.

in my case i just have an auxillary file for this purpose - a filesystem
semaphore if you will.

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top