if (epoll_fd == -1)
EXCEPTIONSTREAM(error,t2n_server_error, "error opening epoll: " << strerror(errno));
- //adding sock (fd) to the set of events that epoll API will monitor
if(sock != -1)
add_to_epoll(sock,&sock);
else
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.ptr = ptr;
- //adding newsock (client fd) to the set of events that epoll API will monitor
+
if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd,&ev) == -1)
EXCEPTIONSTREAM(error,t2n_server_error,"error adding server socket to epoll(): " << strerror(errno));
void socket_handler::remove_from_epoll(int fd)
{
struct epoll_event ev;
- //removing (client fd) from the set of events that epoll API monitors
+
if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fd,&ev) == -1)
LOGSTREAM(debug,"error deleting server socket to epoll(): " << strerror(errno) << " ...ignoring"<<endl);
}
EXCEPTIONSTREAM(error,t2n_server_error,"error changing socket ownership: " << strerror(errno));
}
- socket_handler::create_epoll();
+ create_epoll();
start_listening();
{
if (errno == EINTR)
{
- // select interrupted by signal
+ // epoll interrupted by signal
nfds=0;
}
else
try
{
string data;
- // wait till server is up
sleep(1);
{
sc.write("ABC");
// wait half a sec
- sc.fill_buffer(500000);
+ sc.fill_buffer(500);
sc.get_packet(data);
// close the connection
+
}
- } catch(...)
+ } catch(std::exception &e)
{
- std::cerr << "exception in child. ignoring\n";
+ std::cerr << "exception in child. ignoring\n" << e.what();
}
// don't call atexit and stuff
// max 3 sec
for (int i=0; i < 3; i++)
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
sc.write("ABC");
// wait half a sec
- sc.fill_buffer(500000);
+ sc.fill_buffer(500);
sc.get_packet(data);
// close the connection
// max 3 sec
for (int i=0; i < 3; i++)
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
sc.write("ABC");
// wait half a sec
- sc.fill_buffer(500000);
+ sc.fill_buffer(500);
sc.get_packet(data);
// close the connection
// max 3 sec
for (int i=0; i < 3; i++)
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
}
}
+
BOOST_AUTO_TEST_CASE(ServerCallbackOrder)
{
switch(child_pid=fork())
sc.write("1");
// wait half a sec
- sc.fill_buffer(500000);
+ sc.fill_buffer(500);
sc.get_packet(data);
sc.write("2");
for (int i=0; i < 5; i++)
{
- ss.fill_buffer(500000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
for (int i=0; i < 4; i++)
{
- ss.fill_buffer(500000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
// max 3 sec
for (int i=0; i < 3; i++)
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
sc.write("ABC");
// wait half a sec
- sc.fill_buffer(500000);
+ sc.fill_buffer(500);
sc.get_packet(data);
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
// max 3 sec
for (int i=0; i < 3; i++)
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(2000);
string data;
unsigned int cid;
sc.write("ABC");
- // wait half a sec
- sc.fill_buffer(500000);
+ // wait a sec
+ sc.fill_buffer(1000);
sc.get_packet(data);
}
// max 10 sec
for (int i=0; i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 10 sec
for (int i=0; i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
if(ss.get_packet(data))
break;
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
sc.write("ABC");
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.get_packet(data);
BOOST_CHECK_EQUAL(string("DEF"),data);
sc.write("HAHA");
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.get_packet(data);
BOOST_CHECK_EQUAL(string("xyz"),data);
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
sc.write(string().insert(0,100*1024,'x'));
while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
BOOST_CHECK_EQUAL(string().insert(0,100*1024,'y'),data);
{
// wait till server is up
sleep(1);
- socket_client_connection sc(6666);
+ socket_client_connection sc(6665);
sc.write("hello");
} catch(...)
{
default:
// parent
{
- socket_server ss(6666);
+ socket_server ss(6665);
time_t t0 = time(NULL);
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
if(ss.get_packet(data))
break;
{
try
{
- socket_server ss(6666);
+ socket_server ss(6665);
ss.set_logging(&cerr,debug);
time_t t0 = time(NULL);
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
// wait till server is up
sleep(1);
- socket_client_connection sc(6666);
+ socket_client_connection sc(6665);
sc.write("ABC");
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.get_packet(data);
BOOST_CHECK_EQUAL(string("DEF"),data);
sc.write("HAHA");
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.get_packet(data);
BOOST_CHECK_EQUAL(string("xyz"),data);
{
try
{
- socket_server ss(6666);
+ socket_server ss(6665);
ss.set_logging(&cerr,debug);
time_t t0 = time(NULL);
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
// wait till server is up
sleep(1);
- socket_client_connection sc(6666);
+ socket_client_connection sc(6665);
sc.write(string().insert(0,100*1024,'x'));
while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
BOOST_CHECK_EQUAL(string().insert(0,2048*1024,'y'),data);
for (int i=0; i < 10; i++)
{
SocketSet = ss.get_sockets_set();
- cs.handle(1000000);
+ cs.handle(1000);
}
} catch(...)
{
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
command_client cc(&sc);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
command_client cc(&sc);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
command_client cc(&sc);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
command_client cc(&sc);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 3 sec
for (int i=0; i < 3; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
command_client cc(&sc);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 3 sec
for (int i=0; i < 3; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
command_client cc(&sc);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
BOOST_AUTO_TEST_CASE(NewServerSocket)
{
+
switch(child_pid=fork())
{
case -1:
socket_server ss("./socket");
// ss.set_logging(&cerr,debug);
command_server cs(ss);
-
// handle new connection and just one command
- cs.handle(10000000);
- cs.handle(10000000);
+ cs.handle(10000);
+ cs.handle(10000);
}
- sleep(1);
+ sleep(2);
// close socket, create new one
{
socket_server ss("./socket");
- // ss.set_logging(&cerr,debug);
command_server cs(ss);
-
// max 30 sec
for (int i=0; i < 30; i++)
- cs.handle(1000000);
+ cs.handle(1000);
}
} catch(...)
{
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
string data;
while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.reconnect();
sc.write("x");
while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
BOOST_CHECK_EQUAL(string().insert(0,100,'X'),data);
}
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
string data;
while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.close();
sc.write("x");
while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
BOOST_CHECK_EQUAL(string().insert(0,100,'X'),data);
}
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
string data;
while (!sc.packet_available())
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
sc.reconnect();
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
// max 3 sec
while (time(NULL) < t0 + 3 )
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
// we now should have packets complete packets in the buffer
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
// max 3 sec
while (time(NULL) < t0 + 3 )
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
// we now should have one complete packet and some stuff in the buffer
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
// max 3 sec
while (time(NULL) < t0 + 3 )
- sc.fill_buffer(1000000);
+ sc.fill_buffer(1000);
// we now should have one complete packet and some stuff in the buffer
// call handle, eventually reentrant
if (global_server)
- global_server->handle(10000);
+ global_server->handle(1);
++seen_client_requests;
#include <boost/serialization/export.hpp>
+#include "monotonic_clock.hxx"
BOOST_CLASS_EXPORT(reentrant::testfunc_cmd)
BOOST_CLASS_EXPORT(reentrant::testfunc_res)
// child
{
// wait till server is up
- sleep(2);
+ sleep(1);
// hammer the server
for (int i = 0; i < fork_count; i++)
for (int i=0; i < requests_per_child; i++)
{
socket_client_connection sc("./socket");
- // sc.set_logging(&cerr,debug);
command_client cc(&sc);
result_container rc;
while (seen_client_requests < all_requests)
{
++safety_check;
+
if (safety_check > 10) {
std::cerr << "reached safety check, aborting.\n";
break;
}
- long long maxtime=1000000;
+ int maxtime=1000;
+ int millisec_checkpoit;
+
while(maxtime > 0)
- cs.handle(maxtime);
+ {
+ millisec_checkpoit = monotonic_clock_gettime_msec();
+ if (millisec_checkpoit != -1)
+ {
+ cs.handle(maxtime);
+ maxtime -= abs(monotonic_clock_gettime_msec() - millisec_checkpoit);
+ }
+ else _exit(1);
+ }
}
-
global_server = NULL;
}
// max 10 sec
for (int i=0; i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 10 sec
for (int i=0; i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 10 sec
for (int i=0; i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 10 sec
for (int i=0; i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// max 60 sec - we need atleast 28 handle calls to transfer the buffer
for (int i=0; i < 60; i++) {
- cs.handle(1000000);
+ cs.handle(1000);
}
} catch(...)
{
// make sure the server-child is dead before the next test runs
if (child_pid)
{
- // std::cout << "Killing child with pid: " << child_pid << std::endl;
kill(child_pid, SIGKILL);
int status = 0;
// this is an evil hack to get access to real_write, don't ever do this in an app!!!
real_write_connection *rwc=(real_write_connection*)ssc;
- // we write one char each 0.2 sec
+ // we write one char each 0.5 sec
for (int pos=0; pos < data.size(); pos++)
{
string onebyte;
onebyte+=data[pos];
rwc->real_write(onebyte);
- usleep(200000);
+ usleep(500000);
}
}
};
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// wait till server is up
sleep(1);
socket_client_connection sc("./socket");
- command_client cc(&sc,1000000,1000000);
+ command_client cc(&sc,1,1);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
// wait till server is up
sleep(1);
socket_client_connection sc("./socket");
- command_client cc(&sc,1000000,1000000);
+ command_client cc(&sc,100,100);
- t2n_exception* ep=cc.get_constructor_exception();
+ t2n_exception* ep= cc.get_constructor_exception();
string errormsg;
if (ep)
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";
sleep(1);
socket_client_connection sc("./socket");
- command_client cc(&sc,1000000,1000000);
+ command_client cc(&sc,1,1);
result_container rc;
string errormsg;
// max 10 sec
for (int i=0; i < 10; i++)
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
unsigned int cid;
sleep(1);
socket_client_connection sc("./socket");
- command_client cc(&sc,1000000,1000000);
+ command_client cc(&sc,10,10);
result_container rc;
string errormsg;
// max 5 sec
while (time(NULL) < t0 + 5 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
ss.get_packet(data);
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
if (ss.get_packet(received))
break;
// max 5 sec
while (time(NULL) < t0 + 5 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
string data;
ss.get_packet(data);
// max 10 sec
while (time(NULL) < t0 + 10 )
{
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
if (ss.get_packet(received))
break;
{
public:
cmd_group_x_client(libt2n::client_connection *_c,
- long long _command_timeout_usec=command_timeout_millisec_default,
- long long _hello_timeout_usec=hello_timeout_millisec_default)
- : libt2n::command_client(_c,_command_timeout_usec,_hello_timeout_usec)
+ int _command_timeout_sec=command_timeout_millisec_default,
+ int _hello_timeout_sec=hello_timeout_millisec_default)
+ : libt2n::command_client(_c,_command_timeout_sec,_hello_timeout_sec)
{}
- int serverfunc(int i)
- {
- libt2n::result_container rc;
+ int serverfunc(int i)
+ {
+ libt2n::result_container rc;
- send_command(new serverfunc_cmd(i), rc);
- serverfunc_res* res=dynamic_cast<serverfunc_res*>(rc.get_result());
- if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
- return res->get_data();
- }
+ send_command(new serverfunc_cmd(i), rc);
+ serverfunc_res* res=dynamic_cast<serverfunc_res*>(rc.get_result());
+ if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
+ return res->get_data();
+ }
- std::string getserverlog(void)
- {
- libt2n::result_container rc;
+ std::string getserverlog(void)
+ {
+ libt2n::result_container rc;
- send_command(new getserverlog_cmd(), rc);
- getserverlog_res* res=dynamic_cast<getserverlog_res*>(rc.get_result());
- if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
- return res->get_data();
- }
+ send_command(new getserverlog_cmd(), rc);
+ getserverlog_res* res=dynamic_cast<getserverlog_res*>(rc.get_result());
+ if (!res) throw libt2n::t2n_communication_error("result object of wrong type");
+ return res->get_data();
+ }
};
typedef T2nSingletonWrapper<cmd_group_x_client> wraptype;
// max 10 sec
for (; !close_server && !kill_server && i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
}
} catch(...)
{
wraptype::set_connection(auto_ptr<ConnectionWrapper>
(new ReconnectSocketWrapper("./socket")));
- wraptype::get_connection_wrapper()->set_command_timeout_millisec(3000000);
- wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3000000);
+ wraptype::get_connection_wrapper()->set_command_timeout_millisec(200);
+ wraptype::get_connection_wrapper()->set_hello_timeout_millisec(200);
// 42 closes connection on the server side
t2n_exec(&cmd_group_x_client::serverfunc)(42);
string out=t2n_exec(&cmd_group_x_client::getserverlog)();
-
// count the number of times that "new connection accepted" appears in the server log
string::size_type p=0;
int cnt=0;
wraptype::set_connection(auto_ptr<ConnectionWrapper>
(new ReconnectIgnoreFailureSocketWrapper("./socket")));
- wraptype::get_connection_wrapper()->set_command_timeout_millisec(3000000);
- wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3000000);
+ wraptype::get_connection_wrapper()->set_command_timeout_millisec(3);
+ wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3);
// 42 closes connection on the server side
t2n_exec(&cmd_group_x_client::serverfunc)(42);
// max 10 sec
for (; !close_server && !kill_server && i < 10; i++)
- cs.handle(1000000);
+ cs.handle(1000);
}
} catch(...)
{
// parent
{
// wait till server is up
- sleep(2);
+ sleep(1);
}
}
// max 10 sec
for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
+ ss.fill_buffer(1000);
} catch(...)
{
std::cerr << "exception in child. ignoring\n";