diff --git a/src/Socket2.cpp b/src/Socket2.cpp index 08b97bee0e5c653e59187b1e59b3988b0bbf50de..6c535baa170128788cea318edf3a2f0c0de4bdaf 100644 --- a/src/Socket2.cpp +++ b/src/Socket2.cpp @@ -316,9 +316,7 @@ void Socket2::get_device_property() { proto = UDP; DEBUG_STREAM << "Using UDP protocol" << endl; - } - else - { + } else { proto = TCP; DEBUG_STREAM << "Using TCP protocol" << endl; } @@ -328,13 +326,13 @@ void Socket2::get_device_property() { multiplexing = SLEEP; DEBUG_STREAM << "Using sleep IO multiplexing type" << endl; - } - else - { + } else { multiplexing = SELECT; DEBUG_STREAM << "Using select IO multiplexing type" << endl; } + if (port > 0xFFFF) + init_error = "Invalit port number"; /*----- PROTECTED REGION END -----*/ // Socket2::get_device_property_after } //-------------------------------------------------------- @@ -388,9 +386,16 @@ void Socket2::always_executed_hook() { set_state(Tango::FAULT); set_status(init_error); + return; } - else + + tout.tv_sec = timeout / 1000; + tout.tv_usec = timeout % 1000 * 1000; + if ( ! timerisset( &tout ) ) { + set_state(Tango::FAULT); + set_status("Invalid timeout"); + } else { check_connection( ); } @@ -501,16 +506,6 @@ void Socket2::write(const Tango::DevVarCharArray *argin) /*----- PROTECTED REGION ID(Socket2::write) ENABLED START -----*/ check_init(); - timeval tout; - tout.tv_sec = timeout / 1000; - tout.tv_usec = timeout % 1000 * 1000; - if ( ! timerisset( &tout ) ) - { - Tango::Except::throw_exception( "", - "Invalid timeout", - "Socket2::write()"); - } - char *argin_data = new char[ argin->length() ]; for( unsigned int i=0; i<argin->length(); ++i ) { @@ -622,16 +617,6 @@ Tango::DevVarCharArray *Socket2::read(Tango::DevLong argin) /*----- PROTECTED REGION ID(Socket2::read) ENABLED START -----*/ check_init(); - timeval tout; - tout.tv_sec = timeout / 1000; - tout.tv_usec = timeout % 1000 * 1000; - if ( ! timerisset( &tout ) ) - { - Tango::Except::throw_exception( "", - "Invalid timeout", - "Socket2::read()"); - } - if (argin < 0) { Tango::Except::throw_exception("", @@ -677,16 +662,6 @@ Tango::DevVarCharArray *Socket2::read_until(const Tango::DevVarCharArray *argin) /*----- PROTECTED REGION ID(Socket2::read_until) ENABLED START -----*/ check_init(); - timeval tout; - tout.tv_sec = timeout / 1000; - tout.tv_usec = timeout % 1000 * 1000; - if ( ! timerisset( &tout ) ) - { - Tango::Except::throw_exception( "", - "Invalid timeout", - "Socket2::read_until()"); - } - if (argin->length() != 1) { Tango::Except::throw_exception("", diff --git a/src/Socket2.h b/src/Socket2.h index db8db7ed5459f0a1e6b4ea0d45813114b25f699c..569a9ace582ca84038673a69a67fa0d7c0af73db 100644 --- a/src/Socket2.h +++ b/src/Socket2.h @@ -97,6 +97,8 @@ class Socket2 : public TANGO_BASE_CLASS enum { SLEEP, SELECT } multiplexing; + timeval tout; + /*----- PROTECTED REGION END -----*/ // Socket2::Data Members // Device property data members