00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include "config.h"
00025
00026 #include <scalestack/echo/flood/datagram.h>
00027 #include <scalestack/echo/flood/datagram_service.h>
00028 #include <scalestack/kernel/core.h>
00029 #include <scalestack/kernel/module.h>
00030 #include <scalestack/kernel/option.h>
00031
00032 namespace scalestack
00033 {
00034 namespace echo
00035 {
00036 namespace flood
00037 {
00038
00039
00040
00041
00042
00043 void datagram_service::options(kernel::module& module)
00044 {
00045 module.add_option("iterations",
00046 _("Number of iterations to run, 0 means forever."),
00047 "COUNT", "1");
00048 module.add_option("count", _("Number of concurrent sockets to open."),
00049 "COUNT", "1");
00050 module.add_option("packet_size", _("Size of datagram packets to send."),
00051 "SIZE", "4096");
00052 }
00053
00054 datagram_service::datagram_service(kernel::module& module):
00055 network::datagram_service(module),
00056 _count(module.get_option("count").get_size_value()),
00057 _mutex(module)
00058 {
00059 }
00060
00061 network::datagram* datagram_service::add_datagram(void)
00062 {
00063 return new datagram(*this);
00064 }
00065
00066 void datagram_service::remove_datagram(void)
00067 {
00068 _mutex.lock();
00069 _count--;
00070 if (_count == 0)
00071 {
00072 _mutex.unlock();
00073 _module.get_core().shutdown();
00074 }
00075 else
00076 _mutex.unlock();
00077 }
00078
00079 }
00080 }
00081 }