Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Tuesday, May 08, 2007

gSOAP timeout


To avoid TIME_WAIT state
m = soap_bind(&soap_listener, NULL, listen_port, 100);
if (!soap_valid_socket(m))
{
soap_print_fault(&soap_listener, stderr);
exit(-1);
}
// in order to avoid connection in TIME_WAIT state for a long time
linger lin;
lin.l_onoff = 1;
lin.l_linger = 4; //seconds
setsockopt(m, SOL_SOCKET, SO_LINGER, reinterpret_cast(&lin), sizeof(lin) );

To set send timeout and receive timeout
class soap_client:public soap
{
public:
soap_client()
{
soap_init(this);
send_timeout = 1;
recv_timeout = 1;
accept_timeout = 0;
}
~soap_client()
{
soap_destroy(this);
soap_end(this);
soap_done(this);
std::cout<<__function__<<std::endl;
}
};

set send_timeout and recv_time before soap_bind in server side.

int m = 0, s = 0; /* master and slave sockets */
soap soap_listener;
soap_init(&soap_listener);
set_timeout(&soap_listener);
soap_listener.bind_flags = SO_REUSEADDR;
m = soap_bind(&soap_listener, NULL, listen_port, 100);


When client is timed out, the server still reported operation successful,

it has no knowledge about the timeout error of client side!

0 Comments:

Post a Comment

<< Home