bug-commoncpp
[Top][All Lists]
Advanced

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

Re: tcpstream write() weirdness


From: Ari Johnson
Subject: Re: tcpstream write() weirdness
Date: Fri, 22 Nov 2002 00:09:58 -0600 (CST)

I forgot the mention that in the first message: I do a flush after the
write.  Like I said, the first thing I write (which contains a newline but
does not end with a newline) does get sent in its entirety, but the second
does not.

Ari Johnson

 --

On Fri, 22 Nov 2002, David Sugar wrote:

>
> The stream classes require implicit flushes because you are writing to the
> internal stream buffer first, and then real writes occur.  This can be
> done with << endl or by implicity calling flush().
>
> On Thu, 21 Nov 2002, Ari Johnson wrote:
>
> >
> > I'm using tcpstream (for simplicity) in a multithreaded app, and am
> > protecting all read() and write() calls on it with a mutex.  I am able to
> > write to the tcpstream once and read the server's response, but the next
> > write() call simply never gets sent out to the network.  Is this a known
> > issue?  Many times I've banged my head off of walls trying to figure out
> > why something won't work for me, only to have a mailing list inform me
> > that I was doing something that I shouldn't, so I wonder if that's not the
> > case here.  Below, find a basic idea of what my class hierarchy looks
> > like; and thank you to any who reply.
> >
> > Ari Johnson
> >
> > --
> >
> > class Stream : public Mutex {
> > private:
> >   tcpstream tcp;
> > public:
> >   void read(...) {
> >     while(!tcp.isPending(Socket::pendingInput, 1000)) {
> >       if(tcp.isPending(Socket::pendingError, 0))
> >         throw something;
> >
> >       Thread::yield();
> >     }
> >
> >     enterMutex();
> >     tcp.read(blah, len);
> >     leaveMutex();
> >   };
> >
> >   void write(...) {
> >     enterMutex();
> >     tcp.write(blah, len);
> >     leaveMutex();
> >   };
> > };
> >
> > class Incoming : public Thread {
> > private:
> >   Stream *stream;
> > public:
> >   void run(void) {
> >     while(1) {
> >       stream->read(somewhere);
> >       possibly_tell_Outgoing_to_send_something;
> >     }
> >   };
> > };
> >
> > class Outgoing : public Thread {
> > private:
> >   Stream *stream;
> > public:
> >   void run(void) {
> >     while(1)
> >       if(feel_like_sending_something)
> >         stream->send(something);
> >   };
> > };
> >
> > NB: Incoming and Outgoing are created in pairs, and the pair shares a
> >     single Stream object.
> >
> >
> >
> > _______________________________________________
> > Bug-commoncpp mailing list
> > address@hidden
> > http://mail.gnu.org/mailman/listinfo/bug-commoncpp
> >
>
>
>
> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp
>





reply via email to

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