[or-cvs] r10791: Added (the start of) loader testing code. (libevent-urz/trunk/sample)
Urz at seul.org
Urz at seul.org
Wed Jul 11 09:45:22 UTC 2007
Author: Urz
Date: 2007-07-11 05:45:21 -0400 (Wed, 11 Jul 2007)
New Revision: 10791
Added:
libevent-urz/trunk/sample/IOCPloader-test.c
Log:
Added (the start of) loader testing code.
Added: libevent-urz/trunk/sample/IOCPloader-test.c
===================================================================
--- libevent-urz/trunk/sample/IOCPloader-test.c (rev 0)
+++ libevent-urz/trunk/sample/IOCPloader-test.c 2007-07-11 09:45:21 UTC (rev 10791)
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2007 Christian King <urzumph at gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ /*
+ * Comment here
+ */
+
+#include <Winsock2.h>
+#include "event.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <Windows.h>
+#include <unistd.h>
+
+#define BUF_SIZE 1000
+
+void gen_pattern_a(char *buf, size_t len) {
+ size_t upto;
+ for(upto = 0; upto < len; upto++) {
+ buf[upto] = 'a';
+ }
+}
+
+int check_pattern_a(char *buf, size_t len) {
+ size_t upto;
+ for(upto = 0; upto < len; upto++) {
+ if(buf[upto] != 'a') {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void gen_pattern_b(char *buf, size_t len) {
+ size_t upto;
+ for(upto = 0; upto < len; upto++) {
+ buf[upto] = 'b';
+ }
+}
+
+int check_pattern_a(char *buf, size_t len) {
+ size_t upto;
+ for(upto = 0; upto < len; upto++) {
+ if(buf[upto] != 'b') {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+void listener() {
+ WSADATA wsaData;
+ struct sa_bufferevent* lsabe;
+
+ WSAStartup(MAKEWORD( 2, 2 ), &wsaData);
+ event_init();
+}
+
+void connector_on_read(struct sa_bufferevent *sabe, void *isnull) {
+ char buf[BUF_SIZE+1];
+ size_t len_read;
+
+ len_read = sa_bufferevent_read(sabe, buf, BUF_SIZE);
+
+ if(!check_pattern_a(buf, len_read)) {
+ buf[BUF_SIZE] = '\0';
+ printf("Recieved buffer failed pattern check a: recieved %s\n", buf);
+ exit(0);
+ }
+
+ gen_pattern_b(buf, BUF_SIZE);
+ sa_bufferevent_write(sabe, buf, BUF_SIZE);
+}
+
+
+void connector() {
+ WSADATA wsaData;
+ struct sa_bufferevent* csabe;
+
+ Sleep(10000);
+ // Wait for listener to set up.
+
+ WSAStartup(MAKEWORD( 2, 2 ), &wsaData);
+ event_init();
+
+ csabe = sa_bufferevent_new(connector_on_read, NULL, NULL, NULL);
+
+}
+
+
+int main (int argc, char **argv)
+{
+ if(fork()) {
+ listener();
+ } else {
+ connector();
+ }
+
+ return 0;
+}
More information about the tor-commits
mailing list