Quote:
Originally Posted by wt200999
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
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.