575 zap[
'Q'] =
make_field(JClient::QUEUE_LIMIT) = 100;
581 catch(
const exception &error) {
582 FATAL(error.what() << endl);
586 JServerSocket server(port, backlog);
588 JClientList clientList;
591 DEBUG(
"Port " << setw(10) << port << endl);
592 DEBUG(
"Memory limit " << setw(10) << JDispatch::MEMORY_LIMIT << endl);
593 DEBUG(
"Queue limit " << setw(10) << JClient::QUEUE_LIMIT << endl);
599 select.setReaderMask(server);
601 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ++
client) {
603 if (!
client->in.isReady()) {
604 select.setReaderMask(*
client);
607 if (
client->out.isReset()) {
609 if (!
client->queue.empty()) {
614 client->decrementRequest();
616 select.setWriterMask(*
client);
619 }
else if (
client->out.isBusy()) {
621 select.setWriterMask(*
client);
625 if (select(timeout_us) > 0) {
627 for (JClientList::iterator
client = clientList.begin();
client != clientList.end(); ) {
631 if (select.hasReaderMask(*
client)) {
636 catch(
const exception& error) {
638 ERROR(
"Remove (3) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() << endl);
640 if (
client->getNickname() !=
"") {
651 DEBUG(
"Client" << *
client <<
".read" << static_cast<const JSocketInputBuffer&>(
client->in) << endl);
654 if (
client->in.isReady()) {
658 bool special = JControlHost::maybe_special(
client->in.prefix);
666 client->setSubscription(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
670 client->setNickname(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
676 client->incrementRequest();
684 string nick_name(
client->in.getRemainingData(),
client->in.getRemainingSize());
687 for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
688 if (i->getNickname() == nick_name) {
689 buffer +=
" " + i->getHostname();
693 JControlHost socket(*
client);
695 socket.PutFullString(
DISPTAG_WhereIs, buffer.substr(buffer.empty() ? 0 : 1));
707 istringstream
is(
string(
client->in.getRemainingData(),
client->in.getRemainingSize()));
719 clientList.add(JDispatch(
client->in.prefix,
client->in.data()));
721 if (JDispatch::MEMORY_TOTAL > JDispatch::MEMORY_LIMIT) {
723 WARNING(
"Memory " << setw(10) << JDispatch::MEMORY_TOTAL <<
" > " << setw(10) << JDispatch::MEMORY_LIMIT << endl);
732 if (select.hasWriterMask(*
client)) {
736 DEBUG(
"Client" << *
client <<
".write" << static_cast<const JSocketStatus&>(
client->out) << endl);
738 if (
client->out.isReady()) {
740 client->queue.pop_front();
746 catch(
const exception& error) {
748 DEBUG(
"Remove (2) client" << *
client <<
"<" <<
client->getNickname() <<
">: " << error.what() << endl);
750 if (
client->getNickname() !=
"") {
760 if (select.hasReaderMask(server)) {
764 socket.accept(server.getFileDescriptor());
769 socket.setKeepAlive (
true);
770 socket.setNonBlocking(
true);
772 DEBUG(
"New client" << socket << endl);
774 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)." JProcess -c "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")
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")
#define DEBUG(A)
Message macros.