bug-commoncpp
[Top][All Lists]
Advanced

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

tcpstream write() weirdness


From: Ari Johnson
Subject: tcpstream write() weirdness
Date: Thu, 21 Nov 2002 22:41:46 -0600 (CST)

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.





reply via email to

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