580{
583
584 int port;
585 int backlog;
586 int timeout_us;
589
590 try {
591
593
601
603 }
604 catch(const exception &error) {
606 }
607
608
612
613
615 DEBUG(
"Memory limit " <<
setw(10) << JDispatch::MEMORY_LIMIT <<
endl);
616 DEBUG(
"Queue limit " <<
setw(10) << JClient::QUEUE_LIMIT <<
endl);
617
618
619 for ( ; ; ) {
620
623
624 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ++
client) {
625
626 if (!
client->in.isReady()) {
628 }
629
630 if (
client->out.isReset()) {
631
632 if (!
client->queue.empty()) {
633
635
637 client->decrementRequest();
638
640 }
641
642 }
else if (
client->out.isBusy()) {
643
645 }
646 }
647
649
650 try {
651 nfds = select(timeout_us);
652 }
653 catch(const exception& error) {
655 }
656
658
659 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ) {
660
661 try {
662
664
665 try {
667 }
668 catch(const exception& error) {
669
670 ERROR(
"Remove (3) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() <<
endl);
671
672 if (
client->getNickname() !=
"") {
674 }
675
677
679
680 continue;
681 }
682
684 }
685
686 if (
client->in.isReady()) {
687
689
690 bool special = JControlHost::maybe_special(
client->in.prefix);
691
693
695
696 if (
client->in.prefix.getTag() == DISPTAG_Subscribe) {
697
698 client->setSubscription(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
699
700 }
else if (
client->in.prefix.getTag() == DISPTAG_MyId) {
701
702 client->setNickname(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
703
705
706 }
else if (
client->in.prefix.getTag() == DISPTAG_Gime) {
707
708 client->incrementRequest();
709
710 }
else if (
client->in.prefix.getTag() == DISPTAG_Always) {
711
713
714 }
else if (
client->in.prefix.getTag() == DISPTAG_WhereIs) {
715
716 string nick_name(
client->in.getRemainingData(),
client->in.getRemainingSize());
717 string buffer;
718
719 for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
720 if (i->getNickname() == nick_name) {
721 buffer += " " + i->getHostname();
722 }
723 }
724
726
727 socket.PutFullString(DISPTAG_WhereIs, buffer.substr(buffer.empty() ? 0 : 1));
728
730
732
734
735 continue;
736
737 }
else if (
client->in.prefix.getTag() == DISPTAG_ShowStat) {
738
740
742
743 for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
744
745 int total = 0;
746
747 for (std::deque<JDispatch>::const_iterator message = i->queue.begin(); message != i->queue.end(); ++message) {
748 total += message->size();
749 }
750
751 cout <<
"client[" << i->getFileDescriptor() <<
"] " << i->getNickname() <<
endl;
752 cout <<
"tag - all:";
755 }
757 cout <<
"tag - any:";
760 }
762 cout <<
"queue " << i->queue.size() <<
' ' << total <<
"B" <<
endl;
763 }
764
765 continue;
766
767 }
else if (
client->in.prefix.getTag() == DISPTAG_Debug) {
768
770
772
773 } else {
774
776 }
777 }
778
780
782
783 if (JDispatch::MEMORY_TOTAL > JDispatch::MEMORY_LIMIT) {
784
785 WARNING(
"Memory " <<
setw(10) << JDispatch::MEMORY_TOTAL <<
" > " <<
setw(10) << JDispatch::MEMORY_LIMIT <<
endl);
786
788 }
789 }
790
792 }
793
795
797
799
800 if (
client->out.isReady()) {
802 client->queue.pop_front();
803 }
804 }
805
807 }
808 catch(const exception& error) {
809
810 DEBUG(
"Remove (2) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() <<
endl);
811
812 if (
client->getNickname() !=
"") {
814 }
815
817
819 }
820 }
821
823
825
828
829 socket.setReuseAddress(
true);
830 socket.setKeepAlive (
true);
831 socket.setNonBlocking (
true);
832
834
836 }
837 }
838 }
839}
#define DEBUG(A)
Message macros.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
List of ControlHost client managers.
void add(const JDispatch &message)
Add message to client queues depending on subscription of each client.
void drop()
Drop all messages from client queues for which the client has not the 'all' subscription.
ControlHost client manager.
Data structure of a ControlHost message.
void setReaderMask(const JAbstractFile &file)
Set reader mask.
bool hasReaderMask(const JAbstractFile &file) const
Has reader file.
void setWriterMask(const JAbstractFile &file)
Set writer mask.
bool hasWriterMask(const JAbstractFile &file) const
Has writer file.
Wrapper class for select call.
Auxiliary class for non-blocking socket I/O.
Auxiliary class for non-blocking socket I/O.
Template definition of a multi-dimensional oscillation probability interpolation table.
JWriter & write(JWriter &out) const override final
Write from input.
JReader & read(JReader &in) override final
Read from input.
Utility class to parse command line options.
static const size_t buffer_size
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
unsigned long long int getRAM()
Get RAM of this CPU.