diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2013-01-09 12:47:23 -0300 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2013-01-09 12:47:23 -0300 |
commit | cbba835b154ba31e7a07ba1b15a06b8953eb7e72 (patch) | |
tree | 8ea8ad0b67ba6a2f8a789f9e61ea4f80d0c20d35 /src/IO | |
parent | d236210c1608952b7910123fbede108317a80444 (diff) |
Refactored FD close calls into a single new dClose() dlib function [p37sitdu]
Diffstat (limited to 'src/IO')
-rw-r--r-- | src/IO/IO.c | 5 | ||||
-rw-r--r-- | src/IO/dpi.c | 34 | ||||
-rw-r--r-- | src/IO/http.c | 13 |
3 files changed, 12 insertions, 40 deletions
diff --git a/src/IO/IO.c b/src/IO/IO.c index 1243c70a..a0a8bba5 100644 --- a/src/IO/IO.c +++ b/src/IO/IO.c @@ -125,7 +125,6 @@ static void IO_free(IOData_t *io) */ static void IO_close_fd(IOData_t *io, int CloseCode) { - int st; int events = 0; _MSG("====> begin IO_close_fd (%d) Key=%d CloseCode=%d Flags=%d ", @@ -135,9 +134,7 @@ static void IO_close_fd(IOData_t *io, int CloseCode) * closed! (other clients may set 'IOFlag_ForceClose') */ if (((io->Flags & IOFlag_ForceClose) || (CloseCode == IO_StopRdWr)) && io->FD != -1) { - do - st = close(io->FD); - while (st < 0 && errno == EINTR); + dClose(io->FD); } else { _MSG(" NOT CLOSING "); } diff --git a/src/IO/dpi.c b/src/IO/dpi.c index 24f1fce8..8e71f8ca 100644 --- a/src/IO/dpi.c +++ b/src/IO/dpi.c @@ -86,19 +86,6 @@ void a_Dpi_init(void) } /* - * Close a FD handling EINTR - */ -static void Dpi_close_fd(int fd) -{ - int st; - - dReturn_if (fd < 0); - do - st = close(fd); - while (st < 0 && errno == EINTR); -} - -/* * Create a new connection data structure */ static dpi_conn_t *Dpi_conn_new(ChainLink *Info) @@ -362,7 +349,7 @@ static int Dpi_start_dpid(void) if (pid == 0) { /* This is the child process. Execute the command. */ char *path1 = dStrconcat(dGethomedir(), "/.dillo/dpid", NULL); - Dpi_close_fd(st_pipe[0]); + dClose(st_pipe[0]); if (execl(path1, "dpid", (char*)NULL) == -1) { dFree(path1); path1 = dStrconcat(DILLO_BINDIR, "dpid", NULL); @@ -373,7 +360,7 @@ static int Dpi_start_dpid(void) if (Dpi_blocking_write(st_pipe[1], "ERROR", 5) == -1) { MSG("Dpi_start_dpid (child): can't write to pipe.\n"); } - Dpi_close_fd(st_pipe[1]); + dClose(st_pipe[1]); _exit (EXIT_FAILURE); } } @@ -382,19 +369,18 @@ static int Dpi_start_dpid(void) /* The fork failed. Report failure. */ MSG("Dpi_start_dpid: %s\n", dStrerror(errno)); /* close the unused pipe */ - Dpi_close_fd(st_pipe[0]); - Dpi_close_fd(st_pipe[1]); - + dClose(st_pipe[0]); + dClose(st_pipe[1]); } else { /* This is the parent process, check our child status... */ - Dpi_close_fd(st_pipe[1]); + dClose(st_pipe[1]); if ((answer = Dpi_blocking_read(st_pipe[0])) != NULL) { MSG("Dpi_start_dpid: can't start dpid\n"); dFree(answer); } else { ret = 0; } - Dpi_close_fd(st_pipe[0]); + dClose(st_pipe[0]); } return ret; @@ -467,7 +453,7 @@ static int Dpi_check_dpid_ids() } else if (connect(sock_fd, (struct sockaddr *)&sin, sin_sz) == -1) { MSG("Dpi_check_dpid_ids: %s\n", dStrerror(errno)); } else { - Dpi_close_fd(sock_fd); + dClose(sock_fd); ret = 1; } } @@ -603,7 +589,7 @@ static int Dpi_get_server_port(const char *server_name) dFree(cmd); } dFree(rply); - Dpi_close_fd(sock_fd); + dClose(sock_fd); return ok ? dpi_port : -1; } @@ -648,7 +634,7 @@ static int Dpi_connect_socket(const char *server_name) } dFree(cmd); if (sock_fd != -1 && ret == -1) /* can't send cmd? */ - Dpi_close_fd(sock_fd); + dClose(sock_fd); return ret; } @@ -797,7 +783,7 @@ char *a_Dpi_send_blocking_cmd(const char *server_name, const char *cmd) } if ((ret = Dpi_blocking_read(sock_fd)) == NULL) { MSG_ERR("[a_Dpi_send_blocking_cmd] Can't read message.\n"); } - Dpi_close_fd(sock_fd); + dClose(sock_fd); return ret; } diff --git a/src/IO/http.c b/src/IO/http.c index 3e87f912..bb4bca15 100644 --- a/src/IO/http.c +++ b/src/IO/http.c @@ -210,17 +210,6 @@ static void Http_socket_free(int SKey) } /* - * Close the socket's FD - */ -static void Http_socket_close(SocketData_t *S) -{ - int st; - do - st = close(S->SockFD); - while (st < 0 && errno == EINTR); -} - -/* * Make the HTTP header's Referer line according to preferences * (default is "host" i.e. "scheme://hostname/" ) */ @@ -448,7 +437,7 @@ static int Http_connect_socket(ChainLink *Info) status = connect(S->SockFD, (struct sockaddr *)&name, socket_len); if (status == -1 && errno != EINPROGRESS) { S->Err = errno; - Http_socket_close(S); + dClose(S->SockFD); MSG("Http_connect_socket ERROR: %s\n", dStrerror(S->Err)); } else { a_Chain_bcb(OpSend, Info, &S->SockFD, "FD"); |