failing to open a rs232 port causes server socket code to fail?
by knobby67 from LinuxQuestions.org on (#5Q38H)
Hi All,
I have some code that works fine it opens rs232 to get data from a device, it then opens a server that can be read from a remote device. This all appears to work except when the rs232 fails to open. So say I a device on USB0 and don't have the rs232 converter plugged in. It detects the device isn't there, however when the server code starts it fails.
To start the rs232 I use
Code:this->port.id = open( this->port.portname.c_str( ) , O_RDWR | O_NOCTTY | O_NDELAY );
if ( this->port.id == -1)
{
std::string mess = this->port.portname;
mess += " unable to open comms port";
ErrorControl.set_error( mess );
close( this->port.id );
return( false );
}now when I start the server it fails on
Code: if( (master_socket = socket(AF_INET , SOCK_STREAM , 0)) == 0)
{
perror("socket failed");
exit(EXIT_FAILURE);
}This only reports an error if the USB to RS232 converter is not plugged in. Has anyone experienced this before? Is there a solution? Thanks
I have some code that works fine it opens rs232 to get data from a device, it then opens a server that can be read from a remote device. This all appears to work except when the rs232 fails to open. So say I a device on USB0 and don't have the rs232 converter plugged in. It detects the device isn't there, however when the server code starts it fails.
To start the rs232 I use
Code:this->port.id = open( this->port.portname.c_str( ) , O_RDWR | O_NOCTTY | O_NDELAY );
if ( this->port.id == -1)
{
std::string mess = this->port.portname;
mess += " unable to open comms port";
ErrorControl.set_error( mess );
close( this->port.id );
return( false );
}now when I start the server it fails on
Code: if( (master_socket = socket(AF_INET , SOCK_STREAM , 0)) == 0)
{
perror("socket failed");
exit(EXIT_FAILURE);
}This only reports an error if the USB to RS232 converter is not plugged in. Has anyone experienced this before? Is there a solution? Thanks