CS228 Midterm II -- The Cost of Indenting
-
If I fail to indent my code properly
-
The teacher will punish me.
-
Nothing bad will happen.
-
Real programmers don't; why should I?
-
I can just indent it after I get the code right.
-
Name a system call that servers generally use, and clients generally don't.
_______________
-
Consider your server program #2 (the TCP server). If I disconnect
the network cable, what system call will be the first to fail for your
program? ________
-
Circle all of the system calls that actually send packets over the wire
when executed.
-
accept
-
listen
-
fork
-
connect
-
bind
-
reject
-
gethostbyname
-
write
-
When a system call waits for an external to the program event to complete
we say the system call 'hangs'. For example, accept() waits for another
program to connect, and there it 'hangs'. Can read() hang?
_____________ Can write()? __________________
-
My goal is to have the words "Indent or die' appear on any error.
What type of error would *NOT* generate the words'Indent or die'?
char bug[100];
int sock = socket( ..... );
int fd = accept(sock, .... );
int ret = read(fd, buf, 100);
if (ret == -1) {
perror("Indent or die");
exit(1);
}
-
What will the following code do _________________________________________?
while(fork() == 0) {
cout << "I will always indent
correctly\n";
}
-
In real life many web servers do not use the accept()/fork() paradym like
your server. Never the less these servers can handle multiple
connections at once, and never hang waiting for data. How do they
avoid having read() hang?
-
It's Tuesday at 7:30am. You are in the U.S. Your code is indented
properly. You are under 18. You are playing with MacPaint.
You are working for a company, and not attempting to make a profit.
Who can legally copy the new picture you just drew? (Note: there
is more than one answer.)
-
Is the code for pine correctly indented?
-
Yes, because they were good programmers
-
No, because they are bad programmers.
-
No, because it's a work in progress.
-
My, aren't we fixated on indenting.
-
Suppose I make a web page saying that David Bowie is a bad programmer because
he never indents his code. Further, I claim he sleeps with lizards
and is fatter than Delta Burke. Is this legal? Why?
-
Suppose I go to lookitup.com and search for the words 'automatic code
indenter linux c++'. It shows me 173 pages containing those words.
How did it get the list of pages to show?
-
Under what circumstances is http/0.9 faster than http/1.0?
-
The first time you load a page
-
The second time you load a page.
-
When the file is large
-
When the file is small
-
You send the command "HEAD /index.html http/1.0" to the web server.
Assuming the web server has that file, and implements http version 1.0,
what is the first line of the reply?
-
Suppose you try to connect to UDP port 80. The web server is
running on port 80. What will happen?
-
Which will receive more bytes per second, a request for a large file or
a request for a small file? ___________________
-
What possible outputs can this program print if I run it on many different
computers?
main() {
short a = 256;
short b = ntohs(a);
cout << "A = " << a << "B =
" << b << endl;
}
-
What circumstances will make http/1.1 show the MOST improvement in
performance over http/1.0?
-
Suppose my computer is behind a router that stops all packets with the
SYN bit set from coming to me. In other words, no packet can
arrive to me with the SYN bit set, but any packet I send can have the SYN
bit set, and it will be transmitted successfully. Can I run a web
server? ______ A web client. _________
-
(Talker Question) Consider an enviornment that has very high latency and
high bandwidth. Which would transmit data faster,
a series of http requests in parallel
or a series of http requests one after the other? Why?