Esempio n. 1
0
void base_sink::proc_input()
{
	deque<basic_buff_ptr> temp;
	while (m_open_flag)
	{
		{
			v_lock(write_lck, mtx_msg_queue);
			if (m_msg_queue.size() > 0)
			{
				temp.swap(m_msg_queue);
			}
		}
		for (auto& x : temp)
		{
			process_internal(x);
		}
		temp.clear();
		chrono::system_clock::time_point tp = chrono::system_clock::now() + chrono::milliseconds(500);
		v_unique_lock(lck, mtx_input);
		m_cond_input.wait_for(lck, chrono::milliseconds(100));
		if (!m_open_flag)
		{
			break;
		}
	}
	for (auto& x : m_msg_queue)
	{
		process_internal(x);
	}
	m_msg_queue.clear();
}
Esempio n. 2
0
  ConfigParser::Entry* ConfigParser::parse_line(const char* line) {
    char* var = strdup(line);
    char* equals = strchr(var, '=');

    if(equals) {
      /* Split the string. */
      *equals++ = 0;
    }

    std::string variable = std::string(trim_str(var));

    std::string value;
    // Just the variable name means true, as in enable
    if(equals) {
      value = std::string(trim_str(equals));
    } else {
      value = std::string("true");
    }

    if(process_internal(variable, value)) {
      free(var);
      return NULL;
    }

    Entry* entry = new ConfigParser::Entry();
    entry->variable = variable;
    entry->value = value;

    free(var);

    return entry;
  }
Esempio n. 3
0
/*
 * @job_xx_ben_file, like job.4.ben, it contains
 job.4.0.out
 job.4.1.out
 job.4.2.out
 job.4.3.out
 job.4.4.out
 *
 * */
double data_proc::process_loose(const string& job_xx_ben_file, int job_scale) {

	double timespan_sum;

#ifdef WAY1
	timespan_sum = process_internal(job_xx_ben_file, job_scale, true);
#elif WAY2
	timespan_sum = process_internal2(job_xx_ben_file, job_scale, true);
#elif WAY3
	timespan_sum = process_internal3(job_xx_ben_file, job_scale, true);
#elif WAY4
	timespan_sum = process_internal4(job_xx_ben_file, job_scale, true);
#elif WAY5
	timespan_sum = process_internal5(job_xx_ben_file, job_scale, true);
#endif

	return timespan_sum;
}
void
process_record(int fd, FCGI_Header* header, guint8* body)
{
    Request *req = NULL;
    guint64 id = GET_HASH(fd,fcgi_get_request_id(header));

    //key not found. if header->type is FCGI_BEGIN_REQUEST
    //than create new request, otherwise skip request due to FastCGI spec
    pthread_mutex_lock (&requests_lock);
    req = g_hash_table_lookup (requests, &id);

    if (!req) {
        if (header->type == FCGI_BEGIN_REQUEST) {
            FCGI_BeginRequestBody *begin_body = (FCGI_BeginRequestBody *)body;

            req = g_new (Request, 1);
            req->hash = id;

            g_hash_table_insert (requests, &req->hash, req);
            pthread_mutex_unlock (&requests_lock);

            req->fd = fd;
            req->requestId = fcgi_get_request_id(header);
            req->header = header;
            req->body = body;
            req->request_num = ++request_num;
            req->keep_alive = begin_body->flags & FCGI_KEEP_CONN;
            req->stdout_sent = FALSE;
            req->hostname = NULL;
            req->port = -1;
            req->vpath = NULL;

            //TODO: host_info must be set in parse_params
            req->host_info = find_host_by_path(NULL, -1, NULL);

            //if host is not single, preallocate space for server variables
            if (!req->host_info) {
                req->chunks = g_string_chunk_new(4096);
                req->key_value_pairs = g_array_sized_new(FALSE, FALSE, sizeof(KeyValuePair), 128);
            } else {
                //host is single, so we can create request now
                create_request (req->host_info, req->hash, req->request_num);
            }

            return;
        }
    }
    pthread_mutex_unlock (&requests_lock);

    if (req) {
        switch(header->type)
        {
            case FCGI_BEGIN_REQUEST:
                //TODO: assert should not be reached
                break;
            case FCGI_ABORT_REQUEST:
                //TODO: remove from hash, send abort to web server
                break;
            case FCGI_PARAMS:
                parse_params (req, header, body);
                break;
            case FCGI_STDIN:
                //TODO: read until the end
                process_internal (req, header, body, fcgi_get_content_len(header));
                break;
            case FCGI_DATA:
                //TODO: nothing?
                break;
            case FCGI_GET_VALUES:
                //currently there are no server-side settings (values)
                break;
            default:
                break;
        }
    }
}