Re: std::cin and disabling canonical line processing (buffering)
- From: "Harold Bamford" <HaroldBamford@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Jul 2005 08:29:04 -0700
Thanks!
I believe I have found a couple of implementations of sockets in streams but
I haven't tried them. I expect that I will be using them strictly as I/O and
not doing any fancy control.
"Jason Winnebeck" wrote:
> There do exist streambuf implementations for the various sockets, and
> even if I am wrong I would figure it would be pretty easy to write one.
> I can't think of any "gotchas" or other problems if you could do:
> * setup the socket
> * create the streambufs, istream, and ostream around that socket
> * call the function
> * close the sockets
>
> The problem with socket-in-a-streambuf is that it is not possible to
> call socket functions and such on it, but if you only need the stream
> temporarily as an "interface" of sorts, then you can do all of the
> socket stuff in the calling function.
>
> Jason
>
> Harold Bamford wrote:
> > That's the typical case, isn't it? But not here.
> >
> > I have a program that runs a command line interface on an embedded system.
> > The user can access this via telnet or via an RS232 port that the system will
> > treat as a console. In the embedded system, a task is spawned and the task
> > function is just given the stream pointers. Unfortunately, I don't have much
> > of a say on whether I can get a flag saying "isConsole". After all, as
> > EVERYONE knows, a stream is a stream is a stream...
> >
> > Obviously, if the stream pointers refer to a socket, there won't be
> > console-like stuff to deal with. But if the pointers are for the RS232 (aka,
> > console), then I do have to deal.
> >
> > I also want to have this same CLI run under Windows where it will always be
> > accessed from an actual console. Except that someday, this may actually run
> > in a server process and be accessed through sockets, thus putting me in the
> > same position as with the embedded system.
> >
> > The trick is to limit the system dependencies to a small area. As a first
> > crack, I can #ifdef on WIN32 and just assume I've got cin, but I want to be
> > prepared for the next step...
> >
> > Thanks for your help.
> >
> > -- Harold
> >
> >
> > "Jason Winnebeck" wrote:
> >
> >
> >>Are you trying to make a smart application like grep where it works
> >>differently if it gets its input from standard input (as in from a pipe)
> >>or from a file, as in:
> >>
> >>prog | YourCommand
> >>versus
> >>YourCommand SomeFile
> >>
> >>If so, you might be able to infer the information you need. Make the
> >>function take a boolean "isConsole" If the user passed a filename, then
> >>you pass false and a reference to istream that reads the file, if the
> >>user did not you pass an argument, you pass true for isConsole and pass
> >>a reference to cin.
> >>
> >>This is just an idea; I don't know how well it would work in practice,
> >>or if this is what you are looking for.
> >>
> >>Jason
> >>
> >>Harold Bamford wrote:
> >>
> >>>Now, how do I tell if it is a pointer to console input? Is there a way to
> >>>get the handle associated with an istream? I suspect the just comparing
> >>>addresses won't be reliable. Should I compare addresses of some internal
> >>>structure?
> >>
>
.
- References:
- std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- Re: std::cin and disabling canonical line processing (buffering)
- From: Tom Widmer [VC++ MVP]
- Re: std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- Re: std::cin and disabling canonical line processing (buffering)
- From: Jason Winnebeck
- Re: std::cin and disabling canonical line processing (buffering)
- From: Harold Bamford
- Re: std::cin and disabling canonical line processing (buffering)
- From: Jason Winnebeck
- std::cin and disabling canonical line processing (buffering)
- Prev by Date: Re: std::fill_n and an array of pointers
- Next by Date: Re: std::cin and disabling canonical line processing (buffering)
- Previous by thread: Re: std::cin and disabling canonical line processing (buffering)
- Next by thread: Re: std::cin and disabling canonical line processing (buffering)
- Index(es):
Relevant Pages
|