Esempio n. 1
0
void Server::handleIncomingQueries()
{
  std::cout << "Zapytania..." << std::endl;
  std::list<OwnedPipeChannelPtr> closingConnectionList;

  for(OwnedPipeChannelPtr client : clients_)
  {
    NamedPipeReader& reader = client->getServerReader();

    std::cout << "Awaiting orders..." << std::endl;

    std::string msg = reader.read();    

    if(msg.empty())
      continue;

    std::cout << "Incoming message: " << msg << std::endl;

    if(msg == Linda::Messages::CLOSE_CONNECTION_REQUEST)
      closingConnectionList.push_back(client);            

    std::string answer = handleQuery(msg);
    if(answer == Linda::Messages::TIMEOUT_MESSAGE)
      waitingQueue_.push_back(WaitingQuery(time(NULL) + lastTimeout_, msg, client));
    else
      answerQueue_.push_back(AddressedAnswer(client, answer));
  }
  
  for(OwnedPipeChannelPtr toRemove : closingConnectionList)
    clients_.remove(toRemove); //may be optimized and even made in more precise way
                              //by changig upper loop to old-style std::list::inteterator
                              //list and removing using interator like i = remove(i);
}
Esempio n. 2
0
bool parseSchedulerMessage(int size, const byte *msg, CONTEXT *context)
    {
    switch (msg[0]) 
        {
        case SCHED_CMD_QUERY_ALL:
            return handleQueryAll(size, msg, context);
            break;
        case SCHED_CMD_CREATE_TASK:
            return handleCreateTask(size, msg, context);
            break;
        case SCHED_CMD_DELETE_TASK:
            return handleDeleteTask(size, msg, context);
            break;
        case SCHED_CMD_ADD_TO_TASK:
            return handleAddToTask(size, msg, context);
            break;
        case SCHED_CMD_SCHED_TASK:
            return handleScheduleTask(size, msg, context);
            break;
        case SCHED_CMD_QUERY:
            return handleQuery(size, msg, context);
            break;
        case SCHED_CMD_RESET:
            return handleReset(size, msg, context);
            break;
         case SCHED_CMD_BOOT_TASK:
            return handleBootTask(size, msg, context);
            break;
       }
    return false;
    }
