示例#1
0
string_vector parse3(const std::string& symbols, const string_vector& nonsyms)
{
  enum{ok,skip,broken} state = ok;
  int paren = 0;
  std::string sym;
  // Words between optional '(' ')'
  std::string note;
  string_vector symlist;

  for (int i = 0; i < symbols.size(); i++) {
    char ch = symbols[i];

    if (ch == '+' || ch == '_') {
      if(paren == 0) {
        if (state != broken && paren == 0 && filter(nonsyms, sym)) {
          safe_push_back(symlist, sym, note);
        }
        state = ok;
        sym.clear();
        note.clear();
      }
    }
    else if (state == ok && ch == '(') {
      paren++;
    }
    else if (state == ok && ch == ')') {
      paren--;
    }
    else if (state == ok && ch == ':') {
      state = skip;
    }
    else if (state == ok && goodchar(ch)) {
      if (paren == 0)
        sym.append(1, ch);
      else
        note.append(1, ch);
    }
    else if(state == ok) {
      state = broken;
    }
  }

  if (state != broken && paren == 0 && filter(nonsyms, sym)) {
    safe_push_back(symlist, sym, note);
  }

  return symlist;
}
示例#2
0
void slave_send_to_worker(struct ev_loop *loop, struct ev_io *w, int revents)
{
    // get slave socket
    int slave_socket = w->fd;

    // think we should stop watcher
    ev_io_stop(loop, w);

    // find a free worker and send slave socket to it
    for(auto it = workers.begin(); it != workers.end(); it++)
    {
        if ((*it).second)
        {
            // found free worker, it is busy from now
            (*it).second = false;

            char tmp[1];
            sock_fd_write((*it).first, tmp, sizeof(tmp), slave_socket);

            return;
        }
    }

    // add to queue for later processing
    safe_push_back(slave_socket);
}