diff options
author | LAN-TW <lantw44@gmail.com> | 2013-10-13 02:37:06 +0800 |
---|---|---|
committer | LAN-TW <lantw44@gmail.com> | 2013-10-13 02:37:06 +0800 |
commit | f2f664ec673e3984ea90d4da999b1ed728a585a1 (patch) | |
tree | 544b936293ce4441aaa8d7bc2f13c3243322bc21 | |
parent | a2e6bfc8dcd86e1ef7827123950dea13040d2233 (diff) | |
download | sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.tar sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.tar.gz sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.tar.bz2 sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.tar.lz sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.tar.xz sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.tar.zst sp2013-f2f664ec673e3984ea90d4da999b1ed728a585a1.zip |
HW1: 修正訊息與增加重試機會、忽略 ftruncate 錯誤
-rw-r--r-- | hw1/Makefile | 2 | ||||
-rw-r--r-- | hw1/proc_r.c | 2 | ||||
-rw-r--r-- | hw1/proc_w.c | 21 |
3 files changed, 13 insertions, 12 deletions
diff --git a/hw1/Makefile b/hw1/Makefile index fd93a70..be1c4c4 100644 --- a/hw1/Makefile +++ b/hw1/Makefile @@ -30,7 +30,7 @@ clean: # Real rules configure: configure.ac Makefile.am autoreconf -i - @echo "The `configure' script is created, and you can run it now." + @echo "The \`configure' script is created, and you can run it now." @echo "WARNING: this Makefile will be overwritten by the configure script." read_server: $(read_server_objs) diff --git a/hw1/proc_r.c b/hw1/proc_r.c index 46f03b1..12b6239 100644 --- a/hw1/proc_r.c +++ b/hw1/proc_r.c @@ -142,7 +142,7 @@ bool procconn(server* svr, request* req, int maxfd, errno != EAGAIN) { // fatal error, close the connection - request_msg (&req[i], "socket read: %s", strerror (errno)); + request_msg (&req[i], "read: %s", strerror (errno)); request_free (&req[i], svr); } continue; diff --git a/hw1/proc_w.c b/hw1/proc_w.c index 6bd1990..63cedc0 100644 --- a/hw1/proc_w.c +++ b/hw1/proc_w.c @@ -88,10 +88,16 @@ bool procconn(server* svr, request* req, int maxfd, do { ssize_t this_written = write (req[i].file_fd, req[i].buf + req[i].buf_set, req[i].buf_len); - if (this_written < 0) { - request_msg (&req[i], "write: %s", strerror (errno)); - request_free (&req[i], svr); - break; + if (this_written < 0) + { + if (errno != EINTR && errno != EAGAIN) { + // fatal error, close the connection + request_msg (&req[i], "write: %s", strerror (errno)); + request_free (&req[i], svr); + break; + } else { + continue; + } } req[i].buf_set += this_written; req[i].buf_len -= this_written; @@ -159,14 +165,9 @@ bool procconn(server* svr, request* req, int maxfd, continue; } + // ftruncate is optional, so do not report error rval = ftruncate (req[i].file_fd, 0); request_err (&req[i], "ftruncate", rval); - if (rval < 0) { - write (req[i].conn_fd, svr->reject_hdr, SVR_REJECT_HDR_LEN); - request_msg (&req[i], "REJECT sent"); - request_free (&req[i], svr); - continue; - } request_msg (&req[i], "ACCEPT sent"); write (req[i].conn_fd, svr->accept_hdr, SVR_ACCEPT_HDR_LEN); |