Esempio n. 3
0
void ImageLoader::request(const QUrl &url)
{
    Query createdRequest = createRequest(url);
    if (createdRequest.isValid()) {
        handleQuery(createdRequest);
    }
}
Esempio n. 4
0
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
{
    Q_UNUSED(frame);

    if (request.url().host() == chessApp->url().host()) {
        if (request.url().path() == QString("/%1").arg(QCoreApplication::applicationName())) {
            handleQuery(request.url().queryItems());
            return false;
        }
    }

    switch (type) {
    case QWebPage::NavigationTypeLinkClicked:
        {
            if (request.url().host() != chessApp->url().host()) {
                QDesktopServices::openUrl(request.url());
                return false;
            }
        }
    case QWebPage::NavigationTypeFormSubmitted:
    case QWebPage::NavigationTypeBackOrForward:
    case QWebPage::NavigationTypeReload:
    case QWebPage::NavigationTypeFormResubmitted:
    case QWebPage::NavigationTypeOther:
    default:
        break;
    }
    return QWebPage::acceptNavigationRequest(frame, request, type);
}
Esempio n. 5
0
void GameNetInterface::handleInfoPacket(const Address &remoteAddress, U8 packetType, BitStream *stream)
{
   switch(packetType)
   {
      case Ping:
         if(mGame->isServer())
            handlePing(mGame, remoteAddress, mSocket, stream, mGame->getClientId());
         break;

      case PingResponse: 
         if(!mGame->isServer())  
            handlePingResponse(mGame, remoteAddress, stream);
         break;

      case Query:
         if(mGame->isServer())
            handleQuery(mGame, remoteAddress, mSocket, stream);
         break;

      case QueryResponse: 
         if(!mGame->isServer())  
            handleQueryResponse(mGame, remoteAddress, stream);
         break;

      default:
         TNLAssert(false, "Unknown packetType!");
   }
}
void AbstractGraphPostLoader::request(const QString &graph)
{
    if (!queryManager()) {
        return;
    }

    Query createdRequest = createRequest(graph, data());
    if (createdRequest.isValid()) {
        handleQuery(createdRequest);
    }
}
Esempio n. 7
0
File: example.c Progetto: Sjlver/stp
int main(int argc, char** argv)
{
    int width=8;
    VC handle = vc_createValidityChecker();

    // Create variable "x"
    Expr x = vc_varExpr(handle, "x", vc_bvType(handle, width));

    // Create bitvector x + x
    Expr xPlusx = vc_bvPlusExpr(handle, width, x, x);

    // Create bitvector constant 2
    Expr two = vc_bvConstExprFromInt(handle, width, 2);
    
    // Create bitvector 2*x
    Expr xTimes2 = vc_bvMultExpr(handle, width, two, x);

    // Create bool expression x + x = 2*x
    Expr equality = vc_eqExpr(handle, xPlusx , xTimes2);

    vc_assertFormula(handle, vc_trueExpr(handle) );

    // We are asking STP: ∀ x. true → ( x + x = 2*x )
    // This should be VALID.
    printf("######First Query\n");
    handleQuery(handle, equality);

    // We are asking STP: ∀ x. true → ( x + x = 2 )
    // This should be INVALID.
    printf("######Second Query\n");
    // Create bool expression x + x = 2
    Expr badEquality = vc_eqExpr(handle, xPlusx , two);
    handleQuery(handle, badEquality);

    // Clean up
    vc_Destroy(handle);

    return 0;
}
Esempio n. 8
0
void Server::handleWaitingQueue()
{
  std::cout << "Waiting..." << std::endl;
  for(auto it = waitingQueue_.begin(); it != waitingQueue_.end();)
  {
    std::string answer = handleQuery(it->query);
    if(answer != Linda::Messages::TIMEOUT_MESSAGE)
    {
      answerQueue_.push_back(AddressedAnswer(it->client, answer));
      it = waitingQueue_.erase(it);
    }
    else
      ++it;
  }
}
// ------------ MAIN --------------
int main(int argc, char *argv[])
{	
    // usage check / notification
    if(argc != 6) {
        printf("usage Error: use: hashServer serverAddress serverPort offset[0,64,128,196] successorAddress successorPort\n\n");
        exit(1);
    }
	
	// offset
	offset = atoi(argv[3]);
	
	// alloc hashtable
	table = (struct hashnode *) malloc(sizeof(struct hashnode) * 64);
	
	// set up successor	
    successor_port = atoi(argv[5]);
    if ((successor_he = gethostbyname(argv[4])) == NULL) {  // get the host info
        herror("gethostbyname");
        exit(1);
    }
    
    
    successor_their_addr.sin_family = AF_INET;
    successor_their_addr.sin_port = htons(successor_port);
    successor_their_addr.sin_addr = *((struct in_addr *)successor_he->h_addr);
    memset(successor_their_addr.sin_zero, '\0', sizeof successor_their_addr.sin_zero);
	successor_addrlen = sizeof(successor_their_addr);
	
	//set up local port

	int sockfd, status;
    struct sockaddr_in myaddr;  // local address information

    unsigned char buffer[INTERNAL_BUFFER_LENGTH]; // assume longest
    unsigned int key, value;
    char command[4];

	
	// alloc open request table
//	struct client_request *openClientRequests;
//	openClientRequests = (struct client_request *) malloc(sizeof(struct client_request) * 10); // max. ten parallel connections


    // ---------- UDP --------
    // setup UDP address
    myaddr.sin_family = AF_INET;
    myaddr.sin_addr.s_addr = INADDR_ANY;
    myaddr.sin_port = htons(atoi(argv[2])); // UDP 

    // init udp sock
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if(bind(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0){
		printf("FATAL: UDP binding error\n");
    }
	
	
	if ((server_he = gethostbyname(argv[1])) == NULL) {  // get the host info
		herror("gethostbyname");
		exit(1);
	}
	server_addr.sin_addr = *((struct in_addr *)successor_he->h_addr);
	server_ip = server_addr.sin_addr.s_addr;
	server_port = atoi(argv[2]);
	
    
	printf("Post-poning finger-table setup...\n");
	// wait for nodes to load
	sleep(5);
	
	printf("Setup finger-tables:\n");
	// pack getAddress data
	strcpy(command, "xad");
	forceForwardQuery(command, 2, 0, server_ip,  server_port);
	
	printf("Complete.\n\n");

	// ------- CORE LOOP -----------
    while(1) {
		struct sockaddr_storage their_addr;
		socklen_t addr_size;
		
		printf("Waiting ...\n");
		addr_size = sizeof(their_addr);
		status = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *)&their_addr, &addr_size);
		printf("Recieved query.\n");

        if(status <= 0) {
            printf("Error: receiving");
        } else {
			if (isInternalCommunication(buffer)) {
				unsigned long responseAddress;
				unsigned int responsePort;
				
				unpackDataFromInternal(buffer, command, &key, &value, &responseAddress, &responsePort);
				printf("INTERNAL: [%s] %d:%d (origin: %lu:%d)\n", command, key, value, responseAddress, responsePort);
				
				if (isActiveQuery(command) && canHandleQueryLocally(key)) {
					printf("HANDLE...\n");
					handleQuery(command, key, value, responseAddress, responsePort);
				} else if(isAddressQuery(command)){
					handleAddressQuery(command, key, value, responseAddress, responsePort);
				} else {
					printf("PASS...\n");
					forwardQuery(command, key, value, responseAddress, responsePort);
				}				
			} else {
				unpackData(buffer, command, &key, &value);
				printf("CLIENT: [%s] %d:%d \n", command, key, value);
				
				int requestId = nextFreeRequestId(openClientRequests);
				
				struct client_request request;
				request.socket = *((struct sockaddr *)&their_addr);
				request.socket_addr_len = sizeof(their_addr);
				
				request.active = 1;
				request.key = key;
				
				struct sockaddr_in clientInAddress;
				clientInAddress = *((struct sockaddr_in *) &their_addr);
				request.clientAddress = clientInAddress.sin_addr.s_addr; 
				request.clientPort = clientInAddress.sin_port; //todo
				
				openClientRequests[requestId] = request;
				
				
				if (canHandleQueryLocally(key)) {
					printf("HANDLE...\n");
					handleQuery(command, key, value, request.clientAddress, request.clientPort);
				} else {
					printf("FORCE-FORWARD...\n");
					forceForwardQuery(command, key, value, request.clientAddress, request.clientPort);
					printf("Query entered cluster.\n");
				}
			}
		}
    }
    

    close(sockfd); 


    return 0;
}
Esempio n. 10
0
void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
    std::string::size_type pos = command.find(' ');
    std::string type(command, 0, pos);
    std::string args(command, pos == std::string::npos ? command.size() : pos + 1);

    if (type == "help") // Do help before tabs so they can't override it
    {
        handleHelp(args, tab);
    }
    else if (tab->handleCommand(type, args))
    {
        // Nothing to do
    }
    else if (type == "announce")
    {
        handleAnnounce(args, tab);
    }
    else if (type == "where")
    {
        handleWhere(args, tab);
    }
    else if (type == "who")
    {
        handleWho(args, tab);
    }
    else if (type == "msg" || type == "whisper" || type == "w")
    {
        handleMsg(args, tab);
    }
    else if (type == "query" || type == "q")
    {
        handleQuery(args, tab);
    }
    else if (type == "ignore")
    {
        handleIgnore(args, tab);
    }
    else if (type == "unignore")
    {
        handleUnignore(args, tab);
    }
    else if (type == "join")
    {
        handleJoin(args, tab);
    }
    else if (type == "list")
    {
        handleListChannels(args, tab);
    }
    else if (type == "clear")
    {
        handleClear(args, tab);
    }
    else if (type == "party")
    {
        handleParty(args, tab);
    }
    else if (type == "me")
    {
        handleMe(args, tab);
    }
    else if (type == "record")
    {
        handleRecord(args, tab);
    }
    else if (type == "toggle")
    {
        handleToggle(args, tab);
    }
    else if (type == "present")
    {
        handlePresent(args, tab);
    }
    else
    {
        tab->chatLog(_("Unknown command."));
    }
}