Jonathan Turkanis wrote:
[color=blue]
> "Christopher Benson-Manica" <ataru@nospam.cyberspace.org> wrote in
> message news:c1544q$huq$1@chessie.cirr.com...
>[color=green]
>>Sorry for the lame title, but it's hard to condense what I'm about[/color]
>
> to
>[color=green]
>>say... Here's my situation (my first real C++ situation, yay!).
>>Currently we have a MyTCPThread (don't let the name scare you, this
>>isn't OT) that has a socket member object that has methods Send()[/color]
>
> and
>[color=green]
>>GetLine() for sending and receiving data. I want to subclass
>>MyTCPThread so I can use << and >> as wrappers for Send() and
>>GetLine() (Send() is my primary concern at the moment, FWIW). I[/color]
>
> could
>[color=green]
>>probably come up with some hackneyed scheme to do this on my own,[/color]
>
> but
>[color=green]
>>I'd really like some advice on how to do it well.
>>
>>My initial newbie thoughts suggest something like
>>
>>class
>>MyStreamBasedTCPThread : public MyTCPThread
>>{
>> protected:
>> std::ostringstream outbuf;
>>};
>>
>>but the big problem I see with this is how to make << apply to[/color]
>
> outbuf
>[color=green]
>>(which will get sent) and still keep all the cool overloaded <<
>>operators that ostringstreams already have. I'm really feeling lost
>>looking for a good way to do this. I'd be extremely grateful for[/color]
>
> any
>[color=green]
>>guidance!
>>[/color]
>
>
> I have a library (submitted to boost) which would allow you easily to
> create a standard stream or stream buffer for writing to the TCP
> connection if the underlying connection, if your interface is rich
> enough to allow you to define a wrapper something like this
>
> struct tcp_connection {
> // Constructors, etc.
> int read(char*, int);
> void write(char*, int);
> };
>
> where read and write have the obvious semantics.
>
> You'd end up with something like this
>
> typedef resource_stream<tcp_connection> tcp_stream;
> tcp_stream tcp;
> tcp.open(tcp_connection("www.microsoft.com", 80));
> tcp << "DELETE
http://www.microsoft.com/ HTTP/1.1\r\n"
> << "Host: www.microsoft.com\r\n"
> << "Connection:close\r\n\r\n";
> tcp.flush();
>
> Jonathan
>
>[/color]
Can I get it?