Thread: [Assorted-commits] SF.net SVN: assorted: [682] sandbox/trunk/src/cc
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-04-24 20:51:38
|
Revision: 682 http://assorted.svn.sourceforge.net/assorted/?rev=682&view=rev Author: yangzhang Date: 2008-04-24 13:51:27 -0700 (Thu, 24 Apr 2008) Log Message: ----------- added simple valgrind test Added Paths: ----------- sandbox/trunk/src/cc/valgrind/ sandbox/trunk/src/cc/valgrind/corrupt.cc Added: sandbox/trunk/src/cc/valgrind/corrupt.cc =================================================================== --- sandbox/trunk/src/cc/valgrind/corrupt.cc (rev 0) +++ sandbox/trunk/src/cc/valgrind/corrupt.cc 2008-04-24 20:51:27 UTC (rev 682) @@ -0,0 +1,12 @@ +// Just so I have something to test out valgrind against. + +#include <stdlib.h> +#include <string.h> + +int +main() +{ + void *p = malloc(4); + while (1) memset(p, 0, 8); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-05-02 03:12:44
|
Revision: 695 http://assorted.svn.sourceforge.net/assorted/?rev=695&view=rev Author: yangzhang Date: 2008-05-01 20:12:51 -0700 (Thu, 01 May 2008) Log Message: ----------- added basic st demo Added Paths: ----------- sandbox/trunk/src/cc/st/ sandbox/trunk/src/cc/st/basics.cc Added: sandbox/trunk/src/cc/st/basics.cc =================================================================== --- sandbox/trunk/src/cc/st/basics.cc (rev 0) +++ sandbox/trunk/src/cc/st/basics.cc 2008-05-02 03:12:51 UTC (rev 695) @@ -0,0 +1,42 @@ +#include <cstdio> +#include <iostream> + +#include <commons/check.h> +#include <commons/closing.h> +#include <commons/sockets.h> +#include <commons/st/st.h> + +using namespace std; +using namespace commons; + +void* +f(void *p) +{ + stfd s = tcp_connect("www.google.com", 80); + return NULL; +} + +void* +g(void *p) +{ + st_thread_t t = (st_thread_t) p; + st_sleep(1); + printf("interrupting!\n"); + st_thread_interrupt(t); + printf("interrupted!\n"); + st_sleep(1); + printf("waited\n"); + return NULL; +} + +int +main() +{ + check0(st_init()); + st_thread_t t1 = checkpass(st_thread_create(&f, (void*)"abc", 0, 0)); + checkpass(st_thread_create(&f, (void*)"abc", 0, 0)); + checkpass(st_thread_create(&g, (void*)t1, 0, 0)); + //check0(st_thread_join(t, NULL)); + st_thread_exit(NULL); + return 1; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-05-02 03:13:07
|
Revision: 696 http://assorted.svn.sourceforge.net/assorted/?rev=696&view=rev Author: yangzhang Date: 2008-05-01 20:13:14 -0700 (Thu, 01 May 2008) Log Message: ----------- added basic tamer demo Added Paths: ----------- sandbox/trunk/src/cc/tamer/ sandbox/trunk/src/cc/tamer/basics.tt Added: sandbox/trunk/src/cc/tamer/basics.tt =================================================================== --- sandbox/trunk/src/cc/tamer/basics.tt (rev 0) +++ sandbox/trunk/src/cc/tamer/basics.tt 2008-05-02 03:13:14 UTC (rev 696) @@ -0,0 +1,42 @@ +#include <iostream> +#include <boost/scoped_array.hpp> +#include <commons/check.h> +#include <commons/die.h> +#include <tamer/tamer.hh> +#include <tamer/fd.hh> +#include <tamer/bufferedio.hh> + +using namespace std; +using namespace boost; +using namespace commons; +using namespace tamer; +using namespace tamer::fdx; + +const int port = 8989; + +class C +{ + tamed void f() { return 0; } +}; + +tamed void +go() +{ + tvars { fd listener, conn; } + twait { tcp_listen(port, make_event(listener)); } + checkdie(listener, "listen"); + while (1) { + twait { listener.accept(0, 0, make_event(conn)); } + checkdie(conn, "accept"); + cout << "handling" << endl; + } +} + +int +main() +{ + initialize(); + go(); + loop(); + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-05-14 07:26:03
|
Revision: 810 http://assorted.svn.sourceforge.net/assorted/?rev=810&view=rev Author: yangzhang Date: 2008-05-14 00:26:07 -0700 (Wed, 14 May 2008) Log Message: ----------- added xmap.lzz demo Added Paths: ----------- sandbox/trunk/src/cc/lzz/ sandbox/trunk/src/cc/lzz/xmap.lzz sandbox/trunk/src/cc/lzz/xmap.mk Added: sandbox/trunk/src/cc/lzz/xmap.lzz =================================================================== --- sandbox/trunk/src/cc/lzz/xmap.lzz (rev 0) +++ sandbox/trunk/src/cc/lzz/xmap.lzz 2008-05-14 07:26:07 UTC (rev 810) @@ -0,0 +1,104 @@ +#hdr +#include <iostream> +#include <map> + +#include <pthread.h> + +#include <boost/bind.hpp> + +#include <commons/st/st.h> +#include <commons/boost/threads.h> + +using namespace boost; +using namespace commons; +using namespace std; +#end + +/** + * A thin wrapper around the map class. + */ +class xmap +{ + public: + // Note: map::operator[] is not a const method, so we use map::find(). + void * const & operator[](int k) const { return m.find(k)->second; } + void * & operator[](int k) { return m[k]; } + private: + map<int, void*> m; +}; + +/** + * A server that handles requests to read or update an xmap. + */ +class xmap_server(int port = 17000) +{ + public: + /** + * The main accept loop. + */ + void + serve() + { + st_netfd_t listener = st_tcp_listen(port); + while (true) { + st_netfd_t client = st_accept(listener, NULL, 0, ST_UTIME_NO_TIMEOUT); + st_spawn(boost::bind(&xmap_server::handle, this, client)); + } + } + + private: + /** + * Handle a client. + */ + void + handle(st_netfd_t client) + { + cout << "handling a client " << errno << endl; + string msg("hello\n"); + checkeq(st_write(client, msg.c_str(), msg.size(), ST_UTIME_NO_TIMEOUT), + static_cast<ssize_t>(msg.size())); + check0x(st_netfd_close(client)); + cout << errno << endl; + } + + xmap m; +}; + +void +st_bg() +{ + cout << errno << endl; + while (true) { + cout << "hello st_bg " << errno << endl; + st_sleep(1); + } +} + +void +worker(int i, cqueue<int> queue) +{ + string worker = "worker " + lexical_cast<string>(i) + ": "; + while (true) { + queue.pop(); + cout << worker << "got work" << endl; + cout << worker << "calculating for conn " << errno << endl; + sleep(1); + } + st_call(bind(st_write, fd)); +} + +int +main() +{ + const int nworkers = 5; + vector<pthread_t> workers(nworkers); + for (int i = 0; i < nworkers; i++) { + workers[i] = checknneg(spawn(bind(worker, i))); + } + check0x(pthread_join(workers[i], NULL)); + check0x(st_init()); + check(st_spawn(bind(st_bg))); + xmap_server s; + s.serve(); + return 0; +} Added: sandbox/trunk/src/cc/lzz/xmap.mk =================================================================== --- sandbox/trunk/src/cc/lzz/xmap.mk (rev 0) +++ sandbox/trunk/src/cc/lzz/xmap.mk 2008-05-14 07:26:07 UTC (rev 810) @@ -0,0 +1,32 @@ +TARGET := xmap +LZZS := $(wildcard *.lzz) +SRCS := $(foreach lzz,$(LZZS),$(patsubst %.lzz,%.o,$(lzz))) +HDRS := $(foreach lzz,$(LZZS),$(patsubst %.lzz,%.hh,$(lzz))) +OBJS := $(foreach lzz,$(LZZS),$(patsubst %.lzz,%.cc,$(lzz))) +LDFLAGS := -lstx -lst -lresolv -lpthread +CXXFLAGS := -g3 -Wall -Werror + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(CXX) -o $@ $< $(LDFLAGS) + +%.o: %.cc + wtf $(CXX) $(CXXFLAGS) -c -o $@ $< + +%.cc: %.lzz + lzz -hx hh -sx cc -hl -sl -hd -sd $< + +%.hh: %.lzz + lzz -hx hh -sx cc -hl -sl -hd -sd $< + +clean: + rm -f *.cc *.hh *.o xmap + +doc: $(SRCS) $(HDRS) + doxygen + +.PHONY: clean + +# %.cc doesn't work +.SECONDARY: main.cc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-06-06 00:27:09
|
Revision: 853 http://assorted.svn.sourceforge.net/assorted/?rev=853&view=rev Author: yangzhang Date: 2008-06-05 17:27:11 -0700 (Thu, 05 Jun 2008) Log Message: ----------- added boost lexical cast demo Added Paths: ----------- sandbox/trunk/src/cc/boost_lexical_cast.cc sandbox/trunk/src/cc/boost_tokenizer.cc Added: sandbox/trunk/src/cc/boost_lexical_cast.cc =================================================================== --- sandbox/trunk/src/cc/boost_lexical_cast.cc (rev 0) +++ sandbox/trunk/src/cc/boost_lexical_cast.cc 2008-06-06 00:27:11 UTC (rev 853) @@ -0,0 +1,31 @@ +#include <iostream> +#include <string> +#include <vector> +#include <boost/lexical_cast.hpp> + +using namespace boost; +using namespace std; + +int +main() +{ + string si("12345"); + int i = lexical_cast<int>(si); + cout << i << endl; + + // Doesn't work. +// string sb("true"); +// bool b = lexical_cast<bool>(sb); +// cout << b << endl; + + string sb("1"); + bool b = lexical_cast<bool>(sb); + cout << b << endl; + + // Doesn't work as expected. + stringstream ss("false"); + ss >> b; + cout << b << endl; + + return 0; +} Added: sandbox/trunk/src/cc/boost_tokenizer.cc =================================================================== --- sandbox/trunk/src/cc/boost_tokenizer.cc (rev 0) +++ sandbox/trunk/src/cc/boost_tokenizer.cc 2008-06-06 00:27:11 UTC (rev 853) @@ -0,0 +1,19 @@ +// Prints: +// This +// is +// a +// test + +#include<iostream> +#include<boost/tokenizer.hpp> +#include<string> + +int main(){ + using namespace std; + using namespace boost; + string s = "This is, a test"; + tokenizer<> tok(s); + for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ + cout << *beg << "\n"; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <yan...@us...> - 2008-06-06 01:09:41
|
Revision: 854 http://assorted.svn.sourceforge.net/assorted/?rev=854&view=rev Author: yangzhang Date: 2008-06-05 18:09:41 -0700 (Thu, 05 Jun 2008) Log Message: ----------- some more c++ tests Modified Paths: -------------- sandbox/trunk/src/cc/boost_lexical_cast.cc Added Paths: ----------- sandbox/trunk/src/cc/boost_strings.cc sandbox/trunk/src/cc/exceptions.cc sandbox/trunk/src/cc/polymorphism.cc Modified: sandbox/trunk/src/cc/boost_lexical_cast.cc =================================================================== --- sandbox/trunk/src/cc/boost_lexical_cast.cc 2008-06-06 00:27:11 UTC (rev 853) +++ sandbox/trunk/src/cc/boost_lexical_cast.cc 2008-06-06 01:09:41 UTC (rev 854) @@ -13,6 +13,11 @@ int i = lexical_cast<int>(si); cout << i << endl; + si = "asdf"; + try { i = lexical_cast<int>(si); } + catch (exception& ex) { cout << "got an exception: " << ex.what() << endl; } + //catch (...) { cout << "got an exception" << endl; } + // Doesn't work. // string sb("true"); // bool b = lexical_cast<bool>(sb); Added: sandbox/trunk/src/cc/boost_strings.cc =================================================================== --- sandbox/trunk/src/cc/boost_strings.cc (rev 0) +++ sandbox/trunk/src/cc/boost_strings.cc 2008-06-06 01:09:41 UTC (rev 854) @@ -0,0 +1,25 @@ +// Playground for boost string algorithms. + +#include <iostream> +#include <string> +#include <boost/algorithm/string.hpp> + +using namespace std; +using namespace boost; + +int +main() +{ + // This cannot be const for some reason (even though the iteration doesn't + // *seem* to be mutating the string). + /*const*/ string p("/tmp/dir/file"); + typedef split_iterator<string::iterator> iter; + for (iter it = make_split_iterator(p, last_finder("/", is_equal())); + it != iter(); + ++it) { + cout << "p: " << p << endl; + string part = copy_range<std::string>(*it); + cout << "part: " << part << endl; + } + return 0; +} Added: sandbox/trunk/src/cc/exceptions.cc =================================================================== --- sandbox/trunk/src/cc/exceptions.cc (rev 0) +++ sandbox/trunk/src/cc/exceptions.cc 2008-06-06 01:09:41 UTC (rev 854) @@ -0,0 +1,17 @@ +#include <iostream> +#include <stdexcept> + +using namespace std; + +class e1 : public exception {}; + +int +main() +{ + try { throw e1(); } catch (e1 & e) { cout << "got " << e.what() << endl; } + // This catches fine. + try { throw e1(); } catch (exception & e) { cout << "got " << e.what() << endl; } + // This doesn't work. + try { throw e1(); } catch (exception * e) { cout << "got " << e->what() << endl; } + return 0; +} Added: sandbox/trunk/src/cc/polymorphism.cc =================================================================== --- sandbox/trunk/src/cc/polymorphism.cc (rev 0) +++ sandbox/trunk/src/cc/polymorphism.cc 2008-06-06 01:09:41 UTC (rev 854) @@ -0,0 +1,18 @@ +#include <iostream> + +// Demonstrates that polymorphism can be achieved via either pointers or +// references. + +using namespace std; + +class A { public: virtual const char * f() { return "A"; } }; +class B : public A { public: const char * f() { return "B"; } }; + +int +main() +{ + B b; + A * a = b; cout << a->f() << endl; + A & a = b; cout << a.f() << endl; + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |