예제 #1
0
void test4GetStatus(ChannelPtr& c)
{
	const std::string jobHandle = "H:localhost.localdomain:4";
	GearmanTaskPtr task(new GearmanTask);
	task->request = GearmanMessage::createGetStatusMessage(jobHandle);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
예제 #2
0
sf::Error Datagram::sendTo (ChannelPtr channel) const {
	if (channel->error()) return channel->error();

	sf::ByteArrayPtr chunk = encode ();
	if (!chunk) return error::TooMuch;

	Error err = channel->write (chunk);
	return err;
}
예제 #3
0
void test4Echo(ChannelPtr& c)
{
	GearmanTaskPtr task(new GearmanTask);
	ChannelBufferPtr buffer = Unpooled::buffer(1024, 64);
	for (int i = 0; i < 20; ++i) {
		buffer->writeByte('0');
	}
	
	task->request = GearmanMessage::createEchoReqMessage(buffer);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
예제 #4
0
void test4OptionReq(ChannelPtr& c)
{
	const std::string option = "exception";
	GearmanTaskPtr task(new GearmanTask);
	ChannelBufferPtr payload = Unpooled::buffer(1024, 64);
	for (int i = 0; i < 10; ++i) {
		payload->writeByte('0');
	}
	task->request = GearmanMessage::createOptionReqMessage(option);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
예제 #5
0
void test4submitJobHighBG(ChannelPtr& c)
{
	const std::string functionName = "hello";
	const std::string uniqueId = "123456";
	GearmanTaskPtr task(new GearmanTask);
	ChannelBufferPtr payload = Unpooled::buffer(1024, 64);
	for (int i = 0; i < 10; ++i) {
		payload->writeByte('0');
	}
	task->request = GearmanMessage::createsubmitJobHighBGMessage(functionName,uniqueId,payload);
	//writedown   往gearman写数据
	c->write(UserEvent(task));
}
예제 #6
0
/**
 * A simple HTTP client that prints out the content of the HTTP response to
 * {@link System#out} to test {@link HttpServer}.
 *
 * @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
 * @author Andy Taylor ([email protected])
 * @author <a href="http://gleamynode.net/">Trustin Lee</a>
 *
 * @version $Rev: 2226 $, $Date: 2010-03-31 11:26:51 +0900 (Wed, 31 Mar 2010) $
 */
int main(int argc, const char* argv[]) {
    if (argc != 2) {
        printf("Usage: SnoopClient <URL>");
        return -1;
    }

    URI uri(argv[1]);
    std::string scheme = uri.getScheme().empty() ? "http" : uri.getScheme();
    std::string host = uri.getHost().empty() ? "localhost" : uri.getHost();
    int port = uri.getPort();

    if (port == -1) {
        if (scheme == "http") {
            port = 80;
        }
        else if (scheme == "https") {
            port = 443;
        }
    }

    if ((scheme != "http") && (scheme != "https")) {
        printf("Only HTTP(S) is supported.");
        return -1;
    }

    bool ssl = scheme == "https";

    // Configure the client.
    ClientBootstrap bootstrap(
        ChannelFactoryPtr(new AsioClientSocketChannelFactory(1)));

    // Set up the event pipeline factory.
    bootstrap.setPipeline(getPipeline(ssl));

    // Start the connection attempt.
    ChannelFuturePtr future = bootstrap.connect(InetAddress(host, port));

    // Wait until the connection attempt succeeds or fails.
    ChannelPtr channel = future->awaitUninterruptibly()->channel();

    if (!future->isSuccess()) {
        bootstrap.shutdown();
        return -1;
    }

    // Prepare the HTTP request.
    HttpRequestPtr request =
        HttpRequestPtr(new HttpRequest(HttpVersion::HTTP_1_1,
                       HttpMethod::GET,
                       uri.toString()));

    request->setHeader(HttpHeaders::Names::HOST, host);
    request->setHeader(HttpHeaders::Names::CONNECTION, HttpHeaders::Values::CLOSE);
    request->setHeader(HttpHeaders::Names::ACCEPT_ENCODING, HttpHeaders::Values::GZIP);

    // Set some example cookies.
    //CookieEncoder httpCookieEncoder = new CookieEncoder(false);
    //httpCookieEncoder.addCookie("my-cookie", "foo");
    //httpCookieEncoder.addCookie("another-cookie", "bar");
    //request->setHeader(HttpHeaders::Names::COOKIE, httpCookieEncoder.encode());

    // Send the HTTP request.
    channel->write(request);

    // Wait for the server to close the connection.
    channel->closeFuture()->awaitUninterruptibly();

    // Shut down executor threads to exit.
    bootstrap.shutdown();

    return 0;
};