Revision: 7383
http://playerstage.svn.sourceforge.net/playerstage/?rev=7383&view=rev
Author: gerkey
Date: 2009-03-08 03:33:17 +0000 (Sun, 08 Mar 2009)
Log Message:
-----------
added temporary examples of libevent usage
Added Paths:
-----------
code/branches/federation/gazebo/webgazebo/http.cc
code/branches/federation/gazebo/webgazebo/httpd.cc
Added: code/branches/federation/gazebo/webgazebo/http.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/http.cc
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/http.cc 2009-03-08 03:33:17 UTC
(rev 7383)
@@ -0,0 +1,51 @@
+// Compile with:
+// g++ -o http http.cc -levent
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+// These headers must be included prior to the libevent headers
+#include <sys/types.h>
+#include <sys/queue.h>
+
+// libevent
+#include <event.h>
+#include <evhttp.h>
+
+// Callback that's invoked when the request is done and we have the
+// response
+void
+cb(evhttp_request* req, void* arg)
+{
+ printf("in client cb, got code:%d\n", req->response_code);
+ printf("response len: %d %d %d\n",
+ req->input_buffer->misalign,
+ req->input_buffer->totallen,
+ req->input_buffer->off);
+ printf(":%s:%s:\n",
+ req->input_buffer->buffer,
+ req->input_buffer->orig_buffer);
+ exit(0);
+}
+
+int
+main(void)
+{
+ struct evhttp_connection* ec;
+ struct evhttp_request* er;
+
+ event_init();
+
+ ec = evhttp_connection_new("localhost", 7000);
+ assert(ec);
+
+ er = evhttp_request_new(cb, NULL);
+
+ int ret = evhttp_make_request(ec, er, EVHTTP_REQ_GET, "/foo");
+ printf("ret: %d\n", ret);
+
+ event_dispatch();
+
+ return 0;
+}
Added: code/branches/federation/gazebo/webgazebo/httpd.cc
===================================================================
--- code/branches/federation/gazebo/webgazebo/httpd.cc
(rev 0)
+++ code/branches/federation/gazebo/webgazebo/httpd.cc 2009-03-08 03:33:17 UTC
(rev 7383)
@@ -0,0 +1,42 @@
+// Compile with:
+// g++ -o httpd httpd.cc -levent
+
+#include <stdio.h>
+#include <assert.h>
+
+// These headers must be included prior to the libevent headers
+#include <sys/types.h>
+#include <sys/queue.h>
+
+// libevent
+#include <event.h>
+#include <evhttp.h>
+
+void
+cb(evhttp_request* req, void* arg)
+{
+ printf("in server cb for uri:%s:\n", req->uri);
+ struct evbuffer* eb = evbuffer_new();
+ assert(eb);
+ evbuffer_add_printf(eb, "response for:%s:\n", req->uri);
+ evhttp_send_reply(req, 200, "foo", eb);
+ evbuffer_free(eb);
+}
+
+int
+main(void)
+{
+ struct evhttp* eh;
+
+ event_init();
+
+ eh = evhttp_start("localhost", 7000);
+ assert(eh);
+
+ evhttp_set_gencb(eh, cb, NULL);
+ //evhttp_set_cb(eh, "/foo", cb, NULL);
+
+ event_dispatch();
+
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit