View Single Post
  #9   Spotlight this post!  
Unread 15-01-2009, 01:21
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Re: Getting Live Feed from Axis Camera in Windriver

Quote:
Originally Posted by wt200999 View Post
I was getting the EADDRINUSE thing when I was declaring PCVideoServer as a pointer and making it on the heap. That error stopped when I just declared it on the stack

Code:
PCVideoServer pc;
however I have no idea what that error means
EADDRINUSE is a POSIX error type that is returned when you try to bind an IP socket to a port/address combination that is already in use. For example, if you try to run two web servers on port 80 on your server, only the first instance will be able to bind a socket to port 80, and the other will return as an error with errno EADDRINUSE.

What's happening in your case is that when you declare PCVideoServer on the heap (with new), you bind the video server port on the cRIO, but you never actually delete the PCVideoServer object before your user program completes. Only when the destructor method of PCVideoServer is called is the port actually released:

Code:
void server_heap_bad()
{
   PCVideoServer *server = new PCVideoServer();
   // when this function returns, you lose the pointer to the PCVideoServer object.
   // The PCVideoServer object remains allocated and active, but you can no
   // longer deallocate it because you don't know where it is (this is called a
   // "dangling pointer" error).
   // Thus the video port remains bound until you reboot the cRIO.
}

void server_heap_good()
{
   PCVideoServer *server = new PCVideoServer();
   
   //... do stuff
   delete server; // calls PCVideoServer::~PCVideoServer, which unbinds the port.
}

void server_stack_good()
{
   PCVideoServer server;

   // when this function returns, the server instance is automatically destroyed
   // without the need for delete.  Thus the port will be unbound.
}
Hope this makes sense; in most modern operating systems, the operating system would perform garbage collection on all open handles, including sockets, and eventually the port would automatically be unbound - but this behavior cannot be relied on and may not happen when you kill your project in Wind River.
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
Reply With Quote