[Live-devel] About the right usage of turnOnBackgroundReadHandling()

Aeschbacher Fabrice Fabrice.Aeschbacher at siemens.com
Wed Nov 3 09:53:38 PST 2004


Hi,

I think I'm missing something about the right usage of
turnOnBackgroundReadHandling().
What I'm trying to do is to write a kinda BasicTCPSource class:

class BasicTCPSource: public FramedSource {
...
private:
	int fTcpSocketNum;
...
}

fTcpSocketNum is the handle of a connected TCP socket delivering the
video stream.

I wrote the class on the model of BasicUDPSource:

void BasicTCPSource::incomingPacketHandler(BasicTCPSource* source, int
/*mask*/){
  source->incomingPacketHandler1();
}

void BasicTCPSource::incomingPacketHandler1() {
  // Read the packet into our desired destination:
  fFrameSize = recv(fTcpSocketNum, fTo, BUFFSIZE, 0);

  // Tell our client that we have new data:
  afterGetting(this); // we're preceded by a net read; no infinite
recursion
}

void BasicTCPSource::doGetNextFrame()
{
  // Await the next incoming packet:
  envir().taskScheduler().turnOnBackgroundReadHandling( fTcpSocketNum, 
      (TaskScheduler::BackgroundHandlerProc*)&incomingPacketHandler,
this);

}

<...>

When executing the program, it exists saying:

  FramedSource[0x9293dd8]::getNextFrame(): attempting to read more than
once at the same time!



Then, I tried just to copy a frame from a static array:

static char one_frame[] = { ... };

void BasicTCPSource::incomingPacketHandler1() {
  char dummy[BUFFSIZE];
  // dummy socket read
  (void) recv(fTcpSocketNum, dummy, BUFFSIZE, 0);

  // Copy a static frame
  memcpy(fTo, one_frame, sizeof(one_frame));
  fFrameSize = sizeof(one_frame);

  // Tell our client that we have new data:
  afterGetting(this); // we're preceded by a net read; no infinite
recursion
}


I'm getting the same result:

  FramedSource[0x8f2cdd8]::getNextFrame(): attempting to read more than
once at the same time!

I would greatly appreciate any comment that could help me understand
what I'm doing wrong.

Best regards,
Fabrice Aeschbacher



More information about the live-devel mailing list