03.06.2013 Views

Un modello integrato control-flow e data-flow per il rilevamento ...

Un modello integrato control-flow e data-flow per il rilevamento ...

Un modello integrato control-flow e data-flow per il rilevamento ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

32 3. <strong>Un</strong> <strong>modello</strong> che integra <strong>control</strong> <strong>flow</strong> e <strong>data</strong> <strong>flow</strong><br />

1 #include <br />

2 #define CONFIG "/etc/simpleserver.conf"<br />

3 #define BUFSZ 1024<br />

4<br />

5 read_f<strong>il</strong>e(char *name, char *buf) {<br />

6 fd = open(name, O_RDONLY);<br />

7 read(fd, buf);<br />

8 close(fd);<br />

9 }<br />

10<br />

11 write_f<strong>il</strong>e(char *name, char *buf) {<br />

12 fd = open(name, O_WRONLY);<br />

13 write(fd, buf, len);<br />

14 close(fd);<br />

15 }<br />

16<br />

17 server_loop(struct config *cfg)<br />

18 {<br />

19 wh<strong>il</strong>e (1) {<br />

20 fd = accept_client();<br />

21 read_req(fd, req);<br />

22<br />

23 if (req->method == GET) {<br />

24 read_f<strong>il</strong>e(req->f<strong>il</strong>e, tmpbuf);<br />

25 send(fd, tmpbuf);<br />

26 }<br />

27 else if (req->method == PUT) {<br />

28 recv(fd, tmpbuf);<br />

29 write_f<strong>il</strong>e(req->f<strong>il</strong>e, tmpbuf);<br />

30 break;<br />

31 }<br />

32 }<br />

33 }<br />

34<br />

35 main(void)<br />

36 {<br />

37 read_f<strong>il</strong>e(CONFIG, configbuf);<br />

38 cfg = parse_config(configbuf);<br />

39 if(cfg->admin_wants_chroot)<br />

40 chroot(cfg->chroot_ja<strong>il</strong>);<br />

41<br />

42 server_loop(cfg);<br />

43 }<br />

Figura 3.5: Programma <strong>per</strong> <strong>il</strong> secondo esempio.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!