cs161 2004 Lecture 5 (NMSTL) You should be able to figure out: Debugging: 1 DEBUG << "foo is " << foo 2 INFO << "Accepted connection from " << addr; WARN << "..."; ERROR << "..."; FATAL << "Assertion failed"; // Also kills program CORE << "Assertion failed"; // Kills program, leaving core dump ntime() ptr() C++ aside: Resource Acquisition is Initialization (guards) status buffers Just pointer to space and length, NO position constbuf - immutable databuf - mutable dynbuf - refcounted iohandle just a file descriptor (RAII) iohandle.read/write(buf) seem less useful b/c of the lack of position io_event_loop loop() timer io_handler inherit here for access to ravail(), wavail() calls net_handler takes ravail(), wavail() and convert to higher level "protocol" inherit here for access to connected(), incoming_data(), end_data() tcp_acceptor new tcp_acceptor(loop,PORT,a) accepts then creates T(loop, sock, a) term_handler - convenient, adds "commands" Callbacks: R = func(T1, T2); callback cb(&func) or callback cb = wrap(&func) r = cb(t1, t2); currying! callback cb(&func, t1) r = cb(t2); objects, method is the same, except they are the first TWO arg Code: io_event_loop.loop() select() limits to FD_MAX compared to cb_add,cb_check, this adds timers, thread safety net_handler.ravail() "translates" to higher level callbacks: end_data(), incoming_data() understand valid? (Uses ref counting to ensure valid's still around) proc_handler Why only one descriptor set non blocking? What does set_owned() do? What's missing? error handling kill() child, wait() exit code could share code with net_handler, use same callbacks (needs socketpair()) two-way communication arguments to the process