From a2e6bfc8dcd86e1ef7827123950dea13040d2233 Mon Sep 17 00:00:00 2001 From: LAN-TW Date: Sun, 13 Oct 2013 01:17:33 +0800 Subject: =?UTF-8?q?HW1:=20=E5=B0=87=E9=87=8D=E8=A4=87=E7=9A=84=20request?= =?UTF-8?q?=5Fmsg=20=E7=94=A8=20request=5Ferr=20=E6=9B=BF=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hw1/proc_r.c | 12 +++--------- hw1/proc_w.c | 8 ++------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/hw1/proc_r.c b/hw1/proc_r.c index 301f4e2..46f03b1 100644 --- a/hw1/proc_r.c +++ b/hw1/proc_r.c @@ -94,9 +94,7 @@ bool procconn(server* svr, request* req, int maxfd, if (req[i].header_done) { if (!req[i].header_accept) { req[i].file_fd = open (req[i].filename, O_RDONLY); - request_msg (&req[i], "open %s%s", - req[i].file_fd < 0 ? "error: " : "done", - req[i].file_fd < 0 ? strerror(errno) : ""); + request_err (&req[i], "open", req[i].file_fd); if (req[i].file_fd < 0) { write (req[i].conn_fd, svr->reject_hdr, SVR_REJECT_HDR_LEN); request_msg (&req[i], "REJECT sent"); @@ -106,9 +104,7 @@ bool procconn(server* svr, request* req, int maxfd, struct stat file_stat; rval = fstat (req[i].file_fd, &file_stat); - request_msg (&req[i], "fstat %s%s", - req[i].file_fd < 0 ? "error: " : "done", - req[i].file_fd < 0 ? strerror(errno) : ""); + request_msg (&req[i], "fstat", rval); if (req[i].file_fd < 0) { write (req[i].conn_fd, svr->reject_hdr, SVR_REJECT_HDR_LEN); request_msg (&req[i], "REJECT sent"); @@ -128,9 +124,7 @@ bool procconn(server* svr, request* req, int maxfd, .l_len = 0 }; rval = fcntl (req[i].file_fd, F_SETLK, &lock_info); - request_msg (&req[i], "lock %s%s", - rval < 0 ? "error: " : "done", - rval < 0 ? strerror(errno) : ""); + request_msg (&req[i], "lock", rval); if (rval < 0) { write (req[i].conn_fd, svr->reject_hdr, SVR_REJECT_HDR_LEN); request_msg (&req[i], "REJECT sent"); diff --git a/hw1/proc_w.c b/hw1/proc_w.c index 450981b..6bd1990 100644 --- a/hw1/proc_w.c +++ b/hw1/proc_w.c @@ -112,9 +112,7 @@ bool procconn(server* svr, request* req, int maxfd, req[i].file_fd = open (req[i].filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - request_msg (&req[i], "open %s%s", - req[i].file_fd < 0 ? "error: " : "done", - req[i].file_fd < 0 ? strerror(errno) : ""); + request_err (&req[i], "open", req[i].file_fd); if (req[i].file_fd < 0) { write (req[i].conn_fd, svr->reject_hdr, SVR_REJECT_HDR_LEN); request_msg (&req[i], "REJECT sent"); @@ -124,9 +122,7 @@ bool procconn(server* svr, request* req, int maxfd, struct stat file_stat; rval = fstat (req[i].file_fd, &file_stat); - request_msg (&req[i], "fstat %s%s", - req[i].file_fd < 0 ? "error: " : "done", - req[i].file_fd < 0 ? strerror(errno) : ""); + request_err (&req[i], "fstat", rval); if (req[i].file_fd < 0) { write (req[i].conn_fd, svr->reject_hdr, SVR_REJECT_HDR_LEN); request_msg (&req[i], "REJECT sent"); -- cgit v1.2.3