void AIO_Output_Handler::open
  (ACE_HANDLE new_handle, ACE_Message_Block &) {
  ACE_SOCK_Stream peer (new_handle);
  int bufsiz = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
  peer.set_option (SOL_SOCKET, SO_SNDBUF,
                   &bufsiz, sizeof bufsiz);

  reader_.open (*this, new_handle, 0, proactor ());
  writer_.open (*this, new_handle, 0, proactor ());

  ACE_Message_Block *mb = 0;
  ACE_NEW (mb, ACE_Message_Block (1));
  reader_.read (*mb, 1);
  ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN);
  no_sigpipe.register_action (SIGPIPE, 0);
  can_write_ = 1;
  start_write (0);
}
int AC_Output_Handler::svc () {
  ACE_Message_Block *chunk[ACE_IOV_MAX];
  size_t message_index = 0;
  ACE_Time_Value time_of_last_send (ACE_OS::gettimeofday ());
  ACE_Time_Value timeout;
  ACE_Sig_Action no_sigpipe ((ACE_SignalHandler) SIG_IGN);
  ACE_Sig_Action original_action;
  no_sigpipe.register_action (SIGPIPE, &original_action);

  for (;;) {
    if (message_index == 0) {
      timeout = ACE_OS::gettimeofday ();
      timeout += FLUSH_TIMEOUT;
    }
    ACE_Message_Block *mblk = 0;
    if (getq (mblk, &timeout) == -1) {
      if (errno == ESHUTDOWN) {
        if (connector_->reconnect () == -1) break;
        continue;
      } else if (errno != EWOULDBLOCK) break;
      else if (message_index == 0) continue;
    } else {
      if (mblk->size () == 0
          && mblk->msg_type () == ACE_Message_Block::MB_STOP)
        { mblk->release (); break; }
      chunk[message_index] = mblk;
      ++message_index;
    }
    if (message_index >= ACE_IOV_MAX ||
        (ACE_OS::gettimeofday () - time_of_last_send
         >= ACE_Time_Value(FLUSH_TIMEOUT))) {
      if (this->send (chunk, message_index) == -1) break;
      time_of_last_send = ACE_OS::gettimeofday ();
    }
  }

  if (message_index > 0)
    this->send (chunk, message_index);
  no_sigpipe.restore_action (SIGPIPE, original_action);
  return 0;
}
Example #3
0
void SthenoCore::open(ACE_ARGV& args) throw (RuntimeException&) {
    ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock);

    m_reservationFlag = false;
    m_runNO = 0; //no run
    m_testNO = 0; //no test
    m_trace = true;
    m_maxServicesQoS = 2;
    //m_runtimeQoS = 950000;
    //absolute
    // dont need this
    m_runtimeQoS = RUNTIME_DEFAULT_QOS; //5000;
    m_runtimePeriod = CPUReservation::DEFAULT_PERIOD;

    //signal handling
    ACE_Sig_Action no_sigpipe((ACE_SignalHandler) SIG_IGN);
    ACE_Sig_Action original_action;
    no_sigpipe.register_action(SIGPIPE, &original_action);


    static const ACE_TCHAR options[] = ACE_TEXT("::");
    const char* prefix = "\0";
    ACE_Get_Opt cmd_opts(args.argc(), args.argv(), options);
    int option;
    if (cmd_opts.long_option
            (ACE_TEXT("prefix"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("run"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("test"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("reservation"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("maxservices"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("runtimeqos"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }

    if (cmd_opts.long_option
            (ACE_TEXT("runtimeqosperiod"), ACE_Get_Opt::ARG_REQUIRED) == -1) {
        throw RuntimeException(RuntimeException::INVALID_ARGS);
    }
    printf("AGRS=%d\n", args.argc());

    while ((option = cmd_opts()) != EOF)
        switch (option) {
            case 0:
            {
                //long_option
                const char *op = cmd_opts.long_option();
                printf("LONG=%s\n", cmd_opts.opt_arg());
                if (ACE_OS::strcmp("prefix", op) == 0) {
                    prefix = cmd_opts.opt_arg();
                    printf("Prefix=%s\n", prefix);
                    break;
                }
                if (ACE_OS::strcmp("run", op) == 0) {
                    m_runNO = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("RunNo=%d %s\n", m_runNO, cmd_opts.opt_arg());
                    break;
                }

                if (ACE_OS::strcmp("test", op) == 0) {
                    m_testNO = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("TestNo=%d %s\n", m_testNO, cmd_opts.opt_arg());
                    break;
                }
                if (ACE_OS::strcmp("reservation", op) == 0) {
                    if (strcasecmp(cmd_opts.opt_arg(), "true") == 0) {
                        m_reservationFlag = true;
                    }
                    break;
                }
                if (ACE_OS::strcmp("maxservices", op) == 0) {
                    m_maxServicesQoS = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    break;
                }

                if (ACE_OS::strcmp("runtimeqos", op) == 0) {
                    m_runtimeQoS = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("runtimeqos=%d %s\n", m_runtimeQoS, cmd_opts.opt_arg());
                    break;
                }

                if (ACE_OS::strcmp("runtimeqosperiod", op) == 0) {
                    m_runtimePeriod = Integer::parseInt(cmd_opts.opt_arg(), 10);
                    printf("runtimeqosPeriod=%d %s\n", m_runtimeQoS, cmd_opts.opt_arg());
                    break;
                }
                break;
            }
            case ':':
            {
                ACE_ERROR
                        ((LM_ERROR, ACE_TEXT("-%c requires an argument\n"),
                        cmd_opts.opt_opt()));
                throw RuntimeException(RuntimeException::INVALID_ARGS);
            }
            default:
            {
            }
        }


    m_p2pQoS = P2P_DEFAULT_QOS; //5000;
    m_servicesQoS = SERVICE_MANAGER_DEFAULT_QOS; //5000;
    //total=75K
    //m_perServicesQoS = 25000;//25000;
    /*m_p2pQoS = m_runtimeQoS * 0.2;    
    m_servicesQoS = m_runtimeQoS * 0.8;        
    m_perServicesQoS = m_servicesQoS / m_maxServicesQoS;*/

    //services 100+50 = 150k
    //core 10k
    //p2p 125k
    //

    stringstream statFile;
    stringstream traceFile;
    stringstream debugFile;
    statFile << "stat_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log";
    traceFile << "trace_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log";
    debugFile << "debug_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log";
    initLogging(statFile.str().c_str(), traceFile.str().c_str(), debugFile.str().c_str());
    initRuntimeQoS(args);
    UUIDPtr runtimeUUID;
    getUUID(runtimeUUID);
    String runtimeDomainPath = "";
    m_runtimeQoSManager = this->getQoSManagerInterface(runtimeDomainPath, RUNTIME_DEFAULT_QOS, m_runtimePeriod, false);
    /*if(m_signalHandler.open()!=0){
        throw RuntimeException(RuntimeException::INVALID_OVERLAY);
    }*/

    try {
        QoSManagerInterface* qosManager = 0;
        if (m_reservationFlag) {
            //String p2pPath = "p2p";
            //qosManager = this->getQoSManagerInterface(p2pPath, m_p2pQoS, m_runtimePeriod);
            qosManager = m_runtimeQoSManager;
        }
        getOverlay()->open(qosManager);
        if (m_reservationFlag) {
            //String servicesPath = "services";
            //m_serviceQosManager = this->getQoSManagerInterface(servicesPath, m_servicesQoS, m_runtimePeriod);            
            m_serviceQosManager = m_runtimeQoSManager;
        }

    } catch (OverlayException& ex) {
        throw RuntimeException(RuntimeException::INVALID_OVERLAY);
    } catch (RuntimeException& runtimeEx) {
        throw RuntimeException(RuntimeException::INVALID_OVERLAY);
    }
    toStart();
    if (trace()) {
        TraceRuntimeSingleton::instance()->logRuntimeOpen(this->m_peerID);
    }
}
Example #4
0
File: server.c Project: ytz2/cs820
void listener(char *server_port, char *interface_name) {
	socklen_t len;
	int listening_fd, errcode;
	struct sockaddr server;
	struct sockaddr_in *iptr;
	char text_buf[TEXT_SIZE];
	char local_node[HOSTMAX];
	char *host_name;
	struct thread_params *params;
	pthread_t agent_id;

	no_sigpipe();
	/* establish a server "listening post" */
	listening_fd = openlistener(server_port, interface_name, &server);

	/* get the hostname of server*/
	if (interface_name == NULL) {
		if (gethostname(local_node, HOSTMAX) < 0) {
			perror("Server gethostname");
			exit(1);
		}
		host_name = local_node;
	} else {
		host_name = interface_name;
	}

	if (listening_fd < 0)
		exit(EXIT_FAILURE);

	/* we are now successfully established as a server */
	/* infinite loop -- server serves forever, must be killed by ^C */
	for (;;) {
		iptr = (struct sockaddr_in *) &server;
		if (inet_ntop(iptr->sin_family, &iptr->sin_addr, text_buf,
				TEXT_SIZE) == NULL) {
			perror("inet_ntop server");
			break;
		}
		fprintf(stderr, "%s listening at IP address %s port %d\n", host_name,
				text_buf, ntohs(iptr->sin_port));
		/* accept a client connection (block until one arrives) */
		params = malloc(sizeof(struct thread_params));
		if (params == NULL) {
			perror("listener malloc");
			break;
		}
		len = sizeof(params->client);
		if ((params->client_fd = accept(listening_fd, &params->client, &len))
				< 0) {
			perror("rplcsd accept");
			break;
		}

		iptr = (struct sockaddr_in *) (&params->client);
		if (inet_ntop(iptr->sin_family, &iptr->sin_addr, text_buf,
				TEXT_SIZE) == NULL) {
			perror("inet_ntop client");
			free(params);
			continue;
		}
		fprintf(stderr, "connected to client at IP address %s "
				"port %d\n", text_buf, ntohs(iptr->sin_port));

		/* we are now successfully connected to a remote client */
		errcode = pthread_create(&agent_id, NULL, server_agent, params);
		if (errcode != 0) {
			fprintf(stderr, "pthread_create server agent: %s\n",
					strerror(errcode));
			break;
		}
	} /* infinite loop */

	if (close(listening_fd) < 0) {
		perror("rplcsd server close");
	}
	pthread_exit(NULL);
} /* listener */