598 zap[
'Q'] =
make_field(JClient::QUEUE_LIMIT) = 100;
604 catch(
const exception &error) {
605 FATAL(error.what() << endl);
609 JServerSocket server(port, backlog);
611 JClientList clientList;
614 DEBUG(
"Port " << setw(10) << port << endl);
615 DEBUG(
"Memory limit " << setw(10) << JDispatch::MEMORY_LIMIT << endl);
616 DEBUG(
"Queue limit " << setw(10) << JClient::QUEUE_LIMIT << endl);
622 select.setReaderMask(server);
624 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ++
client) {
626 if (!
client->in.isReady()) {
627 select.setReaderMask(*
client);
630 if (
client->out.isReset()) {
632 if (!
client->queue.empty()) {
637 client->decrementRequest();
639 select.setWriterMask(*
client);
642 }
else if (
client->out.isBusy()) {
644 select.setWriterMask(*
client);
648 if (select(timeout_us) > 0) {
650 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ) {
654 if (select.hasReaderMask(*
client)) {
659 catch(
const exception& error) {
661 ERROR(
"Remove (3) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() << endl);
663 if (
client->getNickname() !=
"") {
674 DEBUG(
"Client" << *
client <<
".read" << static_cast<const JSocketInputBuffer&>(
client->in) << endl);
677 if (
client->in.isReady()) {
681 bool special = JControlHost::maybe_special(
client->in.prefix);
689 client->setSubscription(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
693 client->setNickname(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
699 client->incrementRequest();
707 string nick_name(
client->in.getRemainingData(),
client->in.getRemainingSize());
710 for (JClientList::iterator
i = clientList.begin();
i != clientList.end(); ++
i) {
711 if (
i->getNickname() == nick_name) {
712 buffer +=
" " +
i->getHostname();
716 JControlHost socket(*
client);
718 socket.PutFullString(
DISPTAG_WhereIs, buffer.substr(buffer.empty() ? 0 : 1));
734 for (JClientList::iterator
i = clientList.begin();
i != clientList.end(); ++
i) {
738 for (std::deque<JDispatch>::const_iterator message =
i->queue.begin(); message !=
i->queue.end(); ++message) {
739 total += message->size();
742 cout <<
"client[" <<
i->getFileDescriptor() <<
"] " <<
i->getNickname() << endl;
743 cout <<
"tag - all:";
748 cout <<
"tag - any:";
753 cout <<
"queue " <<
i->queue.size() <<
' ' << total <<
"B" << endl;
760 istringstream
is(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
772 clientList.add(JDispatch(
client->in.prefix,
client->in.data()));
774 if (JDispatch::MEMORY_TOTAL > JDispatch::MEMORY_LIMIT) {
776 WARNING(
"Memory " << setw(10) << JDispatch::MEMORY_TOTAL <<
" > " << setw(10) << JDispatch::MEMORY_LIMIT << endl);
785 if (select.hasWriterMask(*
client)) {
789 DEBUG(
"Client" << *
client <<
".write" << static_cast<const JSocketStatus&>(
client->out) << endl);
791 if (
client->out.isReady()) {
793 client->queue.pop_front();
799 catch(
const exception& error) {
801 DEBUG(
"Remove (2) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() << endl);
803 if (
client->getNickname() !=
"") {
813 if (select.hasReaderMask(server)) {
817 socket.accept(server.getFileDescriptor());
822 socket.setKeepAlive (
true);
823 socket.setNonBlocking(
true);
825 DEBUG(
"New client" << socket << endl);
827 clientList.push_back(JClient(socket));
Utility class to parse command line options.
static const JTag DISPTAG_Subscribe("_Subscri")
Special ControlHost tags.
static const int DISPATCH_PORT
Default ControlHost port.
static const JTag DISPTAG_Died("Died")
static const JTag DISPTAG_MyId("_MyId")
static const JTag DISPTAG_WhereIs("_WhereIs")
then echo Test string reversed by client(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho-r" -C fi if (( 1 ))
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
static const size_t buffer_size
static const JTag DISPTAG_Born("Born")
static const long long int GIGABYTE
Number of bytes in a mega-byte.
unsigned long long int getRAM()
Get RAM of this CPU.
static const JTag DISPTAG_Gime("_Gime")
static const JTag DISPTAG_Debug("_Debug")
static const JTag DISPTAG_Always("_Always")
static const JTag DISPTAG_ShowStat("_ShowSta")
#define DEBUG(A)
Message macros.