Inheritance: WvStream
Example #1
0
    static IEnumerable contprint(WvLog log, WvStream s, string prefix)
    {
	int i = 0;
	while (s.ok)
	{
	    i++;
	    string str = s.read(128).FromUTF8();
	    log.print("{0}#{1}: {2}\n", prefix, i, str);
	    yield return 0;
	}
    }
Example #2
0
    [Test] public void delayed_string()
    {
	WvLog.maxlevel = WvLog.L.Debug1;
	var log = new WvLog("foo", WvLog.L.Debug2);
	
	b = true;
	log.print(new WvDelayedString(badrender));
	WVPASS(b);
	b = false;
	log.print(WvLog.L.Debug1, new WvDelayedString(goodrender));
	WVPASS(b);
	b = true;
	log.print(WvLog.L.Debug2, new WvDelayedString(badrender));
	WVPASS(b);
    }
Example #3
0
    static void do_request(WvHttpRequest req, Stream s)
    {
	WvLog log = new WvLog("do_request");
	log.print("Handling...\n");
	foreach (KeyValuePair<string,string> p in req.headers)
	    log.print("Header: '{0}' = '{1}'", p.Key, p.Value);
	
	using (StreamWriter w = new StreamWriter(s))
	{
	    w.WriteLine("HTTP/1.0 200 OK");
	    w.WriteLine("Content-type: text/plain");
	    w.WriteLine("");
	    w.WriteLine("Hello world!  Your path was '{0}'",
			req.path);
	    w.WriteLine("Query string: '{0}'", req.query_string);
	}
    }
Example #4
0
    public static void Main()
    {
	{
	    Console.WriteLine("stdout works.");
	    Console.OpenStandardError().write("stderr works.\n".ToUTF8());
	    
	    WvLog log = new WvLog("main");
	    log.print("Hello");
	    log.print(" world!\n");
	    
	    WvStream s1 = new WvTcp("localhost", 80);
	    WvStream s2 = new WvTcp("localhost", 80);
	    s1.onreadable += contprint(log, s1, "\nA\n").ToAction();
	    s2.onreadable += contprint(log, s2, "\nB\n").ToAction();
	    s1.print("GET / HTTP/1.0\r\n\r\n");
	    s2.print("FOO / HTTP/1.0\r\n\r\n");
	    while (s1.ok || s2.ok)
		WvStream.runonce();
	    log.print("\n");
	    log.print("s1 err: {0}\n", s1.err.Short());
	    log.print("s2 err: {0}\n", s2.err.Short());
	}
    }
Example #5
0
    public static void Main()
    {
	WvLog log = new WvLog("test");
	new MyPage(log);
    }
Example #6
0
    // Removes any matching enclosing parens from around a string.
    // E.g. "foo" => "foo", "(foo)" => "foo", "((foo))" => "foo", 
    // "((2)-(1))" => "(2)-(1)"
    public static string StripMatchingParens(string s)
    {
        WvLog log = new WvLog("StripMatchingParens", WvLog.L.Debug5);
        int len = s.Length;

        // Count the initial and trailing number of parens
        int init_parens = 0;
        while (init_parens < len && s[init_parens] == '(')
            init_parens++;

        int trailing_parens = 0;
        while (trailing_parens < len && s[len - trailing_parens - 1] == ')')
            trailing_parens++;

        // No leading or trailing parens means there can't possibly be any
        // matching parens.
        if (init_parens == 0 || trailing_parens == 0)
            return s;

        // Count all the parens in between the leading and trailing ones.
        bool is_escaped = false;
        int paren_count = init_parens;
        int min_parens = init_parens;
        for (int i = init_parens; i < s.Length - trailing_parens; i++)
        {
            if (s[i] == '(' && !is_escaped)
                paren_count++;
            else if (s[i] == ')' && !is_escaped)
                paren_count--;
            else if (s[i] == '\'')
                is_escaped = !is_escaped;

            if (paren_count < min_parens)
                min_parens = paren_count;
        }

        // The minimum number of outstanding parens found while iterating over
        // the string is the number of parens to strip.  Unless there aren't
        // enough trailing parens to match the leading ones, of course.
        min_parens = Math.Min(min_parens, trailing_parens);
        log.print("Trimming {0} parens\n", min_parens);
        return s.Substring(min_parens, len - 2*min_parens);
    }
Example #7
0
 public VxSchemaTests()
 {
     log = new WvLog("VxSchema tests");
 }
Example #8
0
 public DiskSchemaTests()
 {
     dbus = new VxDbusSchema(bus);
     log = new WvLog("Schemamatic Tests");
 }
Example #9
0
    public void TestTableUpdateError(string tabname, string tabschema, 
        string errmsg, string oldval, VxPutOpts opts, int errno, WvLog.L level)
    {
        string key = "Table/" + tabname;
        VxSchema schema = new VxSchema();
        schema.Add("Table", tabname, tabschema, false);

        VxSchemaErrors errs = dbus.Put(schema, null, opts);
        log.print("Received errors: {0}\n", errs.ToString());

        WVPASSEQ(errs.Count, 1);
        WVPASSEQ(errs[key][0].key, key);
	log.print("Expected error prefix: [{0}]\n", errmsg);
        WVPASS(errs[key][0].msg.StartsWith(errmsg));
        WVPASSEQ(errs[key][0].errnum, errno);
        WVPASSEQ((int)errs[key][0].level, (int)level);
        WVPASSEQ(errs[key].Count, 1);

        // Ensure that we didn't break what was already there.
        schema = dbus.Get(key);
        if (oldval.ne())
        {
            WVPASSEQ(schema.Count, 1);
            CheckTable(schema, tabname, oldval);
        }
        else
            WVPASSEQ(schema.Count, 0);
    }