コード例 #1
0
void act_client(std::string &addr, size_t sze) {
	int sock = nn_socket(AF_SP, NN_REQ);
	std::string host = "tcp://" + addr + ":12345";
	printf("host: %s\n", host.c_str());
	if (nn_connect(sock, host.c_str()) < 0) {
            printf("%s\nn", nn_strerror(errno));
            return;
	}

	std::vector<size_t> lens;
	make_package(sze, lens);
	std::vector<void *> data;
	for (auto len : lens)
		data.push_back((void *)new char[len]);

	MDL::Timer timer;
	nn_send(sock, NULL, 0, 0);
	nn_recv(sock, NULL, 0, 0);

	timer.start();
	MDL::net::send_all(sock, data, lens);
	timer.end();
	printf("send %f\n", timer.second());
	nn_close(sock);

	for (auto p : data) {
		char *pp = (char *)p;
		delete []pp;
	}
}
コード例 #2
0
void act_server(size_t sze) {
	int sock = nn_socket(AF_SP, NN_REP);
	std::string host = "tcp://*:12345";
	if (nn_bind(sock, host.c_str()) < 0) {
            printf("Error: %s\n", nn_strerror(errno));
            return;
	}

	nn_recv(sock, NULL, 0, 0);
	nn_send(sock, NULL, 0, 0);

	std::vector<size_t> lens;
	make_package(sze, lens);

	MDL::Timer timer;
	timer.start();
	MDL::net::receive_all(sock, lens);
	timer.end();

	printf("receive %f\n", timer.second());
	nn_close(sock);
}
コード例 #3
0
ファイル: mod_lily.c プロジェクト: mvader/lily
static int apache_bind_server(lily_parse_state *parser, request_rec *r)
{
    int ret = 1;
    lily_symtab *symtab = parser->symtab;
    lily_class *package_cls = lily_class_by_id(symtab, SYM_CLASS_PACKAGE);
    lily_sig *package_sig = lily_try_sig_for_class(symtab, package_cls);
    lily_var *bound_var = lily_try_new_var(symtab, package_sig, "server", 0);
    if (bound_var) {
        lily_var *save_top = symtab->var_top;
        int save_spot = symtab->next_register_spot;
        int count = 0;

        ap_add_cgi_vars(r);
        ap_add_common_vars(r);
        bind_table_as(&count, parser, r, r->subprocess_env, "env");

        apr_table_t *http_get_args;
        ap_args_to_table(r, &http_get_args);
        bind_table_as(&count, parser, r, http_get_args, "get");

        bind_post(&count, parser, r);

        bind_httpmethod(&count, parser, r);

        if (count != -1) {
            int ok = 1;
            make_package(&ok, parser, bound_var, count, save_spot, save_top);
            if (ok == 0)
                ret = 0;
        }
        else
            ret = 0;
    }
    else
        ret = 0;

    return ret;
}